lv-create: use the template module to write log file

The copy module will not expand the template and render the variables
included, so we must use template.

Creating a temp file and using it locally means that you must run the
playbook with sudo privledges, which I don't think we want to require.
This introduces a logfile_path variable that the user can use to control
where the logfile is written to, defaulting to the cwd.

Signed-off-by: Andrew Schoen <aschoen@redhat.com>
(cherry picked from commit 35301b35af)
Signed-off-by: Sébastien Han <seb@redhat.com>
pull/3033/head
Andrew Schoen 2018-08-08 16:43:55 -05:00 committed by Sébastien Han
parent 7f44244d23
commit 9af842467e
2 changed files with 19 additions and 31 deletions

View File

@ -2,23 +2,6 @@
hosts:
- osds
vars:
logfile: |
Suggested cut and paste under "lvm_volumes:" in "group_vars/osds.yml" for configuring with osd_scenario=lvm
-----------------------------------------------------------------------------------------------------------
{% for lv in nvme_device_lvs %}
- data: {{ lv.lv_name }}
data_vg: {{ nvme_vg_name }}
journal: {{ lv.journal_name }}
journal_vg: {{ nvme_vg_name }}
{% endfor %}
{% for hdd in hdd_devices %}
- data: {{ hdd_lv_prefix }}-{{ hdd.split('/')[-1] }}
data_vg: {{ hdd_vg_prefix }}-{{ hdd.split('/')[-1] }}
journal: {{ hdd_journal_prefix }}-{{ hdd.split('/')[-1] }}
journal_vg: {{ nvme_vg_name }}
{% endfor %}
tasks:
- name: include vars of lv_vars.yaml
@ -86,18 +69,9 @@
with_items:
- "{{ hdd_devices }}"
# Write ending configuration logfile
- name: create temporary logfile
tempfile:
state: file
suffix: logfile
register: temp_file
- name: print logfile details
debug: var=temp_file
- name: write output for osds.yml to logfile /tmp/ansible.*logfile
copy:
content: "{{ logfile }}"
dest: "{{ temp_file.path }}"
- name: "write output for osds.yml to {{ logfile_path }}"
become: false
template:
src: "templates/lv-create-log.j2"
dest: "{{ logfile_path }}"
delegate_to: localhost

View File

@ -0,0 +1,14 @@
Suggested cut and paste under "lvm_volumes:" in "group_vars/osds.yml" for configuring with osd_scenario=lvm
-----------------------------------------------------------------------------------------------------------
{% for lv in nvme_device_lvs %}
- data: {{ lv.lv_name }}
data_vg: {{ nvme_vg_name }}
journal: {{ lv.journal_name }}
journal_vg: {{ nvme_vg_name }}
{% endfor %}
{% for hdd in hdd_devices %}
- data: {{ hdd_lv_prefix }}-{{ hdd.split('/')[-1] }}
data_vg: {{ hdd_vg_prefix }}-{{ hdd.split('/')[-1] }}
journal: {{ hdd_journal_prefix }}-{{ hdd.split('/')[-1] }}
journal_vg: {{ nvme_vg_name }}
{% endfor %}