Virtualization
ansible 沒有找到劇本中提到的角色
我對 Ansible 很陌生,所以我可能配置錯誤
$$ 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 $$
我的意願是自動將 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: hiddai@foo.com 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 告訴你出了什麼問題:
[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 中的更改將被忽略。
修復此目錄的權限,然後重試。