“skipping: no hosts matched” issue with Vagrant and Ansible

前端 未结 9 1104

I have installed Vagrant, VirtualBox and Ansible and trying to run provision over one host but it always returns \"skipping: no hosts matched\"

The head of my playbook f

相关标签:
9条回答
  • 2021-02-05 03:09

    Changing hosts to "all" worked for me.

    ---
    - hosts: all
      user: vagrant
      sudo: yes
    
    0 讨论(0)
  • 2021-02-05 03:10

    Make sure you're running ansible-playbook command instead of pure ansible command.

    0 讨论(0)
  • 2021-02-05 03:12

    The first thing that jumps out at me is that the syntax on the head of your playbook file is incorrect, (it has extra dashes where it shouldn't). It should look like this instead:

    ---
    - hosts: webservers
      user: vagrant
      sudo: yes
    
    0 讨论(0)
  • 2021-02-05 03:13

    I think you can also do this without a hosts file, by assigning the Ansible groups in your Vagrant file.

    If you don't have multiple machines in your Vagrant file your box will probably be called "default" and you will be able to add multiple Ansible groups with the following code.

    Code:

    config.vm.provision "ansible" do |ansible|
        ansible.groups = {
            "webservers" => ["default"],
            "dev_enviroment" => ["default"]
        }
    
        ansible.playbook = "provisioning/playbook.yml"
    end
    
    0 讨论(0)
  • 2021-02-05 03:13

    make sure you use this command "ansible-playbook -i yourhosts your.yml"

    0 讨论(0)
  • 2021-02-05 03:16

    According to the vagrant documentation (http://docs.vagrantup.com/v2/provisioning/ansible.html), when you use Ansible to provision, vagrant will automatically create an host file named vagrant_ansible_inventory_default which will use vagrant vm.config information (like your VM IP, remote ssh port).

    So just add your playbook path using the ansible.playbook = "playbook.yml"

    0 讨论(0)
提交回复
热议问题