From 7f0a30f94629a8c13cb6d8eef3268a316990ee88 Mon Sep 17 00:00:00 2001 From: lkinser Date: Tue, 5 Feb 2019 14:39:35 -0500 Subject: [PATCH 1/2] Add check to ensure file exists File module will error if the specified file does not exist. Added a check with stat module to look for the file prior to attempting to make the change. --- shared/templates/template_ANSIBLE_file_permissions | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/shared/templates/template_ANSIBLE_file_permissions b/shared/templates/template_ANSIBLE_file_permissions index 50b64a898949..e177259fc14d 100644 --- a/shared/templates/template_ANSIBLE_file_permissions +++ b/shared/templates/template_ANSIBLE_file_permissions @@ -3,10 +3,18 @@ # strategy = configure # complexity = low # disruption = low +vars: + filepath: {{{ FILEPATH }}} + +- name: Ensure {{{ FILEPATH }}} exists + stat: {{{ FILEPATH }}} + register: filepresent + - name: Ensure permission {{{ FILEMODE }}} on {{{ FILEPATH }}} file: path: {{{ FILEPATH }}} mode: {{{ FILEMODE }}} + when: filepresent.stat.exists tags: @ANSIBLE_TAGS@ @ANSIBLE_ENSURE_PLATFORM@ From cf7603de31ab103b20a23d2fc17cf9218d04f35d Mon Sep 17 00:00:00 2001 From: Shawn Wells Date: Tue, 5 Feb 2019 15:06:43 -0500 Subject: [PATCH 2/2] slight adjustment to align with templates Slight modifications to align with https://github.com/ComplianceAsCode/content/blob/master/shared/templates/template_ANSIBLE_file_owner --- shared/templates/template_ANSIBLE_file_permissions | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/shared/templates/template_ANSIBLE_file_permissions b/shared/templates/template_ANSIBLE_file_permissions index e177259fc14d..57c8394d2fe8 100644 --- a/shared/templates/template_ANSIBLE_file_permissions +++ b/shared/templates/template_ANSIBLE_file_permissions @@ -3,19 +3,15 @@ # strategy = configure # complexity = low # disruption = low -vars: - filepath: {{{ FILEPATH }}} - -- name: Ensure {{{ FILEPATH }}} exists - stat: {{{ FILEPATH }}} - register: filepresent +- name: Test for existence {{{ FILEPATH }}} + stat: + path: {{{ FILEPATH }}} + register: file_exists - name: Ensure permission {{{ FILEMODE }}} on {{{ FILEPATH }}} file: path: {{{ FILEPATH }}} mode: {{{ FILEMODE }}} - when: filepresent.stat.exists + when: file_exists.stat.exists and @ANSIBLE_PLATFORM_CONDITION@ tags: @ANSIBLE_TAGS@ - @ANSIBLE_ENSURE_PLATFORM@ -