Ansible : running stable source version with Git

Ansible logo

As stated in the documentation, running Ansible from source using Git is straightforward:

$ git clone git://github.com/ansible/ansible.git --recursive
$ cd ./ansible
$ source ./hacking/env-setup

At this point, Ansible and some Git submodules track the devel branch:

$ ansible --version|head -n 1
ansible 2.0.0 (devel 24b830bbc8) last updated 2015/07/13 23:35:57 (GMT +200)

$ git submodule status
 9acf10face033dda6d5b1f570fb35cbd3deabac5 lib/ansible/modules/core (remotes/origin/v1_modules-441-g9acf10f)
 8a89f4afe452868eccdb8eab841cb501b7bf0548 lib/ansible/modules/extras (heads/devel)
 f8d8af17cdc72500af8319c96004b86ac702a0a4 v1/ansible/modules/core (remotes/origin/v1_modules)
 495ad450e53feb1cd26218dc68056cc34d1ea9ff v1/ansible/modules/extras (495ad45)

However, if you want to stick with the stable branch, be sure to keep both Ansible and submodules synced to the same release.

After several backs and forth between versions for testing purposes, I made the mistake to run a stable Ansible version with some devel version submodules:

$ ansible --version
ansible 1.9.2 (stable-1.9 5d1fb380fc) last updated 2015/07/13 23:22:21 (GMT +200)
  lib/ansible/modules/core: (detached HEAD 9acf10face) last updated 2015/07/13 23:20:04 (GMT +200)
  lib/ansible/modules/extras: (detached HEAD 8a89f4afe4) last updated 2015/07/13 23:20:08 (GMT +200)
  v2/ansible/modules/core: (detached HEAD 85c8a892c8) last updated 2015/07/13 23:22:42 (GMT +200)
  v2/ansible/modules/extras: (detached HEAD 70ea058563) last updated 2015/07/13 23:22:50 (GMT +200)
  configured module search path = None

Many playbooks just run fine, however some very weird behavior occur without any reason:

Some examples:

# Playbook:

- name: Depots par defaut
  sudo: yes
  apt_repository: repo='{{ item }}' state=present
  with_items:
    - 'deb http://mirrors.online.net/debian wheezy main non-free contrib'
    - 'deb http://security.debian.org/ wheezy/updates main contrib non-free'

# Error output:

TASK: [common | Depots par defaut] ********************************************* 
failed: [localhost] => (item=deb http://mirrors.online.net/debian wheezy main non-free contrib) => {"failed": true, "item": "deb http://mirrors.online.net/debian wheezy main non-free contrib", "parsed": false}
BECOME-SUCCESS-tcgojdpvufczunopwoquyzausoacxoes
Traceback (most recent call last):
  File "/home/loic/.ansible/tmp/ansible-tmp-1436823812.86-276372001838864/apt_repository", line 2781, in <module>
    main()
  File "/home/loic/.ansible/tmp/ansible-tmp-1436823812.86-276372001838864/apt_repository", line 453, in main
    if state == 'present' and expanded_repo not in sourceslist.repos_urls:
AttributeError: 'SourcesList' object has no attribute 'repos_urls'

And my favorite:

# Playbook:

- name: Creation /dev/net/tun
  sudo: yes
  action: command mknod /dev/net/tun c 10 200 creates=/dev/net/tun

# Error output:

TASK: [vpn.vz | Creation /dev/net/tun] ********************************* 
failed: [vpn.vz] => {"failed": true}
msg: this module requires key=value arguments (['mknod', '/dev/net/tun', 'c', '10', '200', 'creates=/dev/net/tun'])

FATAL: all hosts have already failed -- aborting

The relation between failing tasks and version mismatch was not very obvious to me, especially because only some modules fail to play correctly.

So, to correctly run a stable version of Ansible from source using Git, specify the stable branch during the initial clone:

$ git clone git://github.com/ansible/ansible.git --recursive -b stable-1.9

All the submodules will also track the stable branch, and everything is going to be ok:

$ cat ansible/.gitmodules 
[submodule "lib/ansible/modules/core"]
    path = lib/ansible/modules/core
    url = https://github.com/ansible/ansible-modules-core.git
    branch = stable-1.9
[submodule "lib/ansible/modules/extras"]
    path = lib/ansible/modules/extras
    url = https://github.com/ansible/ansible-modules-extras.git
    branch = stable-1.9
[submodule "v2/ansible/modules/core"]
    path = v2/ansible/modules/core
    url = https://github.com/ansible/ansible-modules-core.git
    branch = stable-1.9
[submodule "v2/ansible/modules/extras"]
    path = v2/ansible/modules/extras
    url = https://github.com/ansible/ansible-modules-extras.git
    branch = stable-1.9