gpt4 book ai didi

vagrant - ansible : get roles from playbook in a subfolder

转载 作者:行者123 更新时间:2023-12-04 01:05:19 25 4
gpt4 key购买 nike

我有这棵树:

├── 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/
$

我从 vagrant 调用 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$

最佳答案

您可能可以使用变量 roles_path .它指向存储您的角色的文件夹。

关于vagrant - ansible : get roles from playbook in a subfolder,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36472017/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com