Building chain.pem, fullchain.pem and all.pem was implemented seven times across three task files with identical stat, awk and copy tasks. The blocks now include tasks/concatenate.yaml and pass the sources, the destination and the mode, which removes about a hundred lines. Two side effects come with it. Every source file is checked instead of only the foreign one, so a missing file skips the block instead of letting awk fail. And the trailing newline of the result is kept, because stdout_lines joined by a newline dropped it. Co-authored-by: Copilot <copilot@github.com>
25 lines
757 B
YAML
25 lines
757 B
YAML
---
|
|
|
|
# awk 1 prints every line and thereby normalizes source files whose last line lacks a newline.
|
|
- name: Check the source files of {{ _concat_dest }}
|
|
ansible.builtin.stat:
|
|
path: "{{ item }}"
|
|
register: _concat_stat
|
|
loop: "{{ _concat_sources }}"
|
|
|
|
- name: Read the source files of {{ _concat_dest }}
|
|
ansible.builtin.command:
|
|
cmd: "awk 1 {{ _concat_sources | join(' ') }}"
|
|
register: _concat_content
|
|
changed_when: false
|
|
when: _concat_stat.results | rejectattr('stat.exists') | list | length == 0
|
|
|
|
- name: Write {{ _concat_dest }}
|
|
ansible.builtin.copy:
|
|
content: "{{ _concat_content.stdout }}\n"
|
|
dest: "{{ _concat_dest }}"
|
|
owner: "root"
|
|
group: "root"
|
|
mode: "{{ _concat_mode }}"
|
|
when: _concat_content is not skipped
|