1

Snippet of my yaml code:

  - 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

Runtime result:

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

Running 2nd time:

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

Points to note:

/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 version

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)]

Questions:

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?
2

As you can see from your debug output, when you set mode to 2777, it is interpreted as a decimal number, so the (octal) mode applied is 05331. You need to change

mode: 2777

to

mode: 02777

or

mode: '2777'

for ansible to recognize it as octal.

From ansible template module: "You must either add a leading zero so that Ansible's YAML parser knows it is an octal number (like 0644 or 01777) or quote it (like '644' or '1777') so Ansible receives a string and can do its own conversion from string into number."

| improve this answer | |
  • Thank you user4556274. It works. Also, backup problem is resolved with this. For benefits of others, we could also use "mode: preserve" so that source permissions are same at target. Backup is only taken if source file is different than target. – Raman Kathpalia Jun 22 '19 at 15:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.