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 设置为 时2777,它会被解释为十进制数,因此应用的(八进制)模式为05331。你需要改变

mode: 2777

mode: 02777

或者

mode: '2777'

让 ansible 将其识别为八进制。

ansible模板模块:“您必须添加一个前导零,以便 Ansible 的 YAML 解析器知道它是一个八进制数(如064401777),或者引用它(如'644''1777'),以便 Ansible 接收一个字符串并可以自行将字符串转换为数字。”

相关内容