Ansible在rails部署期间生成一个循环符号链接



我每周使用dresden(https://github.com/dresden-weekly/ansible-rails)部署rails应用程序的易任务,我的剧本中的一个任务如下:

- name: Link production database
file:
src: "{{ RAILS_APP_SHARED_PATH }}/db/production.sqlite3"
path: "{{ RAILS_APP_RELEASE_PATH }}/db/production.sqlite3"
state: link
force: yes
follow: false
- debug:
msg: "RAILS_APP_SHARED_PATH is {{ RAILS_APP_SHARED_PATH }} & RAILS_APP_RELEASE_PATH {{ RAILS_APP_RELEASE_PATH }}"

但它指向本身的符号链接:

deploy@scrappy:~/ansible_deploy/shared/db$ ls -l production.sqlite3
lrwxrwxrwx 1 deploy deploy 56 Sep  1 17:46 production.sqlite3 -> /home/deploy/ansible_deploy/shared/db/production.sqlite3

根据调试信息,变量是正确的:

TASK [rails/create-release : Link production database] *****************************************************************************************************
/usr/local/Cellar/ansible/2.9.6/libexec/lib/python3.8/site-packages/netaddr/strategy/__init__.py:189: SyntaxWarning: "is not" with a literal. Did you mean "!="?
if word_sep is not '':
ok: [scrappy]
TASK [rails/create-release : debug] ************************************************************************************************************************
/usr/local/Cellar/ansible/2.9.6/libexec/lib/python3.8/site-packages/netaddr/strategy/__init__.py:189: SyntaxWarning: "is not" with a literal. Did you mean "!="?
if word_sep is not '':
ok: [scrappy] => {
"msg": "RAILS_APP_SHARED_PATH is /home/deploy/ansible_deploy/shared & RAILS_APP_RELEASE_PATH /home/deploy/ansible_deploy/releases/20200901174921"
}

任何关于这个问题的线索都将不胜感激!

在Ubuntu 20.04中对我来说很有用。引用参数src

"要链接到的文件的路径。。。Unix命令ln-s SRC DEST">

给定树

shell> tree /home/deploy/ansible_deploy
/home/deploy/ansible_deploy
├── releases
│   └── 20200901174921
│       └── db
└── shared
└── db
└── production.sqlite3
5 directories, 1 file

下面的剧本

shell> cat playbook.yml
- hosts: localhost
vars:
RAILS_APP_SHARED_PATH: /home/deploy/ansible_deploy/shared
RAILS_APP_RELEASE_PATH: /home/deploy/ansible_deploy/releases/20200901174921
tasks:
- name: Link production database
file:
src: "{{ RAILS_APP_SHARED_PATH }}/db/production.sqlite3"
path: "{{ RAILS_APP_RELEASE_PATH }}/db/production.sqlite3"
state: link
force: true
follow: false
- debug:
msg:
- "RAILS_APP_SHARED_PATH [{{ RAILS_APP_SHARED_PATH }}]"
- "RAILS_APP_RELEASE_PATH [{{ RAILS_APP_RELEASE_PATH }}]"

给出

shell> ansible-playbook playbook.yml
PLAY [localhost] ****
TASK [Link production database] ****
changed: [localhost]
TASK [debug] ****
ok: [localhost] => {
"msg": [
"RAILS_APP_SHARED_PATH [/home/deploy/ansible_deploy/shared]",
"RAILS_APP_RELEASE_PATH [/home/deploy/ansible_deploy/releases/20200901174921]"
]
}
PLAY RECAP ****
localhost: ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0   
shell> tree /home/deploy/ansible_deploy
/home/deploy/ansible_deploy
├── releases
│   └── 20200901174921
│       └── db
│           └── production.sqlite3 -> /home/deploy/ansible_deploy/shared/db/production.sqlite3
└── shared
└── db
└── production.sqlite3
5 directories, 2 files

最新更新