I'm pretty new with Ansible so I might configured things wrong
[I have a Docker container running Ansible service in it
I have an Ansible repository that include the Ansible files (this is a .Git repository]
My will was to automatically revert each lab in vCenter server to a specific snapshot
So, I (with the help of ansible-roles-explained-with-examples guide):
- Created a role with
ansible-galaxy init
command name vcenter
(see directory tree below)
- Created some vcenter tasks files inside
tasks
folder (see directory tree below). Here is an example of rever.yml
task file:
- name: Revert to a snapshot
vmware_guest_snapshot:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
datacenter: "{{ datacenter_name }}"
state: revert
snapshot_name: CLEAN
delegate_to: localhost
- Supplied vCenter credentials in
vcenter\vars\main.yml
file, like this:
# vars file for vcenter
vcenter_hostname: vcenter.foo.com
vcenter_username: [email protected]
vcenter_password: f#0$o#1$0o
- Included the tasks in
tasks\main.yml
file with import-task
key, like this:
---
# tasks file for roles/vcenter
- import_tasks: poweroff.yml
- import_tasks: poweron.yml
- import_tasks: revert.yml
- import_tasks: shutdown.yml
- Created a
revert_lab.yml
playbook that include the role, like this
---
- name: revert an onpremis lab
hosts: all
roles:
- vcenter
Before I executed the playbook to revert all the machines in the lab, I ran a little check
of the playbook syntax:
ansible-playbook playbooks/revert_lab.yml --syntax-check
The error I got was:
[WARNING]: Ansible is being run in a world writable directory (/ansible), ignoring it as an ansible.cfg source. For more information see
https://docs.ansible.com/ansible/devel/reference_appendices/config.html#cfg-in-world-writable-dir
[DEPRECATION WARNING]: Ansible will require Python 3.8 or newer on the controller starting with Ansible 2.12. Current version: 3.6.8 (default, Nov 16 2020, 16:55:22) [GCC
4.8.5 20150623 (Red Hat 4.8.5-44)]. This feature will be removed from ansible-core in version 2.12. Deprecation warnings can be disabled by setting
deprecation_warnings=False in ansible.cfg.
[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'
ERROR! the role 'vcenter' was not found in /ansible/playbooks/roles:/root/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles:/ansible/playbooks
The error appears to be in '/ansible/playbooks/revert_lab.yml': line 5, column 5, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
roles:
- vcenter
^ here
I decided to add ansible.cfg
to my repository with the a roles_path
key:
[defaults]
inventory = /ansible/inventories
roles_path = /ansible/roles
# roles_path = ./roles:..~/ansible/roles
I ran again the --syntax-check
command but got the same error. I tried different kind of role path statments - and got the same error. Of course ansible-playbook
command wasn't work (with the same error message):
ansible-playbook playbooks/revert_lab.yml -i inventories/test/onpremis/domain.com/lab_r.yml
So,
How do I make ansible to recognize my role?
How do I make ansible to run successfully my playbook?
Is ansible.cfg relevant or irrelevant to the "story"?
My repository:
C:.
├───ansible
│ │ ansible.cfg
│ ├───inventories
│ │ └───test
│ │ ├───cloud
│ │ └───onpremis
│ │ └───domain.com
│ │ │ lab_j.yml
│ │ │ lab_r.yml
│ │ └───group_vars
│ │ all.yml
│ ├───playbooks
│ │ revert_lab.yml
│ └───roles
│ └───vcenter
│ ├───tasks
│ │ main.yml
│ │ poweroff.yml
│ │ poweron.yml
│ │ revert.yml
│ │ shutdown.yml
│ └───vars
│ main.yml