Last active
October 17, 2017 23:16
-
-
Save halberom/c2e5948a5811bd839a7f0bd31a344d9a to your computer and use it in GitHub Desktop.
ansible - copy module returns different keys depending on change status - inconsistent
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- hosts: localhost | |
gather_facts: False | |
connection: local | |
vars: | |
foo: bar | |
tasks: | |
- name: first time - dest is changed, 'dest' is returned in results | |
# yes I'm using template, not copy, but the template action plugin calls the copy module... | |
template: | |
src: 01_test.j2 | |
dest: /tmp/foobar | |
register: template_result | |
- debug: | |
var: template_result | |
- name: second time - nothing is changed, 'path' is returned in results | |
template: | |
src: 01_test.j2 | |
dest: /tmp/foobar | |
register: template_result | |
- debug: | |
var: template_result | |
- debug: | |
msg: "To do a conditional, I need to handle both scenarios now - fugly" | |
when: template_result.get('path', template_result.get('dest')) == '/tmp/foobar' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{{ foo }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PLAY [localhost] *************************************************************************************************************************************************************************************************************************************************************** | |
TASK [first time - dest is changed, 'dest' is returned in results] ************************************************************************************************************************************************************************************************************* | |
changed: [localhost] | |
TASK [debug] ******************************************************************************************************************************************************************************************************************************************************************* | |
ok: [localhost] => { | |
"changed": false, | |
"template_result": { | |
"changed": true, | |
"checksum": "e242ed3bffccdf271b7fbaf34ed72d089537b42f", | |
"dest": "/tmp/foobar", | |
"gid": 137676021, | |
"group": "137676021", | |
"md5sum": "c157a79031e1c40f85931829bc5fc552", | |
"mode": "0644", | |
"owner": "lynchg", | |
"size": 4, | |
"src": "/Users/lynchg/.ansible/tmp/ansible-tmp-1496845609.21-59671882598024/source", | |
"state": "file", | |
"uid": 1920260155 | |
} | |
} | |
TASK [second time - nothing is changed, 'path' is returned in results] ********************************************************************************************************************************************************************************************************* | |
ok: [localhost] | |
TASK [debug] ******************************************************************************************************************************************************************************************************************************************************************* | |
ok: [localhost] => { | |
"changed": false, | |
"template_result": { | |
"changed": false, | |
"diff": { | |
"after": { | |
"path": "/tmp/foobar" | |
}, | |
"before": { | |
"path": "/tmp/foobar" | |
} | |
}, | |
"gid": 137676021, | |
"group": "137676021", | |
"mode": "0644", | |
"owner": "lynchg", | |
"path": "/tmp/foobar", | |
"size": 4, | |
"state": "file", | |
"uid": 1920260155 | |
} | |
} | |
TASK [debug] ******************************************************************************************************************************************************************************************************************************************************************* | |
ok: [localhost] => { | |
"changed": false, | |
"msg": "To do a conditional, I need to handle both scenarios now - fugly" | |
} | |
PLAY RECAP ********************************************************************************************************************************************************************************************************************************************************************* | |
localhost : ok=5 changed=1 unreachable=0 failed=0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It would be nice if the bug I filed were fixed, but in the meantime, the workaround is