Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Modify backup task to use the 'copy' module instead of 'shell' #2

Merged
merged 3 commits into from
Jun 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading