]> Frank Brehm's Git Trees - pixelpark/pp-admin-tools.git/commitdiff
Adding Ansible playbook adjust-puppet-facts-customer.yaml
authorFrank Brehm <frank.brehm@pixelpark.com>
Thu, 5 Sep 2019 10:51:36 +0000 (12:51 +0200)
committerFrank Brehm <frank.brehm@pixelpark.com>
Thu, 5 Sep 2019 10:51:36 +0000 (12:51 +0200)
adjust-puppet-facts-customer.yaml [new file with mode: 0644]
inventory/spk-vms.yml

diff --git a/adjust-puppet-facts-customer.yaml b/adjust-puppet-facts-customer.yaml
new file mode 100644 (file)
index 0000000..d323c34
--- /dev/null
@@ -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
+
index a7e873e77cdb56e64eafd37b962d8109ee900f5b..eeade27357d1d4dc0cede3b6dd5078a46c4d7b30 100644 (file)
@@ -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'
+