simple problem has me stumped

20 views
Skip to first unread message

misterT1958

unread,
Feb 10, 2020, 4:33:14 PM2/10/20
to Ansible Project
I have a simple scenario that fails, but I can't figure out why.  Here's the command line invocation and the result:

[root@cluster-mgmt tasks]# ansible-playbook -i ./hosts main.yml

PLAY [CLUSTERS team downtime orchestration play] ********************************************************************************************************************

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

TASK [set nagios downtime] ******************************************************************************************************************************************
fatal: [localhost]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'myTestVar' is undefined\n\nThe error appears to have been in '/autofs/nccs-svm1_home1/tw58/SANDBOX/ANSIBLE_VARDIR/testVar/tasks/main.yml': line 9, column 5, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n  tasks:\n  - name: set nagios downtime\n    ^ here\n"}
 [WARNING]: Could not create retry file '/autofs/nccs-svm1_home1/tw58/SANDBOX/ANSIBLE_VARDIR/testVar/tasks/main.retry'.         [Errno 13] Permission denied:
u'/autofs/nccs-svm1_home1/tw58/SANDBOX/ANSIBLE_VARDIR/testVar/tasks/main.retry'


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

The playbook is simple:

---
# tasks file for testVar

- hosts: localhost
  name: CLUSTERS team downtime orchestration play
  gather_facts: true

  tasks:
  - name: set nagios downtime
    debug:
      msg: "the value of the variable {{ myTestVar }}"

and the variable definition file is even more simple:

[root@cluster-mgmt vars]# more main.yml
---
# vars file for testVar
myTestVar: 58

This is my directory tree:

[root@cluster-mgmt testVar]# tree
.
├── ansible.cfg
├── defaults
│   └── main.yml
├── files
├── handlers
│   └── main.yml
├── hosts
├── meta
│   └── main.yml
├── README.md
├── tasks
│   ├── ansible.cfg -> ../ansible.cfg
│   ├── hosts -> ../hosts
│   └── main.yml
├── templates
├── tests
│   ├── inventory
│   └── test.yml
└── vars
    └── main.yml

Been staring at this all day, trying different things, always get the "undefined variable"!!

Does anybody out there see the problem?

Thanks
T

Vladimir Botka

unread,
Feb 10, 2020, 5:28:35 PM2/10/20
to misterT1958, ansible...@googlegroups.com
On Mon, 10 Feb 2020 13:18:24 -0800 (PST)
misterT1958 <tony.wa...@gmail.com> wrote:

> [root@cluster-mgmt tasks]# ansible-playbook -i ./hosts main.yml
> [...]
> The playbook is simple:
> ---
> # tasks file for testVar
>
> - hosts: localhost
> name: CLUSTERS team downtime orchestration play
> gather_facts: true
>
> tasks:
> - name: set nagios downtime
> debug:
> msg: "the value of the variable {{ myTestVar }}"
> [...]
> [root@cluster-mgmt testVar]# tree
> .
> ├── ansible.cfg
> ├── defaults
> │ └── main.yml
> ├── files
> ├── handlers
> │ └── main.yml
> ├── hosts
> ├── meta
> │ └── main.yml
> ├── README.md
> ├── tasks
> │ ├── ansible.cfg -> ../ansible.cfg
> │ ├── hosts -> ../hosts
> │ └── main.yml
> ├── templates
> ├── tests
> │ ├── inventory
> │ └── test.yml
> └── vars
> └── main.yml

You're mixing the concepts of a "Role"
https://docs.ansible.com/ansible/latest/user_guide/playbooks_reuse_roles.html#roles
and a "Playbook"
https://docs.ansible.com/ansible/latest/user_guide/playbooks.html

1) Move the directory "testVar" into the directory "roles". Remove "hosts" and
"ansible.cfg" from the role and put them into the current directory.

├── playbook.yml
├── hosts
├── ansible.cfg
├── roles
│ └── testVar

[root@cluster-mgmt testVar]# tree
├── defaults
│ └── main.yml
├── files
├── handlers
│ └── main.yml
├── meta
│ └── main.yml
├── README.md
├── tasks
│ └── main.yml
├── templates
├── tests
│ ├── inventory
│ └── test.yml
└── vars
└── main.yml

2) Make sure "ansible.cfg" points to the roles

$ grep roles ansible.cfg
roles_path = $PWD/roles

3) Create playbook.yml

- hosts: localhost
name: CLUSTERS team downtime orchestration play
gather_facts: true
roles:
- testVar

4) Remove the playbook directives from roles/testVar/tasks/main.yml

# tasks file for testVar
- name: set nagios downtime
debug:
msg: "the value of the variable {{ myTestVar }}"

5) Now the command should work

$ ansible-playbook -i hosts -c ansible.cfg playbook.yml

HTH,

-vlado

misterT1958

unread,
Feb 11, 2020, 10:13:14 AM2/11/20
to Ansible Project
Ah,

now I see what you mean - got it working!  Thanks so much for the hand!

kind regards,
T
Reply all
Reply to author
Forward
0 new messages