我尝试对本地主机播放以下剧本来配置 Vagrant 机器
---
- hosts: all
become: yes
roles:
- base
- jenkins
我已经从 github 克隆了必要的角色,它们位于相对路径中
roles/{role name}
执行以下命令:
ansible-playbook -i "localhost," -c local playbook.yml
输出此错误:
==> default: ERROR! the role 'geerlingguy.java' was not found in /home/vagrant/provisioning/roles:/home/vagrant/provisioning:/etc/ansible/roles:/home/vagrant/provisioning/roles
==> default:
==> default: The error appears to have been in '/home/vagrant/provisioning/roles/jenkins/meta/main.yml': line 3, column 5, but may
==> default: be elsewhere in the file depending on the exact syntax problem.
==> default:
==> default: The offending line appears to be:
==> default:
==> default: dependencies:
==> default: - geerlingguy.java
==> default: ^ here
我从 github 克隆了缺少的依赖项,并尝试将其驻留在
roles/java
和 roles/geerlingguy/java
的相对路径中,但都没有解决问题,并且错误保持不变。
我想将所有角色保留在同步的配置文件夹中,而不使用 ansible-galaxy 运行时,以使配置方法尽可能自包含。
这是现在的配置文件夹结构
.
├── playbook.yml
└── roles
├── base
│ └── tasks
│ └── main.yml
├── java
│ ├── defaults
│ │ └── main.yml
│ ├── meta
│ │ └── main.yml
│ ├── README.md
│ ├── tasks
│ │ ├── main.yml
│ │ ├── setup-Debian.yml
│ │ ├── setup-FreeBSD.yml
│ │ └── setup-RedHat.yml
│ ├── templates
│ │ └── java_home.sh.j2
│ ├── tests
│ │ └── test.yml
│ └── vars
│ ├── Debian.yml
│ ├── Fedora.yml
│ ├── FreeBSD.yml
│ ├── RedHat.yml
│ ├── Ubuntu-12.04.yml
│ ├── Ubuntu-14.04.yml
│ └── Ubuntu-16.04.yml
└── jenkins
├── defaults
│ └── main.yml
├── handlers
│ └── main.yml
├── meta
│ └── main.yml
├── README.md
├── tasks
│ ├── main.yml
│ ├── plugins.yml
│ ├── settings.yml
│ ├── setup-Debian.yml
│ └── setup-RedHat.yml
├── templates
│ └── basic-security.groovy
├── tests
│ ├── requirements.yml
│ ├── test-http-port.yml
│ ├── test-jenkins-version.yml
│ ├── test-plugins-with-pinning.yml
│ ├── test-plugins.yml
│ ├── test-prefix.yml
│ └── test.yml
└── vars
├── Debian.yml
└── RedHat.yml
您应该在/roles
文件夹(或系统文件夹)中安装或克隆
所有所需的角色
ansible-galaxy install -p ROLES_PATH geerlingguy.java
应该解决这个特定问题。
但是,最佳实践应该使用
requirements.yml
文件,您需要所有需要的角色,然后使用ansible-galaxy
直接在您的剧本中安装它们。
- name: run ansible galaxy
local_action: command ansible-galaxy install -r requirements.yml --ignore-errors
简单的符号链接就像一个魅力,无需任何安装:
$ mkdir /home/USER/ansible && ln -s /home/USER/GIT/ansible-root/roles
解决方案如下:角色所需路径是
roles/geerlingguy.java/
,而不是roles/geerlingguy/java/
另一种解决方案:在根级别添加
ansible.cfg
:
[defaults]
roles_path = ..