From 35301b35af4e71713edb944eb54654b587710527 Mon Sep 17 00:00:00 2001 From: Andrew Schoen Date: Wed, 8 Aug 2018 16:43:55 -0500 Subject: [PATCH] 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 --- infrastructure-playbooks/lv-create.yml | 36 +++---------------- .../templates/lv-create-log.j2 | 14 ++++++++ 2 files changed, 19 insertions(+), 31 deletions(-) create mode 100644 infrastructure-playbooks/templates/lv-create-log.j2 diff --git a/infrastructure-playbooks/lv-create.yml b/infrastructure-playbooks/lv-create.yml index 9d4ee8077..1217499fe 100644 --- a/infrastructure-playbooks/lv-create.yml +++ b/infrastructure-playbooks/lv-create.yml @@ -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 diff --git a/infrastructure-playbooks/templates/lv-create-log.j2 b/infrastructure-playbooks/templates/lv-create-log.j2 new file mode 100644 index 000000000..8b0d78feb --- /dev/null +++ b/infrastructure-playbooks/templates/lv-create-log.j2 @@ -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 %} -- 2.39.5