ansible-role-blockinfile icon indicating copy to clipboard operation
ansible-role-blockinfile copied to clipboard

Doesn't work with ansible 1.x

Open iliv opened this issue 8 years ago • 2 comments

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

iliv avatar Mar 29 '16 15:03 iliv

Thanks for the detailed compat analysis. I admit I've been negligent in testing this module for older versions of Ansible. I actually wonder how much demand there is still for supporting Ansible prior to 1.9 - is it worth making efforts to keep compatibility?

Fortunately, I already have some testing scripts, so it would make that task easier if I have an automatic testing infrastructure hosted by Travis CI. Is it that easy to set up?

yaegashi avatar Mar 29 '16 23:03 yaegashi

Well, a lot of businesses tend to use so called LTS versions of distributions. Typically this means no bleeding edge software is available on these systems. On the flip side, the software is stable, presumably tested and very reliable. Ubuntu LTS provides ansible 1.5.4. I'm not sure about RHEL but I'd imagine it is a similar story. With that in mind, you really want to cater to these target audiences because they are the people who will appreciate good support the most. Supporting LTS makes a lot of sense as it is basically the industry standard of sorts. So, I'd say yes, make sure it's compatible and people will appreciate it. The few like myself that get here to actually report the problem are only the tip of the proverbial iceberg.

iliv avatar Mar 30 '16 15:03 iliv