出于测试目的,我已经配置了vagrant / virtualbox / ansible的组合。
版本>> Ansible:2.3.1.0 |流浪汉:1.9.5。
跑步时:
vagrant provision
输出状态:
web1: Running provisioner: ansible...
web1: Running ansible-playbook...
PLAY [Install Apache]
**********************************************************
skipping: no hosts matched
PLAY RECAP
****************************************************************
配置文件下方:
Vagrantfile:
Vagrant.configure("2") do |config|
config.vm.box = "centos/7"
config.vm.define "web1"
config.vm.network "private_network", type: "dhcp"
config.vm.network "forwarded_port", guest: 8040, host: 8090
config.vm.provider "virtualbox" do |vb|
vb.memory = "256"
config.vm.provision "ansible" do |ansible|
ansible.playbook = "provisioning/playbook.yml"
end
end
end
Playbook:
---
- name: Install Apache
hosts: testclients
become_user: root
roles:
- apache
安全库存(/ etc / ansible / hosts):
[testclients]
testclient3
并成功检查
ansible -m ping testclients
testclient3 | SUCCESS => {
"changed": false,
"ping": "pong"
}
奇怪的是,如果我将自己运行剧本(ansible-playbook playbook.yml),它会起作用,相反在没有并且返回“没有主机匹配”的流浪者中。 任何帮助将不胜感激。
答案 0 :(得分:1)
由于您没有声明Vagrant使用的清单文件,因此它不匹配,因此它不会返回与testclients匹配的主机。
您可以使用以下选项来解决问题
在Playbook定义中,更改主机定义
---
- name: Install Apache
hosts: all
become_user: root
即使它最终不是你想要的,试试一下,确保一切正常。
在您的Vagrantfile中
config.vm.provision "ansible" do |ansible|
ansible.playbook = "provisioning/playbook.yml"
ansible.inventory_path = "path_to_your_file"
end
您需要确保告知如何访问该实例,以便您需要清单
testclient3 ansible_ssh_host=127.0.0.1 ansible_ssh_port=2200 ansible_ssh_user='vagrant' ansible_ssh_private_key_file='path to ssh key'
您需要vagrant来设置groups
config.vm.provision "ansible" do |ansible|
ansible.playbook = "provisioning/playbook.yml"
ansible.groups = {
"testclients" => ["testclient3"]
}
end
vagrant将生成库存文件