Ansible 不安装来自 Git SCM 的依赖项
Ansible does not install dependency from Git SCM
我正在尝试创建一个名为 "Adminer" 的新 Ansible 角色,它需要 "Apache" 角色。
我在 meta/main.yml
中将 Apache 角色指定为依赖项:
---
dependencies:
- src: git+https@github.com:alexandrubau/ansible-apache.git
name: apache
我正在使用 Vagrant 测试管理员角色,但出现以下错误:
vagrant provision
==> default: Running provisioner: shell...
default: Running: inline script
==> default: Running provisioner: ansible_local...
Vagrant has automatically selected the compatibility mode '2.0'
according to the Ansible version installed (2.4.2.0).
Alternatively, the compatibility mode can be specified in your Vagrantfile:
https://www.vagrantup.com/docs/provisioning/ansible_common.html#compatibility_mode
default: Running ansible-playbook...
ERROR! the role 'apache' was not found in /vagrant/tests/roles:/home/vagrant/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles:/:/vagrant/tests
The error appears to have been in '/vagrant/meta/main.yml': line 3, column 5, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
dependencies:
- src: https://github.com/alexandrubau/ansible-apache.git
^ here
Ansible failed to complete successfully. Any error output should be
visible above. Please fix these errors and try again.
Ansible 不应该从提供的 git 存储库下载新角色吗?
这是我的 Vagrant 文件:
# -*- mode: ruby -*-
# vi: set ft=ruby :
$script = <<SCRIPT
mkdir -p /etc/ansible/roles
ln -f -s /vagrant /etc/ansible/roles/test-role
SCRIPT
Vagrant.configure("2") do |config|
config.vm.box = "bento/ubuntu-16.04"
config.vm.hostname = "ansible-test.local"
config.vm.network "private_network", ip: "192.168.13.37"
config.vm.synced_folder "../", "/vagrant"
config.vm.provider "virtualbox" do |vbox|
vbox.memory = 2048
vbox.cpus = 2
end
config.vm.provision "shell", inline: $script
config.vm.provision "ansible_local" do |ansible|
ansible.inventory_path = "tests/inventory"
ansible.playbook = "tests/test.yml"
ansible.limit = "localhost"
end
end
感谢您的帮助
因此,当您安装角色时,meta/main.yml
文件似乎只能由 ansible-galaxy
命令读取。
这在 official Ansible docs 中说明:
When dependencies are encountered by ansible-galaxy
, it will automatically install each dependency to the roles_path
. To understand how dependencies are handled during play execution, see...
我通过使用 requirements.yml
文件和 运行 找到了解决方法:
ansible-galaxy install -r requirements.yml
我正在尝试创建一个名为 "Adminer" 的新 Ansible 角色,它需要 "Apache" 角色。
我在 meta/main.yml
中将 Apache 角色指定为依赖项:
---
dependencies:
- src: git+https@github.com:alexandrubau/ansible-apache.git
name: apache
我正在使用 Vagrant 测试管理员角色,但出现以下错误:
vagrant provision
==> default: Running provisioner: shell...
default: Running: inline script
==> default: Running provisioner: ansible_local...
Vagrant has automatically selected the compatibility mode '2.0'
according to the Ansible version installed (2.4.2.0).
Alternatively, the compatibility mode can be specified in your Vagrantfile:
https://www.vagrantup.com/docs/provisioning/ansible_common.html#compatibility_mode
default: Running ansible-playbook...
ERROR! the role 'apache' was not found in /vagrant/tests/roles:/home/vagrant/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles:/:/vagrant/tests
The error appears to have been in '/vagrant/meta/main.yml': line 3, column 5, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
dependencies:
- src: https://github.com/alexandrubau/ansible-apache.git
^ here
Ansible failed to complete successfully. Any error output should be
visible above. Please fix these errors and try again.
Ansible 不应该从提供的 git 存储库下载新角色吗?
这是我的 Vagrant 文件:
# -*- mode: ruby -*-
# vi: set ft=ruby :
$script = <<SCRIPT
mkdir -p /etc/ansible/roles
ln -f -s /vagrant /etc/ansible/roles/test-role
SCRIPT
Vagrant.configure("2") do |config|
config.vm.box = "bento/ubuntu-16.04"
config.vm.hostname = "ansible-test.local"
config.vm.network "private_network", ip: "192.168.13.37"
config.vm.synced_folder "../", "/vagrant"
config.vm.provider "virtualbox" do |vbox|
vbox.memory = 2048
vbox.cpus = 2
end
config.vm.provision "shell", inline: $script
config.vm.provision "ansible_local" do |ansible|
ansible.inventory_path = "tests/inventory"
ansible.playbook = "tests/test.yml"
ansible.limit = "localhost"
end
end
感谢您的帮助
因此,当您安装角色时,meta/main.yml
文件似乎只能由 ansible-galaxy
命令读取。
这在 official Ansible docs 中说明:
When dependencies are encountered by
ansible-galaxy
, it will automatically install each dependency to theroles_path
. To understand how dependencies are handled during play execution, see...
我通过使用 requirements.yml
文件和 运行 找到了解决方法:
ansible-galaxy install -r requirements.yml