Overcast
Overcast

Reputation: 70

Odd Ansible Output

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

Answers (1)

P....
P....

Reputation: 18411

You need to use this syntax for debug:

  - name: Extra Vars
    debug:
      msg: "This is the extra variable {{ extra }}"

Reason for printing hello world:

msg string Default: "Hello world!" The customized message that is printed. If omitted, prints a generic message.

Read: doc

Upvotes: 1

Related Questions