Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Variable assignment with include_vars and register #39733

Closed
mathieucoavoux opened this issue May 4, 2018 · 7 comments
Closed

Variable assignment with include_vars and register #39733

mathieucoavoux opened this issue May 4, 2018 · 7 comments
Labels
affects_2.4 This issue/PR affects Ansible v2.4 bug This issue/PR relates to a bug. module This issue/PR relates to a module. support:core This issue/PR relates to code supported by the Ansible Engineering Team. utilities Utilities category

Comments

@mathieucoavoux
Copy link

mathieucoavoux commented May 4, 2018

ISSUE TYPE
  • Bug Report
COMPONENT NAME

include_vars

ANSIBLE VERSION
ansible 2.4.2.0
Install from pip
CONFIGURATION

[user1@server1 ansible]$ ansible-config dump --only-changed
[user1@server1 ansible]$

OS / ENVIRONMENT

N/A

SUMMARY

Variable assignment with include_vars and register

STEPS TO REPRODUCE

When including a variable file with register, the variables inside this file cannot take the value of another defined variable

roles/test/tasks/main.yml

---
- include_vars: "roles/test/vars/test.yml"
  register: myvar

- include_vars: "roles/test/vars/test2.yml"

- debug:
    msg: "mykey1 : {{mykey1}}, mykey1bis: {{mykey1bis}}"

- debug:
    msg: "mykey2 : {{mykey2}}, mykey2bis: {{mykey2bis}}"

roles/test/vars/test.yml

---
mykey1: "myvalue1"
mykey1bis: "{{mykey1}}"

roles/test/vars/test2.yml

---
mykey2: "myvalue2"
mykey2bis: "{{mykey2}}"
EXPECTED RESULTS
PLAY [localhost] *******************************************************************************************************************

TASK [Gathering Facts] *************************************************************************************************************
ok: [localhost]

TASK [test : include_vars] *********************************************************************************************************
ok: [localhost]

TASK [test : include_vars] *********************************************************************************************************
ok: [localhost]

TASK [test : debug] ****************************************************************************************************************
ok: [localhost] => {
    "msg": "mykey1 : myvalue1, mykey1bis: myvalue1"
}

TASK [test : debug] ****************************************************************************************************************
ok: [localhost] => {
    "msg": "mykey2 : myvalue2, mykey2bis: myvalue2"
}
ACTUAL RESULTS
ansible-playbook 2.4.2.0
  config file = None
  configured module search path = [u'/myhome/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /mypath/ansible/lib/python2.7/site-packages/ansible
  executable location = /mypath/ansible/bin/ansible-playbook
  python version = 2.7.5 (default, May  3 2017, 07:55:04) [GCC 4.8.5 20150623 (Red Hat 4.8.5-14)]
No config file found; using defaults
setting up inventory plugins
 [WARNING]: Unable to parse /etc/ansible/hosts as an inventory source

 [WARNING]: No inventory was parsed, only implicit localhost is available

 [WARNING]: Could not match supplied host pattern, ignoring: all

 [WARNING]: provided hosts list is empty, only localhost is available

Loading callback plugin default of type stdout, v2.0 from /mypath/ansible/lib/python2.7/site-packages/ansible/plugins/callback/__init__.pyc

PLAYBOOK: test.yml *****************************************************************************************************************
1 plays in test.yml

PLAY [localhost] *******************************************************************************************************************

TASK [Gathering Facts] *************************************************************************************************************
Using module file /mypath/ansible/lib/python2.7/site-packages/ansible/modules/system/setup.py
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: tauadmt
<127.0.0.1> EXEC /bin/sh -c 'echo ~ && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /myhome/.ansible/tmp/ansible-tmp-1525433990.2-105806259019021 `" && echo ansible-tmp-1525433990.2-105806259019021="` echo /myhome/.ansible/tmp/ansible-tmp-1525433990.2-105806259019021 `" ) && sleep 0'
<127.0.0.1> PUT /tmp/tmpCugHW9 TO /myhome/.ansible/tmp/ansible-tmp-1525433990.2-105806259019021/setup.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /myhome/.ansible/tmp/ansible-tmp-1525433990.2-105806259019021/ /myhome/.ansible/tmp/ansible-tmp-1525433990.2-105806259019021/setup.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/usr/bin/python /myhome/.ansible/tmp/ansible-tmp-1525433990.2-105806259019021/setup.py; rm -rf "/myhome/.ansible/tmp/ansible-tmp-1525433990.2-105806259019021/" > /dev/null 2>&1 && sleep 0'
ok: [localhost]
META: ran handlers

TASK [test : include_vars] *********************************************************************************************************
task path: /myrepo/ansible/roles/test/tasks/main.yml:2
ok: [localhost] => {
    "ansible_facts": {
        "mykey1": "myvalue1",
        "mykey1bis": "{{mykey1}}"
    },
    "ansible_included_var_files": [
        "/myrepo/ansible/roles/test/vars/test.yml"
    ],
    "changed": false
}

TASK [test : include_vars] *********************************************************************************************************
task path: /myrepo/ansible/roles/test/tasks/main.yml:5
ok: [localhost] => {
    "ansible_facts": {
        "mykey2": "myvalue2",
        "mykey2bis": "{{mykey2}}"
    },
    "ansible_included_var_files": [
        "/myrepo/ansible/roles/test/vars/test2.yml"
    ],
    "changed": false
}

TASK [test : debug] ****************************************************************************************************************
task path: /myrepo/ansible/roles/test/tasks/main.yml:7
ok: [localhost] => {
    "msg": "mykey1 : myvalue1, mykey1bis: {{mykey1}}"
}

TASK [test : debug] ****************************************************************************************************************
task path: /mypath/ansible/roles/test/tasks/main.yml:10
ok: [localhost] => {
    "msg": "mykey2 : myvalue2, mykey2bis: myvalue2"
}
META: ran handlers
META: ran handlers

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

@ansibot
Copy link
Contributor

ansibot commented May 4, 2018

Files identified in the description:

If these files are inaccurate, please update the component name section of the description or use the !component bot command.

click here for bot help

@ansibot
Copy link
Contributor

ansibot commented May 4, 2018

@ansibot ansibot added affects_2.4 This issue/PR affects Ansible v2.4 bug This issue/PR relates to a bug. module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. support:core This issue/PR relates to code supported by the Ansible Engineering Team. labels May 4, 2018
@sivel sivel removed the needs_triage Needs a first human triage before being processed. label May 4, 2018
@aleshav
Copy link

aleshav commented Sep 23, 2018

Duplicate of #21088? Could be reproduced in Ansible 2.6.4. as well.

@ansibot ansibot added the utilities Utilities category label Feb 17, 2019
@ansibot
Copy link
Contributor

ansibot commented May 16, 2020

Files identified in the description:

If these files are incorrect, please update the component name section of the description or use the !component bot command.

click here for bot help

@felixfontein
Copy link
Contributor

Can be reproduced with current devel (2.11.0.dev0) as well.

@webmozart
Copy link

Experiencing the same issue with Ansible 2.10.5.

@mkrizek
Copy link
Contributor

mkrizek commented Jun 4, 2021

Duplicate of #21088.

@mkrizek mkrizek closed this as completed Jun 4, 2021
@ansible ansible locked and limited conversation to collaborators Jul 2, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.4 This issue/PR affects Ansible v2.4 bug This issue/PR relates to a bug. module This issue/PR relates to a module. support:core This issue/PR relates to code supported by the Ansible Engineering Team. utilities Utilities category
Projects
None yet
Development

No branches or pull requests

7 participants