Last Updated: February 25, 2016
·
366
· leucos

Check mode and missing registered variables

When you run in --check mode, shell module is skipped. If you use it to register some variables, you might want to add a when_set condition to plays that use this variable in templates, so template generation doesn't break.

Here is an example :

- name: Tmux | Gets installed Tmux version
  shell: tmux -V
  register: tmux_version

- name: Tmux | Adds .tmux.conf for user
  template: src=tpl/tmux.j2 dest=~user/.tmux.conf 
  when_set: $tmux_version

In check mode, shell module is skipped, so without the when_set here, if you'd use $tmux_version in the template , the module would bail out complaining about an undefined variable.