我对 Ansible 很陌生,所以我可能配置错误
[我有一个运行 Ansible 服务的 Docker 容器
我有一个包含 Ansible 文件的 Ansible 存储库(这是一个 .Git 存储库)
我的意愿是自动将 vCenter 服务器中的每个实验室恢复为特定快照
所以,我(在ansible-roles-explained-with-examples 指南的帮助下):
ansible-galaxy init
使用命令名称创建了一个角色vcenter
(参见下面的目录树)- 在文件夹内创建了一些 vCenter 任务文件
tasks
(请参见下面的目录树)。以下是rever.yml
任务文件的示例:
- 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
- 在文件中提供 vCenter 凭据
vcenter\vars\main.yml
,如下所示:
# vars file for vcenter
vcenter_hostname: vcenter.foo.com
vcenter_username: [email protected]
vcenter_password: f#0$o#1$0o
- 将任务包含在
tasks\main.yml
带有import-task
密钥的文件中,如下所示:
---
# tasks file for roles/vcenter
- import_tasks: poweroff.yml
- import_tasks: poweron.yml
- import_tasks: revert.yml
- import_tasks: shutdown.yml
- 创建了一个
revert_lab.yml
包含角色的剧本,就像这样
---
- name: revert an onpremis lab
hosts: all
roles:
- vcenter
在执行 playbook 以还原实验室中的所有机器之前,我对 playbook 语法进行了一些检查:
ansible-playbook playbooks/revert_lab.yml --syntax-check
我得到的错误是:
[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
我决定ansible.cfg
使用 a 键添加到我的存储库roles_path
:
[defaults]
inventory = /ansible/inventories
roles_path = /ansible/roles
# roles_path = ./roles:..~/ansible/roles
我再次运行--syntax-check
命令但得到了同样的错误。我尝试了不同类型的角色路径语句 - 并得到了同样的错误。当然ansible-playbook
命令不起作用(带有相同的错误消息):
ansible-playbook playbooks/revert_lab.yml -i inventories/test/onpremis/domain.com/lab_r.yml
那么,如何让 ansible 识别我的角色?
如何使 ansible 成功运行我的剧本?
ansible.cfg 与“故事”相关还是无关?
我的存储库:
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
Ansible 告诉你出了什么问题:
这意味着您在 ansible.cfg 中的更改将被忽略。
修复此目录的权限,然后重试。