ansible テンプレートモジュール権限エラー

ansible テンプレートモジュール権限エラー

私のyamlコードスニペット:

  - name: 11|Copy sw-installer.jinja2 response file for unattended installation

     template:
       src: "{{ CNTRL_SERVER_RSP_FILE_DIR_LOCATION_FOR_INSTALL }}/sw-installer.jinja2"
       dest: "/opt/something/{{ ENV_CHOSEN }}/tempLocation/sw-installer.conf"
       owner: joker
       group: circus
       mode: 2777
       backup: yes

     when:
       - ansible_facts['os_family'] == "CentOS" or ansible_facts['os_family'] == "RedHat"
       - ansible_distribution_version | int >= 6
       - http_dir_path.stat.exists == true
       - http_dir_path.stat.isdir == true
       - ChangeDirPermission is defined
       - ChangeDirPermission is succeeded

     register: CopyRspFileResult

   - debug:
       var: CopyRspFileResult

ランタイム結果:

TASK [11|Copy sw-installer.jinja2 response file for unattended installation] ********************************************
changed: [rm-host.company.com]

TASK [debug] ***************************************************************************************************************
ok: [rm-host.company.com] => {
    "CopyRspFileResult": {
        "changed": true,
        "checksum": "b0f86be744b2b0c767b4861e7a36800708c47ff9",
        "dest": "/opt/something/unitc/tempLocation/sw-installer.conf",
        "diff": [],
        "failed": false,
        "gid": 4912,
        "group": "circus",
        "md5sum": null,
        "mode": "05331",
        "owner": "joker",
        "secontext": "system_u:object_r:usr_t:s0",
        "size": 8534,
        "src": "/u/joker/.ansible/tmp/ansible-tmp-1561211521.59-240308852971878/source",
        "state": "file",
        "uid": 1124558737
    }
}

2回目の実行:

TASK [11|Copy sw-installer.jinja2 response file for unattended installation] ********************************************
fatal: [rm-host.company.com]: FAILED! => {"changed": false, "checksum": "b0f86be744b2b0c767b4861e7a36800708c47ff9", "msg": "Could not make backup of /opt/something/unitc/tempLocation/sw-installer.conf to /opt/something/unitc/tempLocation/sw-installer.conf.51030.2019-06-22@10:02:12~: [Errno 13] Permission denied: '/opt/something/unitc/tempLocation/sw-installer.conf'"}
        to retry, use: --limit @/u/sdbmiu/scripts/Ansible/playbooks/webagent/plays/WebAgent_Install.retry

PLAY RECAP *****************************************************************************************************************
rm-host.company.com     : ok=7    changed=2    unreachable=0    failed=1

指示:

/opt/something/unitc/tempLocation has permission of 2775

Exact same error appears even if I use /tmp as remote location

I'm running as user joker on remote node. So not running as root or sudo. I don't have permission to do that. 

バージョン

ansible 2.7.10
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/home/company/sdbmiu/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /bin/ansible
  python version = 2.7.5 (default, Mar 26 2019, 22:13:06) [GCC 4.8.5 20150623 (Red Hat 4.8.5-36)]

質問:

1. Why does it fails to set appropriate permission when mode: 2777 is specified? But on remote node, permission appear as (5331/--ws-wx--t)

2. Why should backup fail?

答え1

デバッグ出力に見られるように、modeをに設定すると277710進数として解釈されるため、適用される(8進数)モードはです05331。あなたは変わらなければなりません

mode: 2777

到着

mode: 02777

または

mode: '2777'

Ansibleにこれを8進数として認識させます。

~からアンサーブルテンプレートモジュール: "AnsibleのYAMLパーサーが8進数(例えば0644or 01777)であることを知るために、0を前に追加するか、Ansibleが文字列を受け取り、それを文字列を数値に変換できるように引用する必要があります(例:'644'or)。'1777'

関連情報