Skip to content

Commit

Permalink
feat(provisoning-templates): Add role for provisioning templates in f…
Browse files Browse the repository at this point in the history
…oreman (#54)
  • Loading branch information
smirta authored Feb 14, 2025
1 parent 8bbe3bb commit 4381ca7
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
65 changes: 65 additions & 0 deletions roles/provisioning_templates/README.md
Original file line number Diff line number Diff line change
@@ -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.
18 changes: 18 additions & 0 deletions roles/provisioning_templates/meta/main.yml
Original file line number Diff line number Diff line change
@@ -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: []
19 changes: 19 additions & 0 deletions roles/provisioning_templates/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 4381ca7

Please sign in to comment.