ansible-role-blockinfile
ansible-role-blockinfile copied to clipboard
Doesn't work with ansible 1.x
Hello,
I tried to use the most recent version 0.6 of this module with ansible 1.7.1 and 1.5.4 and it doesn't work at all:
- name: Add DB Config
blockinfile:
dest: "{{ test_rootfs }}/blockinfile"
block: |
DATABASES={
'default': dbname
}
ERROR: blockinfile is not a legal parameter in an Ansible task or handler
After much troubleshooting I realized that role/module Python script file was blockinfile.py, when it's supposed to be blockinfile:
.
├── CONTRIBUTING.md
├── library
│ └── blockinfile.py
├── meta
│ └── main.yml
├── README.md
└── tests
├── expected
├── fixtures
├── hosts
├── run.sh
├── test-basic.yml
├── test-block.yml
├── test-follow.yml
├── testing
├── test-insertab.yml
├── test-replace.yml
└── test-state.yml
Even then, when blockinfile.py was renamed to blockinfile ansible 1.5.4 would run into this problem:
fatal: [127.0.0.1] => imported module support code does not exist at /usr/lib/python2.7/dist-packages/ansible/module_utils/splitter.py
Ansible version 1.7.1 has the required splitter.py utility but even so there was one more issue:
failed: [127.0.0.1] => {"failed": true, "parsed": false}
invalid output was:
SUDO-SUCCESS-qkewojdkkysbtyyflfhsnifqgvkpjnrg
Traceback (most recent call last):
File "/home/ansiblemgr/.ansible/tmp/ansible-tmp-1459262324.65-150912085331989/blockinfile", line 1833, in <module>
main()
File "/home/ansiblemgr/.ansible/tmp/ansible-tmp-1459262324.65-150912085331989/blockinfile", line 226, in main
if ANSIBLE_VERSION.startswith('1.'):
NameError: global name 'ANSIBLE_VERSION' is not defined
debug3: mux_client_read_packet: read header failed: Broken pipe
debug2: Received exit status from master 0
Shared connection to 127.0.0.1 closed.
I edited the module Python script blockinfile(.py) and commented out the problematic conditional as in my case I have ansible 1.7 and it's essentially superfluous:
if present and block:
# Escape seqeuences like '\n' need to be handled in Ansible 1.x
#if ANSIBLE_VERSION.startswith('1.'):
# block = re.sub('', block, '')
block = re.sub('', block, '')
blocklines = [marker0] + block.splitlines() + [marker1]
else:
blocklines = []
Then it finally worked.
I haven't tested any other parameters outside what is shown in the beginning of this report.
This module is either awfully broken or woefully undocumented. So, please, either fix these issues or update documentation and clearly indicate that 2.0 is the only supported version.
Ivan