使用Vagrant和Ansible提供ubuntu/xenial64

使用Vagrant和Ansible提供ubuntu/xenial64,vagrant,ansible,Vagrant,Ansible,我正在尝试使用Vagrant创建一个vm,并使用Ansible提供它。已安装的工具版本包括: 流浪汉:2.0.0 Ansible:2.3.2.0 Python:2.7.10 Virtualbox:5.1.30 以下是我正在运行vagrant的目录的内容: 以下是文件的内容: 剧本/main.yml: 剧本/目录: 剧本/vars.yml: docker_edition: 'ce' docker_package: "docker-{{ docker_edition }}" docker_packa

我正在尝试使用Vagrant创建一个vm,并使用Ansible提供它。已安装的工具版本包括:

流浪汉:2.0.0 Ansible:2.3.2.0 Python:2.7.10 Virtualbox:5.1.30

以下是我正在运行vagrant的目录的内容:

以下是文件的内容:

剧本/main.yml:

剧本/目录:

剧本/vars.yml:

docker_edition: 'ce'
docker_package: "docker-{{ docker_edition }}"
docker_package_state: present
当我运行vagrant up时,输出为:

==> default: Checking for guest additions in VM...
    default: The guest additions on this VM do not match the installed version of
    default: VirtualBox! In most cases this is fine, but in rare cases it can
    default: prevent things such as shared folders from working properly. If you see
    default: shared folder errors, please make sure the guest additions within the
    default: virtual machine match the version of VirtualBox you have installed on
    default: your host and reload your VM.
    default: 
    default: Guest Additions Version: 5.0.40
    default: VirtualBox Version: 5.1
==> default: Setting hostname...
==> default: Configuring and enabling network interfaces...
==> default: Mounting shared folders...
    default: /vagrant => /Users/danilo/tutorials/ansible ubuntu
==> default: Running provisioner: ansible...
    default: Running ansible-playbook...
PYTHONUNBUFFERED=1 ANSIBLE_FORCE_COLOR=true ANSIBLE_HOST_KEY_CHECKING=false ANSIBLE_SSH_ARGS='-o UserKnownHostsFile=/dev/null -o IdentitiesOnly=yes -o IdentityFile=/Users/danilo/tutorials/ansible ubuntu/.vagrant/machines/default/virtualbox/private_key -o ControlMaster=auto -o ControlPersist=60s' ansible-playbook --connection=ssh --timeout=30 --extra-vars=ansible_user\=\'ubuntu\' --limit="default" --inventory-file=playbooks/inventory --become -v playbooks/main.yml
No config file found; using defaults
ERROR! Specified --limit does not match any hosts
Ansible failed to complete successfully. Any error output should be
visible above. Please fix these errors and try again.
然而,流浪的ssh工作正常。你知道我遗漏了什么吗?

首先,如果你使用hosts:ubuntu,那么你必须定义命名机器:

config.vm.define "ubuntu" do |ubuntu|
  ubuntu.vm.provision "ansible" do |ansible|
    ansible.playbook = "playbooks/main.yml"
    ansible.sudo = true
    ansible.verbose = true
    ansible.inventory_path = "playbooks/inventory"
    ansible.compatibility_mode = "2.0"
  end
end
否则更改为主机:播放中的默认值

但是

我不知道您为什么要尝试通过192.168.33.7进行配置-对于这个用例来说似乎完全没有必要-您可以从文件中删除ansible.inventory\u路径 在同一个清单文件中,您指定了未在ubuntu/xenial64框中配置的用户vagrant ansible.sudo在Vagrant文件中也不是必需的 在ubuntu/xenial64上以这种方式运行Ansible可能会因为缺少Python2而失败
在做了这些更改并再次运行之后,我得到了PLAY[192.168.33.7]************************************************************************************************************跳过:没有匹配的主机请更加努力。
[ubuntu]
192.168.33.7

[ubuntu:vars]
ansible_ssh_user=vagrant
ansible_ssh_private_key_file=~/.vagrant.d/insecure_private_key
docker_edition: 'ce'
docker_package: "docker-{{ docker_edition }}"
docker_package_state: present
==> default: Checking for guest additions in VM...
    default: The guest additions on this VM do not match the installed version of
    default: VirtualBox! In most cases this is fine, but in rare cases it can
    default: prevent things such as shared folders from working properly. If you see
    default: shared folder errors, please make sure the guest additions within the
    default: virtual machine match the version of VirtualBox you have installed on
    default: your host and reload your VM.
    default: 
    default: Guest Additions Version: 5.0.40
    default: VirtualBox Version: 5.1
==> default: Setting hostname...
==> default: Configuring and enabling network interfaces...
==> default: Mounting shared folders...
    default: /vagrant => /Users/danilo/tutorials/ansible ubuntu
==> default: Running provisioner: ansible...
    default: Running ansible-playbook...
PYTHONUNBUFFERED=1 ANSIBLE_FORCE_COLOR=true ANSIBLE_HOST_KEY_CHECKING=false ANSIBLE_SSH_ARGS='-o UserKnownHostsFile=/dev/null -o IdentitiesOnly=yes -o IdentityFile=/Users/danilo/tutorials/ansible ubuntu/.vagrant/machines/default/virtualbox/private_key -o ControlMaster=auto -o ControlPersist=60s' ansible-playbook --connection=ssh --timeout=30 --extra-vars=ansible_user\=\'ubuntu\' --limit="default" --inventory-file=playbooks/inventory --become -v playbooks/main.yml
No config file found; using defaults
ERROR! Specified --limit does not match any hosts
Ansible failed to complete successfully. Any error output should be
visible above. Please fix these errors and try again.
config.vm.define "ubuntu" do |ubuntu|
  ubuntu.vm.provision "ansible" do |ansible|
    ansible.playbook = "playbooks/main.yml"
    ansible.sudo = true
    ansible.verbose = true
    ansible.inventory_path = "playbooks/inventory"
    ansible.compatibility_mode = "2.0"
  end
end