From 4381ca79aa77f75ff36667afd2596d39e181260b Mon Sep 17 00:00:00 2001 From: "Simon N." Date: Sat, 15 Feb 2025 00:25:43 +0100 Subject: [PATCH] feat(provisoning-templates): Add role for provisioning templates in foreman (#54) --- README.md | 1 + roles/provisioning_templates/README.md | 65 +++++++++++++++++++++ roles/provisioning_templates/meta/main.yml | 18 ++++++ roles/provisioning_templates/tasks/main.yml | 19 ++++++ 4 files changed, 103 insertions(+) create mode 100644 roles/provisioning_templates/README.md create mode 100644 roles/provisioning_templates/meta/main.yml create mode 100644 roles/provisioning_templates/tasks/main.yml diff --git a/README.md b/README.md index 5321ca3..ad7d0f2 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ Contains foreman roles and playbooks. * [`hosts`](https://github.com/radiorabe/ansible-collection-foreman/tree/main/roles/hosts) * [`installation_mediums`](https://github.com/radiorabe/ansible-collection-foreman/tree/main/roles/installation_mediums) * [`job_templates`](https://github.com/radiorabe/ansible-collection-foreman/tree/main/roles/job_templates) +* [`provisioning_templates`](https://github.com/radiorabe/ansible-collection-foreman/tree/main/roles/provisioning_templates) * [`locations`](https://github.com/radiorabe/ansible-collection-foreman/tree/main/roles/locations) * [`realms`](https://github.com/radiorabe/ansible-collection-foreman/tree/main/roles/realms) * [`roles`](https://github.com/radiorabe/ansible-collection-foreman/tree/main/roles/roles) diff --git a/roles/provisioning_templates/README.md b/roles/provisioning_templates/README.md new file mode 100644 index 0000000..c0640ef --- /dev/null +++ b/roles/provisioning_templates/README.md @@ -0,0 +1,65 @@ +# Ansible Role - radiorabe.foreman.provisioning_templates + +This role creates and manages provisioning templates in Foreman. + +## Role Variables + +This role supports the [FAM Common Role Variables](https://github.com/theforeman/foreman-ansible-modules/blob/develop/README.md#common-role-variables). + +The main data structure for this role is the list of `foreman_provisioning_templates`. Each `provisioning_template` requires either of the following fields: + +- `file_name`: The path of a template file, that shall be imported. +- `template`: The content of the provisioning Template. + +The following fields are optional in the sense that the server will use default values when they are omitted: + +- `audit_comment`: Content of the audit comment field. +- `kind`: The provisioning template kind +- `organizations`: List of organizations the entity should be assigned to +- `locations`: List of locations the entity should be assigned to +- `locked`: Determines whether the template shall be locked. +- `name`: The name of the provisioning Template. If omited, will be determined from the `name` header of the template or the filename (in that order). + +## Dependencies + +The `radiorabe.foreman.provisioning_templates` role depends on modules from the [`theforeman.foreman`](https://galaxy.ansible.com/theforeman/foreman) collection. + +## Example Playbooks + +```yaml +- name: add provisioning_templates to foreman + hosts: localhost + gather_facts: false + roles: + - role: radiorabe.foreman.provisioning_templates + vars: + foreman_server_url: https://foreman.example.com + foreman_username: admin + foreman_password: changeme + foreman_provisioning_templates: + - name: A New Finish Template + kind: finish + state: present + template: | + <%# + name: Finish timetravel + kind: finish + %> + cd / + rm -rf * + locations: + - Gallifrey + organizations: + - TARDIS INC + - name: A New provisioning Template + state: present + template: | + <%# + name: A provisioning Template + %> + rm -rf <%= input("toDelete") %> +``` + +## License + +This role is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, version 3 of the License. diff --git a/roles/provisioning_templates/meta/main.yml b/roles/provisioning_templates/meta/main.yml new file mode 100644 index 0000000..7219502 --- /dev/null +++ b/roles/provisioning_templates/meta/main.yml @@ -0,0 +1,18 @@ +--- +galaxy_info: + author: RaBe IT-Reaktion + description: Creates and manages provisioning templates in Foreman. + issue_tracker_url: https://github.com/radiorabe/ansible-collection-foreman/issues + license: AGPL-3.0-only + min_ansible_version: "2.14" + platforms: + - name: EL + versions: + - all + - name: Fedora + version: + - all + galaxy_tags: + - radiorabe + - foreman +dependencies: [] diff --git a/roles/provisioning_templates/tasks/main.yml b/roles/provisioning_templates/tasks/main.yml new file mode 100644 index 0000000..8a2eb3f --- /dev/null +++ b/roles/provisioning_templates/tasks/main.yml @@ -0,0 +1,19 @@ +--- +- name: Add provisioning_templates + theforeman.foreman.provisioning_template: + server_url: "{{ foreman_server_url | default(omit) }}" + username: "{{ foreman_username | default(omit) }}" + password: "{{ foreman_password | default(omit) }}" + state: "{{ foreman_provisioning_templates_item.state | default(omit) }}" + audit_comment: "{{ foreman_provisioning_templates_item.audit_comment | default(omit) }}" + kind: "{{ foreman_provisioning_templates_item.kind | default(omit) }}" + file_name: "{{ foreman_provisioning_templates_item.file_name | default(omit) }}" + locations: "{{ foreman_provisioning_templates_item.locations | default(omit) }}" + locked: "{{ foreman_provisioning_templates_item.locked | default(omit) }}" + name: "{{ foreman_provisioning_templates_item.name | default(omit) }}" + operatingsystems: "{{ foreman_provisioning_templates_item.operatingsystems | default(omit) }}" + organizations: "{{ foreman_provisioning_templates_item.organizations | default(omit) }}" + template: "{{ foreman_provisioning_templates_item.template | default(omit) }}" + loop: "{{ foreman_provisioning_templates | default([]) }}" + loop_control: + loop_var: foreman_provisioning_templates_item