У меня есть это дерево:
├── plays
│ ├── ansible.cfg
│ ├── playbook_01.yml
│ ├── playbook_02.yml
│ └── playbook_03.yml
├── README.rst
├── roles
│ ├── role_A
│ │ ├── files
│ │ └── tasks
│ │ └── main.yml
│ └── role_B
│ ├── files
│ └── tasks
│ └── main.yml
├── serverlist
│ ├── client1_serverlist_prod
│ ├── client1_serverlist_test
│ ├── client1_serverlist_train
│ ├── client2_serverlist_prod
│ ├── client2_serverlist_test
│ └── client2_serverlist_train
└── vagrant
└── Vagrantfile
С файловой папкой ansible.cfg::
$ cat plays/ansible.cfg
[defaults]
roles_path=../roles/
$
Я вызываю из бродяги ansible.playbook::
$ grep playbook vagrant/Vagrantfile
ansible.playbook = "../plays/playbook_01.yml
на playbook_01.yml::
$ cat plays/playbook_01.yml
- hosts: vagrant
vars:
user: fox
home: /home/fox
roles:
- role_B
с роль_B::
$ cat roles/role_B/tasks/main.yml
---
- name: Create user group
group: name={{ user }} state=present
- name: Create home directory for user
file: state=directory path={{ home }} group=www-data owner={{ user }}
$
Но, возможно, только когда мы увидели роли в папке воспроизведения, я получаю эту ошибку::
vagrant$ vagrant provision
==> vagrant: Running provisioner: ansible...
PYTHONUNBUFFERED=1 ANSIBLE_HOST_KEY_CHECKING=false ANSIBLE_FORCE_COLOR=true
ANSIBLE_SSH_ARGS='-o UserKnownHostsFile=/dev/null -o IdentitiesOnly=yes -o
ForwardAgent=yes -o ControlMaster=auto -o ControlPersist=60s' ansible-playbook
--user=vagrant --connection=ssh --timeout=30 --limit='vagrant'
--inventory-file=/home/luis/lab/sandbox/akd-iac/stack/vagrant/.vagrant/provisioners/ansible/inventory
--sudo -vvvv ../plays/playbook_01.yml
ERROR: cannot find role in
~/stack/plays/roles/role_B or
~/stack/plays/role_B or /etc/ansible/roles/role_B
Ansible failed to complete successfully. Any error output should be
visible above. Please fix these errors and try again.
vagrant$