How can I produce an Ansible inventory without provisioning?

In my workflow I run `vagrant up --no-provision` to bring the machines up, then do some other stuff and, only then do I need to run the provisioner. But this "other stuff" I am doing actually need the ansible inventory to be present. Is there a proper way to generate the inventory? Right now, after the --no-provision step, I run vagrant provision passing it an ansible tag called "none" which does not exist in my playbooks.

1 thought on “How can I produce an Ansible inventory without provisioning?”

  1. if you make the ip address and hostname a ruby variable in the Vagrantfile, you can use the var ip_address to also fill the inventory file:

    inventory_file=”ansible/inventory” “private_network”, ip: ip_address
    config.vm.hostname = hostname

    config.vm.provision “ansible” do |ansible|
    File.write(inventory_file, “#{hostname} ansible_ssh_host=#{ip_address} ansible_ssh_port=22”)

    edit: with a bit of ruby code the inventory_file will be filled at the moment of provisioning.
    edit2: shorter code


Leave a Comment