From 406078fddb1b05f46c52fae35fb990a353d44fd8 Mon Sep 17 00:00:00 2001 From: Jimmy McCrory Date: Tue, 23 Oct 2018 10:55:26 -0700 Subject: [PATCH] Use file module instead of shell to remove roles Replace the shell command that checks for and removes existing roles that were not git clones with an equivalent when clause/file module for improved idempotence when running the bootstrap-ansible script. Change-Id: Ibfef9c91bc95e75ee8a86debf718ce78454d46c5 --- scripts/get-ansible-role-requirements.yml | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/scripts/get-ansible-role-requirements.yml b/scripts/get-ansible-role-requirements.yml index 1d2e3bda70..7be7bb03b2 100644 --- a/scripts/get-ansible-role-requirements.yml +++ b/scripts/get-ansible-role-requirements.yml @@ -19,14 +19,12 @@ user: root tasks: - name: Remove target directory if required - shell: | - if [[ ! -d "{{ item.path | default(role_path_default) }}/{{ item.name | default(item.src | basename) }}/.git" ]]; then - rm -rf "{{ item.path | default(role_path_default) }}/{{ item.name | default(item.src | basename) }}" - fi - args: - executable: /bin/bash + file: + path: "{{ item.path | default(role_path_default) }}/{{ item.name | default(item.src | basename) }}" + state: absent when: - item.scm == "git" or item.scm is undefined + - "(item.path | default(role_path_default) ~ '/' ~ item.name | default(item.src | basename) ~ '/.git') is not directory" with_items: "{{ required_roles }}" - name: Ensure the default roles directory exists