Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix foreman_provisioning role #1866

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
1 change: 1 addition & 0 deletions roles/foreman_provisioning/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ 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_centos_medium_name: "CentOS Stream 9 mirror"
2 changes: 1 addition & 1 deletion roles/foreman_provisioning/tasks/configure_centos_9.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
architectures:
- x86_64
media:
- CentOS Stream 9 mirror
- "{{ foreman_provisioning_centos_medium_name }}"
provisioning_templates: "{{ result.resources | map(attribute='name') }}"
ptables:
- Kickstart default
Expand Down
30 changes: 30 additions & 0 deletions roles/foreman_provisioning/tasks/configure_debian_12_7.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
- name: "Find all relevant templates" # noqa: args[module]
theforeman.foreman.resource_info:
resource: provisioning_templates
search: name ~ "Preseed default" or name = "Linux host_init_config default"
register: result

- name: "Ensure Debian 12.7" # noqa: args[module]
theforeman.foreman.operatingsystem:
name: Debian
family: Debian
major: 12
minor: 7
release_name: bookworm
architectures:
- x86_64
media:
- Debian mirror
provisioning_templates: "{{ result.resources | map(attribute='name') }}"
ptables:
- Preseed default
state: present
password_hash: "SHA256"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like CentOS

Suggested change
password_hash: "SHA256"
password_hash: "SHA512"


- name: "Set default template for Debian 12.7" # noqa: args[module]
theforeman.foreman.os_default_template:
operatingsystem: "Debian 12.7"
template_kind: "{{ item.template_kind_name }}"
provisioning_template: "{{ item.name }}"
state: present
loop: "{{ result.resources | sort(attribute='name') | unique(attribute='template_kind_name') }}"
36 changes: 0 additions & 36 deletions roles/foreman_provisioning/tasks/configure_debian_9_3.yml

This file was deleted.

36 changes: 0 additions & 36 deletions roles/foreman_provisioning/tasks/configure_fedora_27.yml

This file was deleted.

28 changes: 28 additions & 0 deletions roles/foreman_provisioning/tasks/configure_fedora_40.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
- name: "Find all relevant templates" # noqa: args[module]
theforeman.foreman.resource_info:
resource: provisioning_templates
search: name ~ "Kickstart default" or name = "Linux host_init_config default"
register: result

- name: "Ensure Fedora 40" # noqa: args[module]
theforeman.foreman.operatingsystem:
name: Fedora
family: Redhat
major: 40
architectures:
- x86_64
media:
- Fedora mirror
provisioning_templates: "{{ result.resources | map(attribute='name') }}"
ptables:
- Kickstart default
state: present
password_hash: "SHA256"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
password_hash: "SHA256"
password_hash: "SHA512"


- name: "Set default template for Fedora 40" # noqa: args[module]
theforeman.foreman.os_default_template:
operatingsystem: "Fedora 40"
template_kind: "{{ item.template_kind_name }}"
provisioning_template: "{{ item.name }}"
state: present
loop: "{{ result.resources | sort(attribute='name') | unique(attribute='template_kind_name') }}"
36 changes: 0 additions & 36 deletions roles/foreman_provisioning/tasks/configure_ubuntu_17_10.yml

This file was deleted.

29 changes: 29 additions & 0 deletions roles/foreman_provisioning/tasks/configure_ubuntu_24_04.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
- name: "Find all relevant templates" # noqa: args[module]
theforeman.foreman.resource_info:
resource: provisioning_templates
search: name ~ "Preseed default" or name = "Linux host_init_config default"
register: result

- name: "Ensure Ubuntu 24.04" # noqa: args[module]
theforeman.foreman.operatingsystem:
name: Ubuntu
family: Debian
major: "24.04"
release_name: artful
architectures:
- x86_64
media:
- Ubuntu mirror
provisioning_templates: "{{ result.resources | map(attribute='name') }}"
ptables:
- Preseed default
state: present
password_hash: "SHA256"

- name: "Set default template for Ubuntu 24.04" # noqa: args[module]
theforeman.foreman.os_default_template:
operatingsystem: "Ubuntu 24.04"
template_kind: "{{ item.template_kind_name }}"
provisioning_template: "{{ item.name }}"
state: present
loop: "{{ result.resources | sort(attribute='name', reverse=True) | unique(attribute='template_kind_name') }}"
33 changes: 17 additions & 16 deletions roles/foreman_provisioning/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@
- name: 'Setup CentOS 9 provisioning'
import_tasks: configure_centos_9.yml

- name: 'Setup Fedora 27 provisioning'
import_tasks: configure_fedora_27.yml
- name: 'Setup Fedora 40 provisioning'
import_tasks: configure_fedora_40.yml

- name: 'Setup Debian 9.3 provisioning'
import_tasks: configure_debian_9_3.yml
- name: 'Setup Debian 12.7 provisioning'
import_tasks: configure_debian_12_7.yml

- name: 'Setup Ubuntu 17.10 provisioning'
import_tasks: configure_ubuntu_17_10.yml
- name: 'Setup Ubuntu 24.04 provisioning'
import_tasks: configure_ubuntu_24_04.yml

# TODO verify - should not be needed, DNS should work just fine
- name: 'set unattended_url'

Check warning on line 15 in roles/foreman_provisioning/tasks/main.yml

View workflow job for this annotation

GitHub Actions / ansible-lint

args[module]

missing required arguments: password, server_url, username

Check warning on line 15 in roles/foreman_provisioning/tasks/main.yml

View workflow job for this annotation

GitHub Actions / ansible-lint

args[module]

missing required arguments: password, server_url, username
shell: >
{{ foreman_provisioning_hammer }} settings set --name unattended_url --value 'http://{{ foreman_provisioning_ip_address }}'
theforeman.foreman.setting:
name: unattended_url
value: "http://{{ foreman_provisioning_ip_address }}"

- name: 'find hostgroup Base'
shell: >
Expand All @@ -37,30 +38,30 @@
--name 'Base'
--architecture x86_64
--domain {{ foreman_provisioning_domain }}
--environment production
--puppet-environment production
--puppet-ca-proxy-id {{ foreman_provisioning_smart_proxy.Id }}
--puppet-proxy-id {{ foreman_provisioning_smart_proxy.Id }}
--subnet '{{ foreman_provisioning_network }}/24'
{{ foreman_provisioning_compute_profile_option }}
{{ foreman_provisioning_compute_resource_option }}
--root-pass changeme
--root-password changeme
--pxe-loader "PXELinux BIOS"
--organization '{{ foreman_provisioning_organization }}'
{{ foreman_provisioning_hammer_taxonomy_params }}
when: foreman_provisioning_hostgroup_base.stderr.find('not found') != -1

- name: 'find hostgroup CentOS 7'
- name: 'find hostgroup CentOS 9'
shell: >
{{ foreman_provisioning_hammer }} hostgroup info --name 'CentOS 7 Mirror'
{{ foreman_provisioning_hammer }} hostgroup info --name 'CentOS 9 Mirror'
register: foreman_provisioning_hostgroup_centos_mirror
ignore_errors: True

- name: 'create hostgroup CentOS 7 Mirror'
- name: 'create hostgroup CentOS 9 Mirror'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we replace the hammer logic with FAM here too? theforeman.foreman.hostgroup should be way easier to maintain:

- name: "Ensure CentOS 9 Mirror hostgroup"
  theforeman.foreman.hostgroup:
    name: 'CentOS 9 Mirror'
    operatingsystem: 'CentOS_Stream 9'
    medium: '{{ foreman_provisioning_centos_medium_name }}'
    ptable: 'Kickstart default'
    parent: 'Base'

Not sure how to convert foreman_provisioning_hammer_taxonomy_params easily.

And the same for the Base hostgroup.

shell: >
{{ foreman_provisioning_hammer }} hostgroup create
--name 'CentOS 7 Mirror'
--operatingsystem 'CentOS 7'
--medium '{{ centos_medium_name }}'
--name 'CentOS 9 Mirror'
--operatingsystem 'CentOS_Stream 9'
--medium '{{ foreman_provisioning_centos_medium_name }}'
--partition-table 'Kickstart default'
--parent 'Base'
{{ foreman_provisioning_hammer_taxonomy_params }}
Expand Down
6 changes: 3 additions & 3 deletions roles/foreman_provisioning_infrastructure/tasks/main.yml
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In #1888 I had a go at rewriting much of this file to also use FAM. I'd appreciate if you could take a look.

Original file line number Diff line number Diff line change
Expand Up @@ -103,20 +103,20 @@
# Puppet
- name: 'find environment'
shell: >
{{ foreman_provisioning_hammer }} environment info --name "production"
{{ foreman_provisioning_hammer }} puppet-environment info --name "production"
register: foreman_provisioning_environment
ignore_errors: True

- name: 'create environment'
shell: >
{{ foreman_provisioning_hammer }} environment create
{{ foreman_provisioning_hammer }} puppet-environment create
--name production
{{ foreman_provisioning_hammer_taxonomy_params }}
when: foreman_provisioning_environment.stderr.find('not found') != -1

- name: 'update environment' # it may have been automatically created by puppet if katello reports first
shell: >
{{ foreman_provisioning_hammer }} environment update
{{ foreman_provisioning_hammer }} puppet-environment update
--name production
{{ foreman_provisioning_hammer_taxonomy_params }}

Expand Down
8 changes: 4 additions & 4 deletions roles/libvirt/tasks/tftp.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
- name: 'create the provisioning libvirt network'
virt_net:
community.libvirt.virt_net:
command: define
name: provision
xml: '{{ lookup("template", "../templates/network.xml.j2") }}'
Expand All @@ -14,7 +14,7 @@
path: /etc/libvirt/qemu/networks/autostart/provision.xml

- name: 'create the provisioning storage'
virt_pool:
community.libvirt.virt_pool:
command: define
name: provision
xml: '{{ lookup("template", "../templates/storage.xml.j2") }}'
Expand Down Expand Up @@ -58,13 +58,13 @@
shell: set -o pipefail && find /var/lib/tftpboot/ -type d | xargs chmod g+s

- name: 'start the provision libvirt network'
virt_net:
community.libvirt.virt_net:
state: active
name: provision
autostart: yes

- name: 'start the provision libvirt storage pool'
virt_pool:
community.libvirt.virt_pool:
state: active
name: provision
autostart: yes
Loading