Ansible 1.6.7+ issue : quote variables with equal signs > stdout.in Ievgen Kuzminov IT blog

Ansible 1.6.7+ issue : quote variables with equal signs

Aug 5, 2014, 5:37:44 PM

I have noticed that on Ansible 1.6.10 my old stable playbooks are not working. It shows an error :
A variable inserted a new parameter into the module args. Be sure to quote variables if they contain equal signs (for example: "{{var}}").

There is a huge conversation on GitHub around different appearances of this isssue.

Solutinon

  • Rollback to Ansible <= 1.6.6 (you can find .deb packages here).
  • Or change your playbook and ad quotes around all shell string that contain "=" sign (atleast I've got such understanding while searchin the solution).

It appears that you can't do something like this now (combine actual shell command and some shell module arguments like creates)

    - name: Configure ZSH (Install oh-my-zsh)
      shell: "{{ item }}"
      with_items:
        - creates='/home/vagrant/.oh-my-zsh' su - vagrant -c 'wget https://github.com/robbyrussell/oh-my-zsh/raw/master/tools/install.sh -O - | zsh'
        - sed -i 's/ZSH_THEME="robbyrussell"/ZSH_THEME="jreese"/' /home/vagrant/.zshrc

So with_items now strictly for typical operations with same "template". And in case like above we will need to write separate task for each step (yes I agree that was a mess doing like that... but I liked it for a quick Shell -> Ansible convertation).

NB! Actually these errors started from very-very weird one.

Traceback (most recent call last):
  File "/usr/bin/ansible-playbook", line 317, in <module>
    sys.exit(main(sys.argv[1:]))
  File "/usr/bin/ansible-playbook", line 257, in main
    pb.run()
  File "/usr/lib/pymodules/python2.7/ansible/playbook/__init__.py", line 289, in run
    play = Play(self, play_ds, play_basedir, vault_password=self.vault_password)
  File "/usr/lib/pymodules/python2.7/ansible/playbook/play.py", line 152, in __init__
    self._tasks      = self._load_tasks(self._ds.get('tasks', []), load_vars)
  File "/usr/lib/pymodules/python2.7/ansible/playbook/play.py", line 576, in _load_tasks
    (k,v) = t.split("=", 1)
ValueError: need more than 1 value to unpack

It is actually caused by constructions like
include: vhosts.yml vhosts={{ vhosts }}
it should be replaced like this
include: vhosts.yml vhosts="{{ vhosts }}"

Solution for [WARNING]: It is unnecessary to use '{{' in loops, leave variables in loop expressions bare.

This kind of error apperas when you use something liek this
with_items: "{{ vhosts }}"
you should use
with_items: vhosts

comments powered by Disqus
Ievgen
Kuzminov "iJackUA"
Web Team Lead
at MobiDev (Kharkiv, Ukraine)
Code in Ruby and Elixir, but still love PHP. Explore ES6 and Vue.js. Explore databases, use Ubuntu and MacOS, think about IT people and management

Notes