From ba3891b3382878cdf0c9c1c8b790ce30fe32706a Mon Sep 17 00:00:00 2001 From: James Slagle Date: Tue, 14 May 2019 14:49:25 -0400 Subject: [PATCH] Add tripleo-hieradata role The tripleo-hieradata ansible role will be used to copy hieradata files to nodes. It will be an initial replacement of the Heat SoftwareDeployment resources that use group:hiera. A followup patch will add support for configuring the hierarchy in /etc/puppet/hiera.yaml (as the Heat hook script does today). Change-Id: I28b5c2bedbba1c27da628c6bda4c7a57ca0f3ad7 implements: blueprint reduce-deployment-resources --- roles/tripleo-hieradata/README.md | 35 ++++++++++++++++++++++ roles/tripleo-hieradata/defaults/main.yaml | 3 ++ roles/tripleo-hieradata/tasks/main.yaml | 27 +++++++++++++++++ roles/tripleo-hieradata/test-playbook.yaml | 9 ++++++ 4 files changed, 74 insertions(+) create mode 100644 roles/tripleo-hieradata/README.md create mode 100644 roles/tripleo-hieradata/defaults/main.yaml create mode 100644 roles/tripleo-hieradata/tasks/main.yaml create mode 100644 roles/tripleo-hieradata/test-playbook.yaml diff --git a/roles/tripleo-hieradata/README.md b/roles/tripleo-hieradata/README.md new file mode 100644 index 000000000..26d581f48 --- /dev/null +++ b/roles/tripleo-hieradata/README.md @@ -0,0 +1,35 @@ +tripleo-hieradata +================= + +An Ansible role to hieradata files. + +Role variables +-------------- + +Required: + +* `hieradata_template` -- path to template of hieradata content +* `hieradata_variable_start_string` -- string marking the beginning of a template print statement. +* `hieradata_variable_end_string` -- string marking the end of a template print statement. + +Test playbook +------------- + +Assuming you have tripleo-inventory.yml generated, you can run the +test playbook like: + + ANSIBLE_ROLES_PATH=tripleo-common/roles \ + ANSIBLE_HOST_KEY_CHECKING=False \ + ansible-playbook \ + -i tripleo-inventory.yml \ + tripleo-common/roles/tripleo-hieradata/test-playbook.yml + +License +------- + +Free software: Apache License (2.0) + +Author Information +------------------ + +OpenStack TripleO team diff --git a/roles/tripleo-hieradata/defaults/main.yaml b/roles/tripleo-hieradata/defaults/main.yaml new file mode 100644 index 000000000..64d1cb382 --- /dev/null +++ b/roles/tripleo-hieradata/defaults/main.yaml @@ -0,0 +1,3 @@ +hieradata_template: "" +hieradata_variable_start_string: "{{" +hieradata_variable_end_string: "}}" diff --git a/roles/tripleo-hieradata/tasks/main.yaml b/roles/tripleo-hieradata/tasks/main.yaml new file mode 100644 index 000000000..b2f4ed91a --- /dev/null +++ b/roles/tripleo-hieradata/tasks/main.yaml @@ -0,0 +1,27 @@ +- name: Create /etc/puppet/hieradata + file: + path: /etc/puppet/hieradata + state: directory + mode: 0700 + +- name: Template hieradata file + when: hieradata_template != "" + delegate_to: localhost + run_once: True + become: false + template: + src: "{{ hieradata_template }}" + dest: "{{ hieradata_template ~ '.rendered' }}" + variable_start_string: "{{ hieradata_variable_start_string }}" + variable_end_string: "{{ hieradata_variable_end_string }}" + +- name: Copy hieradata files + copy: + dest: /etc/puppet/hieradata/{{ item.key }}.json + mode: 0600 + content: "{{ item.value }}" + loop: "{{ hieradata_content['datafiles'] | dict2items }}" + loop_control: + label: "{{ item.key }}" + vars: + hieradata_content: "{{ lookup('file', hieradata_template ~ '.rendered') | from_yaml }}" diff --git a/roles/tripleo-hieradata/test-playbook.yaml b/roles/tripleo-hieradata/test-playbook.yaml new file mode 100644 index 000000000..e9b14083c --- /dev/null +++ b/roles/tripleo-hieradata/test-playbook.yaml @@ -0,0 +1,9 @@ +- hosts: overcloud + tasks: + - name: test tripleo-hieradata + include_role: + name: tripleo-hieradata + vars: + hieradata_template: hieradata.j2.yaml + variable_start_string: "{{" + variable_end_string: "}}"