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.
Written by Michel Blanc
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ansible
Authors
Misha Behersky
78.83K
tartansandal
73.25K
Related Tags
#ansible
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#