Reputation: 70
I'm fairly new to Ansible, but this is giving me some unexpected results. I need to integrate an extra variable in a playbook where I have to deal with outputting data to different directories. Being new, I thought I would do the most simple test possible to make sure I'm getting the Syntax right, but I'm ending up with some odd results.
Here's the playbook that's giving me trouble.
---
- hosts: localhost
become: yes
tasks:
- name: Extra Vars
debug: "This is the extra variable {{ extra }}"
I've changed the variable name, but each time - this will output this:
ansible-playbook show_variables.yml -e 'extra=Extra'
TASK [Extra Vars] ***************************************************************************************************************************************************
ok: [localhost] => {
"msg": "Hello world!"
}
I get "Hello World!", no matter what I change the variable name or value to:
[ansible@oelinux1 ansible]$ ansible-playbook show_variables.yml -e "extra=Goodbye World"
PLAY [localhost] ****************************************************************************************************************************************************
TASK [Gathering Facts] **********************************************************************************************************************************************
ok: [localhost]
TASK [Extra Vars] ***************************************************************************************************************************************************
ok: [localhost] => {
"msg": "Hello world!"
}
PLAY RECAP **********************************************************************************************************************************************************
localhost : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
[ansible@oelinux1 ansible]$
Now, I can make a simple change and get my Variable, this works just fine.
- name: Extra Vars
debug:
var: extra
[ansible@oelinux1 ansible]$ ansible-playbook show_variables.yml -e "extra=GoodbyeWorld"
PLAY [localhost] ****************************************************************************************************************************************************
TASK [Gathering Facts] **********************************************************************************************************************************************
ok: [localhost]
TASK [Extra Vars] ***************************************************************************************************************************************************
ok: [localhost] => {
"extra": "GoodbyeWorld"
}
PLAY RECAP **********************************************************************************************************************************************************
localhost : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
[ansible@oelinux1 ansible]$
Am I doing something wrong here? I would expect some error or something, not a "Hello World!" If I run it without the variable defined on the command line, it gives an error about the variable not being defined, of course.
Just curious why this is happening.
*[ansible@oelinux1 ansible]$ ansible --version
ansible 2.9.14
config file = /etc/ansible/ansible.cfg
configured module search path = [u'/home/ansible/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python2.7/site-packages/ansible
executable location = /bin/ansible
python version = 2.7.5 (default, May 27 2020, 06:51:48) [GCC 4.8.5 20150623 (Red Hat 4.8.5-44.0.1)]
[ansible@oelinux1 ansible]$*
Upvotes: 0
Views: 477