Skip to content

Commit

Permalink
Refactor CentOS provisioning to use theforeman.foreman modules
Browse files Browse the repository at this point in the history
This PR refactors the CentOS Stream 9 provisioning tasks by replacing
Hammer CLI commands with theforeman.foreman Ansible modules.
  • Loading branch information
archanaserver committed Sep 10, 2024
1 parent b7e2c5b commit c08b8e7
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 39 deletions.
3 changes: 3 additions & 0 deletions requirements.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
collections:
- name: https://github.com/theforeman/foreman-ansible-modules.git
type: git

- name: https://github.com/theforeman/foreman-operations-collection
type: git

Expand Down
3 changes: 3 additions & 0 deletions roles/foreman_provisioning/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ foreman_provisioning_network: 192.168.73.0
foreman_provisioning_installer_options: []
foreman_provisioning_domain: example.com
foreman_provisioning_foreman_version: "{{ foreman_repositories_version | default('nightly') }}"
foreman_provisioning_username: "admin"
foreman_provisioning_password: "changeme"
foreman_provisioning_server_url: "https://foreman.example.com"
65 changes: 26 additions & 39 deletions roles/foreman_provisioning/tasks/configure_centos_9.yml
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

View workflow job for this annotation

GitHub Actions / ansible-lint

args[module]

value of template_kind must be one of: Bootdisk, cloud-init, finish, host_init_config, iPXE, job_template, kexec, POAP, provision, PXEGrub, PXEGrub2, PXELinux, registration, script, user_data, ZTP, got: kickstart

Check warning on line 19 in roles/foreman_provisioning/tasks/configure_centos_9.yml

View workflow job for this annotation

GitHub Actions / ansible-lint

args[module]

value of template_kind must be one of: Bootdisk, cloud-init, finish, host_init_config, iPXE, job_template, kexec, POAP, provision, PXEGrub, PXEGrub2, PXELinux, registration, script, user_data, ZTP, got: kickstart
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

0 comments on commit c08b8e7

Please sign in to comment.