From 852c02d00016c6d42b20b4b11a2e11498dee3e37 Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Thu, 5 Sep 2019 12:51:36 +0200 Subject: [PATCH] Adding Ansible playbook adjust-puppet-facts-customer.yaml --- adjust-puppet-facts-customer.yaml | 48 +++++++++++++++++++++++++++++++ inventory/spk-vms.yml | 7 +++-- 2 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 adjust-puppet-facts-customer.yaml diff --git a/adjust-puppet-facts-customer.yaml b/adjust-puppet-facts-customer.yaml new file mode 100644 index 0000000..d323c34 --- /dev/null +++ b/adjust-puppet-facts-customer.yaml @@ -0,0 +1,48 @@ +--- + +- name: 'Adjust custom puppet facts for customer data.' + hosts: '{{ target }}' + + tasks: + - name: 'What is going to happen?' + debug: "var={{ item }}" + with_items: + - target + - project + - customer_yaml_file + + - name: "Get file stats of {{ customer_yaml_file }} ..." + stat: + path: "{{ customer_yaml_file }}" + ignore_errors: True + changed_when: False + register: customer_yfile_stat + + - name: "Get current configured customer in {{ customer_yaml_file }} ..." + shell: "if test -f {{ customer_yaml_file }} ; then cat {{ customer_yaml_file }} | grep '^customer:' | sed -e 's/^[^:]*:[ ]*//' -e 's/[ ]*$//'; fi" + ignore_errors: True + changed_when: False + register: cur_customer + + - name: "Get current configured project in {{ customer_yaml_file }} ..." + shell: "if test -f {{ customer_yaml_file }} ; then cat {{ customer_yaml_file }} | grep '^project:' | sed -e 's/^[^:]*:[ ]*//' -e 's/[ ]*$//'; fi" + ignore_errors: True + changed_when: False + register: cur_project + + - name: "Set project in in {{ customer_yaml_file }}, if necessary ..." + block: + + - name: "Save project {{ cur_customer.stdout }} in {{ customer_yaml_file }} ..." + shell: "echo -e \"---\ncustomer: {{ cur_customer.stdout }}\nproject: {{ cur_customer.stdout }}\" > {{ test_customer_yaml_file }}" + + when: cur_project.stdout == '' + + - name: "Set permissions of file {{ customer_yaml_file }} ..." + file: + path: "{{ customer_yaml_file }}" + owner: 'root' + group: 'root' + mode: 0644 + when: customer_yfile_stat.stat.exists == true + diff --git a/inventory/spk-vms.yml b/inventory/spk-vms.yml index a7e873e..eeade27 100644 --- a/inventory/spk-vms.yml +++ b/inventory/spk-vms.yml @@ -136,8 +136,6 @@ all: stage: 'live' live-search01-spk.spk.pixelpark.net: stage: 'live' - live-search01-spk.spk.pixelpark.net: - stage: 'live' live-search02-spk.spk.pixelpark.net: stage: 'live' live-search03-spk.spk.pixelpark.net: @@ -344,3 +342,8 @@ all: stage: 'stage' vars: project: 'spk-saas-mysql' + + vars: + customer_yaml_file: '/etc/puppetlabs/facter/facts.d/customer.yaml' + test_customer_yaml_file: '/tmp/customer.yaml' + -- 2.39.5