Ansible在Rails部署期间进行圆形符号链接

问题描述

我正在使用每周一次的德累斯顿(https://github.com/dresden-weekly/ansible-rails)ansible任务来部署我的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