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
    }
}

두 번째 실행:

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'

관련 정보