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