Ansible: unpack a file on the remote host - Ansible version 2.2

Posted by ads' corner on Friday, 2017-01-20
Posted in [Ansible][Linux]

A while ago I posted about a nasty problem in the Ansible unarchive module: in version 2.0.x, if you do not specify copy=no, Ansible will happily copy the file again from the Ansible host.

Turns out, that problem was fixed in version 2.2, but now the Playbook runs into an error:

fatal: [xxx]: FAILED! => {"changed": false, "failed": true, "msg": "parameters are mutually exclusive: ('copy', 'remote_src')"}

Even if copy is set to no, Ansible no longer accepts both parameters.

Ok, let’s make Ansible happy, double the lines and add where conditions:

For older Ansible versions:

1
2
3
- name: unzip test archive (Ansible < 2.2)
  unarchive: src=/tmp/test.zip dest=/tmp/test-tmp-install remote_src=yes copy=no
  when: ansible_version.full | version_compare('2.2.0.0', operator='<', strict=False)

And for newer versions:

1
2
3
- name: unzip test archive (Ansible >= 2.2)
  unarchive: src=/tmp/test.zip dest=/tmp/test-tmp-install remote_src=yes copy=no
  when: ansible_version.full | version_compare('2.2.0.0', operator='>=', strict=False)

Categories: [Ansible] [Linux]