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
This commit is contained in:
Jimmy McCrory 2018-10-23 10:55:26 -07:00
parent 8e94e4d322
commit 406078fddb

View File

@ -19,14 +19,12 @@
user: root user: root
tasks: tasks:
- name: Remove target directory if required - name: Remove target directory if required
shell: | file:
if [[ ! -d "{{ item.path | default(role_path_default) }}/{{ item.name | default(item.src | basename) }}/.git" ]]; then path: "{{ item.path | default(role_path_default) }}/{{ item.name | default(item.src | basename) }}"
rm -rf "{{ item.path | default(role_path_default) }}/{{ item.name | default(item.src | basename) }}" state: absent
fi
args:
executable: /bin/bash
when: when:
- item.scm == "git" or item.scm is undefined - 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 }}" with_items: "{{ required_roles }}"
- name: Ensure the default roles directory exists - name: Ensure the default roles directory exists