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: "}}"