Template - chmod (Readme) failed: chmod: invalid mode 'False'
marjancinober opened this issue · 2 comments
Basic template "{{ inventory_hostname }}" creates the file
root@testwrt:~# cat Readme
testwrt.test.lan
but reports the error
TASK [Make Readme for testwrt.test.lan] ****************************************
fatal: [testwrt.test.lan]: FAILED! => {"changed": false, "checksum": "adc83b19e793491b1c6ea0fd8b46cd9f32e592fc", "msg": "chmod (Readme) failed: chmod: invalid mode 'False'", "path": "Readme", "state": "file"}
to retry, use: --limit @/home/user/ansible-bug/routers.retry
PLAY RECAP *********************************************************************
testwrt.test.lan : ok=11 changed=0 unreachable=0 failed=1
and stops the playbook.
I'm quite new at Ansible. No idea how to debug the shell script on remote router.
...
--------- To Replay the Bug Copy and Paste ---------
WD=`pwd`/ansible-bug
mkdir $WD
# Install ansible in virtualenv
cd $WD
sudo pip3 install -U virtualenv
virtualenv .venv
. .venv/bin/activate
pip install ansible
# Clone gekmihesg/ansible
mkdir roles; cd roles/
git clone https://github.com/gekmihesg/ansible-openwrt.git
mv ansible-openwrt/ openwrt/
# Configure bug demo
cd $WD
mkdir -p roles/openwrt/vars/
cat << EOF > roles/openwrt/vars/main.yml
#// Reduce flash wear on target device
ansible_remote_tmp: /tmp/ansible
ansible_ssh_transfer_method: scp
EOF
cat << EOF > hosts
[openwrt]
testwrt.test.lan
EOF
cat << EOF > routers.yml
- hosts: openwrt
roles:
- openwrt
gather_facts: no
tasks:
- name: Make Readme for {{inventory_hostname}}
template:
src: roles/openwrt/templates/Readme.j2
dest: Readme
mode: '0644'
EOF
mkdir -p roles/openwrt/templates
cat << EOF > roles/openwrt/templates/Readme.j2
{{ inventory_hostname }}
EOF
ansible-playbook -v -i hosts routers.yml -l testwrt.test.lan 2>&1 | tee .buglog
Ok, AFTER loosing a day I stumbled across temporary solution shown as explicit "mode: '0644' " parameter above. Strange, as it requires both single quote and leading zero. According to Ansible documentation one should suffice, and should work without specifying the mode as well, as it actually works in other non-openwrt roles.
This seems to resolve my example issue, but it'a a blind guess. I am afraid there probably is a better place to place this correction at, right?
--- roles/openwrt/filter_plugins/monkeypatch.py.orig 2019-03-14 19:41:08.056362453 +0100
+++ roles/openwrt/filter_plugins/monkeypatch.py 2019-03-22 22:43:15.280304372 +0100
@@ -4,7 +4,10 @@
def _fix_module_args(module_args):
for k, v in module_args.items():
if v is None:
- module_args[k] = False
+ if k == 'mode':
+ module_args[k] = ''
+ else:
+ module_args[k] = False
elif isinstance(v, dict):
_fix_module_args(v)
elif isinstance(v, list):
Note, For this to work I had to run ... to recompile to pyc
python roles/openwrt/filter_plugins/monkeypatch.py