From 7af941c5a7c6f1395796487d73e84b15ca06a07c Mon Sep 17 00:00:00 2001 From: Kyle Benson Date: Thu, 15 Feb 2018 15:29:38 -0500 Subject: [PATCH 1/3] Modified backup task to use the 'copy' module instead of 'shell' by passing the 'remote_src' option. This helps to enforce a desired state model and reduces ambiguity on success/failure. --- tasks/main.yml | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/tasks/main.yml b/tasks/main.yml index 2b1fd56..0aefeaa 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -105,14 +105,20 @@ - name: Apply changes when: __postfix_has_config_changed | d("") is search("True") block: + - name: Gather facts for ansible_date_time + setup: + filter: + - 'ansible_date_time' + when: postfix_backup_multiple | bool + - name: Backup configuration - shell: >- - set -euo pipefail; - cp /etc/postfix/main.cf - /etc/postfix/main.cf.{{ postfix_backup_multiple | - ternary("$(date -Iseconds)", "backup") }} + copy: + remote_src: true + src: /etc/postfix/main.cf + dest: /etc/postfix/main.cf.{{ postfix_backup_multiple | + ternary(ansible_date_time.iso8601, "backup") }} + mode: '0644' when: postfix_backup or postfix_backup_multiple - changed_when: true - name: Ensure Last modified header is absent lineinfile: From 757e4a5db53f0e0c07e97f49c802bb3e46a567e1 Mon Sep 17 00:00:00 2001 From: Richard Megginson Date: Tue, 11 Jun 2024 10:08:47 -0600 Subject: [PATCH 2/3] remove unnecessary quotes remove unnecessary quotes --- tasks/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasks/main.yml b/tasks/main.yml index 0aefeaa..9797eca 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -108,7 +108,7 @@ - name: Gather facts for ansible_date_time setup: filter: - - 'ansible_date_time' + - ansible_date_time when: postfix_backup_multiple | bool - name: Backup configuration From 62c73108422c1957c4fa245d8469c9c93694e2d3 Mon Sep 17 00:00:00 2001 From: Richard Megginson Date: Tue, 11 Jun 2024 10:09:07 -0600 Subject: [PATCH 3/3] use double quotes instead of single use double quotes instead of single --- tasks/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasks/main.yml b/tasks/main.yml index 9797eca..27c5130 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -117,7 +117,7 @@ src: /etc/postfix/main.cf dest: /etc/postfix/main.cf.{{ postfix_backup_multiple | ternary(ansible_date_time.iso8601, "backup") }} - mode: '0644' + mode: "0644" when: postfix_backup or postfix_backup_multiple - name: Ensure Last modified header is absent