From 43c4707d2a62defb4829571903314409fe7c41d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Hertzog?= Date: Fri, 23 Feb 2018 15:51:34 +0100 Subject: [PATCH] Do not try to run git config when git is not available The state will not fail gracefully, instead you will get an error like this one: ID: users_rhertzog_user_gitconfig_0 Function: git.config_set Name: alias.br Result: False Comment: State 'git.config_set' was not found in SLS 'users' Reason: 'git' __virtual__ returned False Changes: And since pillar data can't be (easily) tuned according to minion's status, we really need this check here. My tests with Salt 2017.7.3 have shown that cmd.has_exec() is reliable for this, contrary the what the comment was implying. --- users/init.sls | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/users/init.sls b/users/init.sls index 0206ba3..aa9adf4 100644 --- a/users/init.sls +++ b/users/init.sls @@ -446,10 +446,6 @@ users_googleauth-{{ svc }}-{{ name }}: {%- endfor %} {%- endif %} -# -# if not salt['cmd.has_exec']('git') -# fails even if git is installed -# # this doesn't work (Salt bug), therefore need to run state.apply twice #include: # - users @@ -460,6 +456,7 @@ users_googleauth-{{ svc }}-{{ name }}: # - sls: users # {% if 'gitconfig' in user %} +{% if salt['cmd.has_exec']('git') %} {% for key, value in user['gitconfig'].items() %} users_{{ name }}_user_gitconfig_{{ loop.index0 }}: {% if grains['saltversioninfo'] >= [2015, 8, 0, 0] %} @@ -477,6 +474,7 @@ users_{{ name }}_user_gitconfig_{{ loop.index0 }}: {% endif %} {% endfor %} {% endif %} +{% endif %} {% endfor %}