ansible / ansible-modules-core

Ansible modules - these modules ship with ansible
1.3k stars 1.95k forks source link

Template modules does not adhere to variable precedence #5868

Closed ashemedai closed 7 years ago

ashemedai commented 7 years ago
ISSUE TYPE
COMPONENT NAME

template

ANSIBLE VERSION
ansible 2.2.0.0
  config file = 
  configured module search path = Default w/o overrides
CONFIGURATION

No settings in place.

OS / ENVIRONMENT

N/A

SUMMARY
STEPS TO REPRODUCE

Please replace - in filename with / https://gist.github.com/ashemedai/6482b3fdb8a64eed14c44554f1898893

EXPECTED RESULTS

The file test.output to contain: Variable in question: "Ijklmnop"

ACTUAL RESULTS

The file test.output contains: Variable in question: "Abcdefgh"

% ansible-playbook -vvvv testplaybook -i inventory/testenv
No config file found; using defaults
Loading callback plugin default of type stdout, v2.0 from /usr/local/lib/python2.7/dist-packages/ansible/plugins/callback/__init__.pyc

PLAYBOOK: testplaybook *********************************************************
1 plays in testplaybook

PLAY [Testing variables] *******************************************************

TASK [testrole : debug] ********************************************************
task path: /home/jeroenr/ansible/testrole/tasks/main.yml:1
ok: [localhost] => {
    "testvar1": "Abcdefgh"
}

TASK [testrole : debug] ********************************************************
task path: /home/jeroenr/ansible/testrole/tasks/main.yml:4
ok: [localhost] => {
    "testvar2": "Ijklmnop"
}

TASK [testrole : debug] ********************************************************
task path: /home/jeroenr/ansible/testrole/tasks/main.yml:7
ok: [localhost] => {
    "setting": "Abcdefgh"
}

TASK [testrole : debug] ********************************************************
task path: /home/jeroenr/ansible/testrole/tasks/main.yml:10
ok: [localhost] => {
    "apache_vhosts": [
        {
            "setting": "Ijklmnop"
        }
    ]
}

TASK [testrole : Test template] ************************************************
task path: /home/jeroenr/ansible/testrole/tasks/main.yml:13
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: jeroenr
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo $HOME/.ansible/tmp/ansible-tmp-1481288820.47-185974184970601 `" && echo ansible-tmp-1481288820.47-185974184970601="` echo $HOME/.ansible/tmp/ansible-tmp-1481288820.47-185974184970601 `" ) && sleep 0'
Using module file /usr/local/lib/python2.7/dist-packages/ansible/modules/core/files/stat.py
<127.0.0.1> PUT /tmp/tmpBZata5 TO /home/jeroenr/.ansible/tmp/ansible-tmp-1481288820.47-185974184970601/stat.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /home/jeroenr/.ansible/tmp/ansible-tmp-1481288820.47-185974184970601/ /home/jeroenr/.ansible/tmp/ansible-tmp-1481288820.47-185974184970601/stat.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/usr/bin/python /home/jeroenr/.ansible/tmp/ansible-tmp-1481288820.47-185974184970601/stat.py && sleep 0'
<127.0.0.1> PUT /tmp/tmpwTMm8B TO /home/jeroenr/.ansible/tmp/ansible-tmp-1481288820.47-185974184970601/source
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /home/jeroenr/.ansible/tmp/ansible-tmp-1481288820.47-185974184970601/ /home/jeroenr/.ansible/tmp/ansible-tmp-1481288820.47-185974184970601/source && sleep 0'
Using module file /usr/local/lib/python2.7/dist-packages/ansible/modules/core/files/copy.py
<127.0.0.1> PUT /tmp/tmpsb1ndq TO /home/jeroenr/.ansible/tmp/ansible-tmp-1481288820.47-185974184970601/copy.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /home/jeroenr/.ansible/tmp/ansible-tmp-1481288820.47-185974184970601/ /home/jeroenr/.ansible/tmp/ansible-tmp-1481288820.47-185974184970601/copy.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/usr/bin/python /home/jeroenr/.ansible/tmp/ansible-tmp-1481288820.47-185974184970601/copy.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /home/jeroenr/.ansible/tmp/ansible-tmp-1481288820.47-185974184970601/ > /dev/null 2>&1 && sleep 0'
changed: [localhost -> 127.0.0.1] => (item={u'setting': u'Ijklmnop'}) => {
    "changed": true, 
    "checksum": "0000a8d305bfb42e85bccb5f9ed6702e2cea4ae9", 
    "dest": "/tmp/test.output", 
    "gid": 1000, 
    "group": "jeroenr", 
    "invocation": {
        "module_args": {
            "backup": false, 
            "content": null, 
            "delimiter": null, 
            "dest": "/tmp/test.output", 
            "directory_mode": null, 
            "follow": true, 
            "force": true, 
            "group": null, 
            "mode": null, 
            "original_basename": "test.j2", 
            "owner": null, 
            "regexp": null, 
            "remote_src": null, 
            "selevel": null, 
            "serole": null, 
            "setype": null, 
            "seuser": null, 
            "src": "/home/jeroenr/.ansible/tmp/ansible-tmp-1481288820.47-185974184970601/source", 
            "unsafe_writes": null, 
            "validate": null
        }
    }, 
    "item": {
        "setting": "Ijklmnop"
    }, 
    "md5sum": "7ff832456b67b6778d49dc5e33e78b70", 
    "mode": "0644", 
    "owner": "jeroenr", 
    "size": 85, 
    "src": "/home/jeroenr/.ansible/tmp/ansible-tmp-1481288820.47-185974184970601/source", 
    "state": "file", 
    "uid": 1000
}

PLAY RECAP *********************************************************************
localhost                  : ok=5    changed=1    unreachable=0    failed=0   

% cat /tmp/test.output 
Simply testing variable precedence and expansion:

Variable in question: "Abcdefgh"
ansibot commented 7 years ago

This repository has been locked. All new issues and pull requests should be filed in https://github.com/ansible/ansible

Please read through the repomerge page in the dev guide.

ashemedai commented 7 years ago

This issue was moved to ansible/ansible#19154