ansible 找不到剧本中提到的角色

ansible 找不到剧本中提到的角色

我对 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

在执行剧本来恢复实验室中的所有机器之前,我对剧本语法进行了一些检查:

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

答案1

Ansible 告诉你哪里出了问题:

[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

这意味着您在 ansible.cfg 中的更改将被忽略。

修复此目录的权限并重试。

相关内容