Packer + ansible, how to specify an inventory file

When I use a stroller, I can specify the inventory file in Vagrantfile.

Example:

config.vm.provision "ansible" do |ansible|
    ansible.playbook = "my_folder/playbook.yml"
    ansible.inventory_path = "my_folder/inventory_file"
end

How to configure inventory_file when using a package?

I do not see any information in the official documentation of the packer:

http://www.packer.io/docs/provisioners/ansible-local.html

I need to specify an inventory file, because when I run my packer.json file, this is the output:

digitalocean: Executing Ansible: ansible-playbook /tmp/my_folder/playbook.yml -c local -i "127.0.0.1,"
digitalocean:
digitalocean: PLAY [foo] ******************************************************************
digitalocean: skipping: no hosts matched

The packer seems to be using an inventory file named "127.0.0.1", and I don't know why.

How can I specify an inventory file?

Thank!

+4
source share
2 answers

, , , (-c local), .

, -hosts all 127.0.0.1, .

+4

hosts: all , playbook Packer.

, , , :

[web_servers]
web1.example.com
web2.example.com

[db_servers]
db.example.com

... inventory_groups ansible-local, Packer localhost :

"provisioners": [ 
  { "type": "file", "source": "my_folder", "destination": "/tmp/" }, 
  { "type": "shell", "script": "provisioner.sh" }, 
  { 
    "type": "ansible-local", 
    "staging_directory": "/tmp/my_folder",
    "playbook_file": "my_folder/playbook.yml",
    "inventory_groups": "web_servers"
  }
]

. Packer

+2

All Articles