# How do I use multiple ansible versions on the same machine for different playbooks that require specific versions?

**URL:** <https://forum.ansible.com/t/how-do-i-use-multiple-ansible-versions-on-the-same-machine-for-different-playbooks-that-require-specific-versions/20506>\
**Category:** Ansible Project\
**Created:** [February 10, 2016, 7:16am UTC](https://forum.ansible.com/t/how-do-i-use-multiple-ansible-versions-on-the-same-machine-for-different-playbooks-that-require-specific-versions/20506 "2016-02-10T07:16:11Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Philip\_Kirkland](https://avatars.discourse-cdn.com/v4/letter/p/5f8ce5/32.png) [@Philip\_Kirkland](https://forum.ansible.com/u/Philip_Kirkland)\
**Post date:** [February 10, 2016, 7:16am UTC](https://forum.ansible.com/t/how-do-i-use-multiple-ansible-versions-on-the-same-machine-for-different-playbooks-that-require-specific-versions/20506/1 "2016-02-10T07:16:11Z")

</div>

Hi all,

Perhaps I’m approaching this the wrong way; I would appreciate some feedback.

We have various playbooks that have been developed over a period of time. Due to the (sometimes) lack of backwards compatibility of ansible, some playbooks might require a specific version. I don’t want to run this on different ansible runtime/orchestration servers; I’d like to be able to handle this on the one server.

In previous versions (prior to the core/extras submodule being split out), we could typically download some tar.gz releases and unzip/extract them into different directories. Then prior to running a playbook we could source hacking/env-setup for the specific version that we needed and could run the playbook.

For example:

`  
source ansible-1.7.2/hacking/env-setup

# run my ansible-playbook that requires version 1.7.2

source ansible-1.6.3/hacking/env-setup  
#run my ansible-playbook that requires version 1.6.3  
`

The above does not work since the core and extras modules became git submodules as outlined below.

Now I have a couple of options:

1. Take a release (such as [http://releases.ansible.com/ansible/ansible-2.0.0.2.tar.gz](http://releases.ansible.com/ansible/ansible-2.0.0.2.tar.gz)). This doesn’t have the hacking directory so how do I configure my environment? I don’t want to run setup since doing this for different versions will override each other, and running jobs in parallel would certainly get issues if I did this. Hence I don’t have an easy mechanism of catering for different versions.

2. Take a source tar.gz (such as [https://github.com/ansible/ansible/archive/v2.0.0.2-1.tar.gz](https://github.com/ansible/ansible/archive/v2.0.0.2-1.tar.gz)). Whilst this gives me the hacking directory the lib/ansible/modules/core and lib/ansible/modules/extras (which correspond to the git submodules) are empty, so I would need to obtain those as well. How do I get those?

What I think would solve my issue is a tarball that includes all the source (including the git submodules) as well as the hacking directory.

Or am I going about this the wrong way?

Thanks for any help, advice or pointers.

Phil

---

<div class="post-metadata">

**Author:** ![Bourgeois\_Ghislain\_6](https://avatars.discourse-cdn.com/v4/letter/b/2acd7d/32.png) [@Bourgeois\_Ghislain\_6](https://forum.ansible.com/u/Bourgeois_Ghislain_6)\
**Post date:** [February 10, 2016, 2:37pm UTC](https://forum.ansible.com/t/how-do-i-use-multiple-ansible-versions-on-the-same-machine-for-different-playbooks-that-require-specific-versions/20506/2 "2016-02-10T14:37:34Z")

</div>

Hi,

You can basically do what the env-setup script is doing with that in bash for example:

ANSIBLE=path-to-my-ansible-version  
export PATH=$PATH:$ANSIBLE/bin  
export PYTHONPATH=$ANSIBLE/lib  
export ANSIBLE\_LIBRARY=$ANSIBLE/library

You just need to manipulate those variables, so that should not be too bad to script.

Ghislain

---

<div class="post-metadata">

**Author:** ![profhase85](https://avatars.discourse-cdn.com/v4/letter/p/2bfe46/32.png) [@profhase85](https://forum.ansible.com/u/profhase85)\
**Post date:** [February 11, 2016, 4:33pm UTC](https://forum.ansible.com/t/how-do-i-use-multiple-ansible-versions-on-the-same-machine-for-different-playbooks-that-require-specific-versions/20506/3 "2016-02-11T16:33:47Z")

</div>

I would propose you to use python’s virtualenvs:

virtualenv ansible17  
source ansible17/bin/activate  
pip install ansible==1.7

# work with it

deactivate

# next time

source ansible17/bin/activate

It is the same approach as you are using, but as virtualenv encapsulates the whole environment, so you don’t need to bother about the dependencies

---

<div class="post-metadata">

**Author:** ![profhase85](https://avatars.discourse-cdn.com/v4/letter/p/2bfe46/32.png) [@profhase85](https://forum.ansible.com/u/profhase85)\
**Post date:** [February 11, 2016, 4:34pm UTC](https://forum.ansible.com/t/how-do-i-use-multiple-ansible-versions-on-the-same-machine-for-different-playbooks-that-require-specific-versions/20506/4 "2016-02-11T16:34:04Z")

</div>

I would propose you to use python’s virtualenvs:

virtualenv ansible17  
source ansible17/bin/activate  
pip install ansible==1.7

# work with it

deactivate

# next time

source ansible17/bin/activate

It is the same approach as you are using, but as virtualenv encapsulates the whole environment, so you don’t need to bother about the dependencies

---

<div class="post-metadata">

**Author:** ![Subramanian\_P\_V](https://avatars.discourse-cdn.com/v4/letter/s/53a042/32.png) [@Subramanian\_P\_V](https://forum.ansible.com/u/Subramanian_P_V)\
**Post date:** [July 28, 2016, 11:57pm UTC](https://forum.ansible.com/t/how-do-i-use-multiple-ansible-versions-on-the-same-machine-for-different-playbooks-that-require-specific-versions/20506/5 "2016-07-28T23:57:42Z")

</div>

Hi Philip,

I am facing the same situation. Is there a way to run ansible like an excutable like sourcing in old environments. I have a setup where ansible 1.5 is present and on the same machine i need to execute the ansible scripts of 2.0.0.2 version

Thanks

Regards  
Subramanian

---

<div class="post-metadata">

**Author:** ![Carlos\_A\_Carnero\_Del](https://avatars.discourse-cdn.com/v4/letter/c/7ea924/32.png) [@Carlos\_A\_Carnero\_Del](https://forum.ansible.com/u/Carlos_A_Carnero_Del)\
**Post date:** [July 31, 2016, 7:44pm UTC](https://forum.ansible.com/t/how-do-i-use-multiple-ansible-versions-on-the-same-machine-for-different-playbooks-that-require-specific-versions/20506/6 "2016-07-31T19:44:09Z")

</div>

IMO, the best option in this case is to make use of Python virtual  
environments, and install Ansible via pip  
\<[http://docs.ansible.com/ansible/intro\_installation.html#latest-releases-via-pip&gt;\](http://docs.ansible.com/ansible/intro_installation.html#latest-releases-via-pip&gt;%5C).  
You can have several virtual environments, each with different Ansible  
versions, and then activate the one you need prior to running your  
playbooks.

HTH,  
Carlos.

---

<div class="post-metadata">

**Author:** ![Mike\_Biancaniello](https://avatars.discourse-cdn.com/v4/letter/m/dec6dc/32.png) [@Mike\_Biancaniello](https://forum.ansible.com/u/Mike_Biancaniello)\
**Post date:** [August 1, 2016, 1:38pm UTC](https://forum.ansible.com/t/how-do-i-use-multiple-ansible-versions-on-the-same-machine-for-different-playbooks-that-require-specific-versions/20506/7 "2016-08-01T13:38:20Z")

</div>

I would also suggest python virtual environments.

Although, I have also used Docker images for running Ansible. I create a Docker image with ‘ansible’ as the ENTRYPOINT, then create a shell script to execute ‘docker run -it --rm \<image\_name\> \<playbook\_name\> []’. This will execute ansible inside the docker and use the playbooks that you put inside the image when you created it.
