# I would like 'vagrant provision' to save my ansible\_python\_interpreter setting in the inventory file

**URL:** <https://forum.ansible.com/t/i-would-like-vagrant-provision-to-save-my-ansible-python-interpreter-setting-in-the-inventory-file/27025>\
**Category:** Ansible Project\
**Tags:** ubuntu\
**Created:** [March 18, 2018, 4:53am UTC](https://forum.ansible.com/t/i-would-like-vagrant-provision-to-save-my-ansible-python-interpreter-setting-in-the-inventory-file/27025 "2018-03-18T04:53:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tim\_Stewart](https://avatars.discourse-cdn.com/v4/letter/t/13edae/32.png) [@Tim\_Stewart](https://forum.ansible.com/u/Tim_Stewart)\
**Post date:** [March 18, 2018, 4:53am UTC](https://forum.ansible.com/t/i-would-like-vagrant-provision-to-save-my-ansible-python-interpreter-setting-in-the-inventory-file/27025/1 "2018-03-18T04:53:05Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![Gilles\_Cornu](https://avatars.discourse-cdn.com/v4/letter/g/ecccb3/32.png) [@Gilles\_Cornu](https://forum.ansible.com/u/Gilles_Cornu)\
**Post date:** [March 19, 2018, 6:47am UTC](https://forum.ansible.com/t/i-would-like-vagrant-provision-to-save-my-ansible-python-interpreter-setting-in-the-inventory-file/27025/2 "2018-03-19T06:47:17Z")

</div>

Hi Tim,

You can do this with the [host\_vars](https://www.vagrantup.com/docs/provisioning/ansible_common.html#host_vars) provisioner option.

Best,  
Gilles

PS: This question should better be asked in the [vagrant mailing list](https://groups.google.com/forum/#!forum/vagrant-up) 😉

---

<div class="post-metadata">

**Author:** ![Tim\_Stewart](https://avatars.discourse-cdn.com/v4/letter/t/13edae/32.png) [@Tim\_Stewart](https://forum.ansible.com/u/Tim_Stewart)\
**Post date:** [March 19, 2018, 2:41pm UTC](https://forum.ansible.com/t/i-would-like-vagrant-provision-to-save-my-ansible-python-interpreter-setting-in-the-inventory-file/27025/3 "2018-03-19T14:41:54Z")

</div>

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!
