-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor CentOS provisioning to use theforeman.foreman modules
This PR refactors the CentOS Stream 9 provisioning tasks by replacing Hammer CLI commands with theforeman.foreman Ansible modules.
- Loading branch information
1 parent
b7e2c5b
commit c08b8e7
Showing
3 changed files
with
32 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,27 @@ | ||
- name: "set CentOS medium name" | ||
set_fact: | ||
centos_medium_name: "CentOS Stream 9 mirror" | ||
- name: "Ensure CentOS Stream 9" | ||
theforeman.foreman.operatingsystem: | ||
username: "{{ foreman_provisioning_username }}" | ||
password: "{{ foreman_provisioning_password }}" | ||
server_url: "{{ foreman_provisioning_server_url }}" | ||
name: CentOS Stream | ||
family: Redhat | ||
major: 9 | ||
architectures: | ||
- x86_64 | ||
media: | ||
- CentOS Stream 9 mirror | ||
provisioning_templates: | ||
- Kickstart default | ||
ptables: | ||
- Kickstart default | ||
state: present | ||
|
||
- name: "create CentOS 9" | ||
shell: > | ||
{{ foreman_provisioning_hammer }} os info --title "CentOS 9" || | ||
{{ foreman_provisioning_hammer }} os create | ||
--name CentOS --major 9 --architectures x86_64 --family 'Redhat' --media '{{ centos_medium_name }}' --partition-tables 'Kickstart default' | ||
- name: "find CentOS 9" | ||
shell: > | ||
{{ foreman_provisioning_hammer }} --output json os info --name "CentOS 9" || | ||
{{ foreman_provisioning_hammer }} --output json os info --title "CentOS 9" | ||
register: foreman_provisioning_centos_json | ||
ignore_errors: True | ||
|
||
- name: "get CentOS 9 info" | ||
set_fact: | ||
foreman_provisioning_centos9: "{{ foreman_provisioning_centos9_json.stdout|from_json }}" | ||
|
||
- name: "find kickstart templates" | ||
shell: > | ||
{{ foreman_provisioning_hammer }} --output=json template list | ||
--search 'name ~ "Kickstart default"' | ||
register: kickstart_templates_json | ||
|
||
- name: "set kickstart templates" | ||
set_fact: | ||
kickstart_templates: "{{ kickstart_templates_json.stdout|from_json }}" | ||
|
||
- name: "associate kickstart templates to CentOS 9" | ||
shell: > | ||
{{ foreman_provisioning_hammer }} template add-operatingsystem --id {{ item.Id }} --operatingsystem 'CentOS 9' | ||
with_items: "{{ kickstart_templates }}" | ||
|
||
- name: "set default templates for CentOS 9" | ||
shell: > | ||
{{ foreman_provisioning_hammer }} os set-default-template --id {{ foreman_provisioning_centos9.Id }} --provisioning-template-id {{ item.Id }} | ||
with_items: "{{ kickstart_templates }}" | ||
- name: "Set default template for CentOS Stream 9" | ||
Check warning on line 19 in roles/foreman_provisioning/tasks/configure_centos_9.yml GitHub Actions / ansible-lintargs[module]
Check warning on line 19 in roles/foreman_provisioning/tasks/configure_centos_9.yml GitHub Actions / ansible-lintargs[module]
|
||
theforeman.foreman.os_default_template: | ||
username: "{{ foreman_provisioning_username }}" | ||
password: "{{ foreman_provisioning_password }}" | ||
server_url: "{{ foreman_provisioning_server_url }}" | ||
operatingsystem: "CentOS Stream 9" | ||
template_kind: "kickstart" | ||
provisioning_template: "Kickstart default" | ||
state: present |