I would like 'vagrant provision' to save my ansible_python_interpreter setting in the inventory file

Ansible Version:

`

$ ansible --version
ansible 2.4.3.0
config file = /home/tim/AnsibleFun/ansible.cfg
configured module search path = [u’/home/tim/.ansible/plugins/modules’, u’/usr/share/ansible/plugins/modules’]
ansible python module location = /usr/lib/python2.7/dist-packages/ansible
executable location = /usr/bin/ansible
python version = 2.7.12 (default, Dec 4 2017, 14:50:18) [GCC 5.4.0 20160609]

`

Vagrant Version:

`

$ vagrant --version
Vagrant 2.0.3

`

Ubuntu Version:

`

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 16.04.4 LTS
Release: 16.04
Codename: xenial

`

Here is ./ansible.cfg:

`

[defaults]
inventory = .vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory
nocows = 1

[privilege_escalation]

These are required to enable ansible to escalate privileges for installing

software.

become = True
become_method = sudo
become_user = root

`

Here is my Vagrantfile:

`

Vagrant.configure(“2”) do |config|

config.vm.define “traffic” do |traffic|
traffic.vm.box = “ubuntu/xenial64”

Perform ansible provisioning

config.vm.provision “ansible” do |ansible|

Specify the playbook to use

ansible.playbook = “playbooks/traffic_playbook.yml”

Specify Ansible compatibility mode

ansible.compatibility_mode = “2.0”

ansible.extra_vars = { ansible_python_interpreter: “/usr/bin/python3” }
end
end
end

`

When I run vagrant provision, an inventory file is created containing:

`

Generated by Vagrant

traffic ansible_host=127.0.0.1 ansible_port=2222 ansible_user=‘vagrant’ ansible_ssh_private_key_file=‘/home/tim/AnsibleFun/.vagrant/machines/traffic/virtualbox/private_key’

`

When I run the ad-hoc command: ansible all -m ping

I get:

`

traffic | FAILED! => {
“changed”: false,
“module_stderr”: “Shared connection to 127.0.0.1 closed.\r\n”,
“module_stdout”: “/bin/sh: 1: /usr/bin/python: not found\r\n”,
“msg”: “MODULE FAILURE”,
“rc”: 0
}

`

Now if I add an ansible_python_interpreter setting to my inventory file, the ad hoc command succeeds:

`

traffic | SUCCESS => {
“changed”: false,
“ping”: “pong”
}

`

But when I run: vagrant provision again, the ansible_python_interpreter setting is removed from my inventory file loses and my ad hoc commands start failing again with the /usr/bin/python not found error.

Is there some Vagrantfile syntax I can use to persist the ansible_python_interpreter setting in my inventory file?

Thanks!

Hi Tim,

You can do this with the host_vars provisioner option.

Best,
Gilles

PS: This question should better be asked in the vagrant mailing list :wink:

Giles,
Thanks for your helpful answer! As I was drifting off to sleep, I realized my question might have been a better fit for the Vagrant group.

Have a great day!