Skip to content
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions roles/foreman_provisioning/tasks/configure_debian_12_7.yml
Copy link
Member

Choose a reason for hiding this comment

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

Would this work as a replacement for the Hammer stuff?

- name: "Ensure Debian 12" # 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:                                                              
      - Preseeed default                                                                 
    ptables:                                                                             
      - Preseed default                                                                  
    state: present                                                                       
                                                                                         
- name: "Set default template for Debian 12" # noqa: args[module]                        
  theforeman.foreman.os_default_template:                                                
    operatingsystem: "Debian 12"                                                         
    template_kind: "provision"                                                           
    provisioning_template: "Preseed default"                                             
    state: present  

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Almost, if I'm reading it correctly, the current hammer-based implementation associates all templates which start with "Preseed default" with the os. This one associates just the ones which are explicitly listed? Unless I'm missing something, fam doesn't really give us options to list with search and the reuse the result so I'd have to fallback to a mix of hammer and this to associate all the relevant templates?

Copy link
Member

Choose a reason for hiding this comment

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

I've also often wondered how we can make this better. We already know the operating systems that are compatible (since the template lists them) so should Foreman have some option to automatically associate all compatible options? And by that I mean server side, without having to specify them.

@evgeni any thoughts on this?

Copy link
Member

Choose a reason for hiding this comment

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

FAM can do searches (I can drop you an example if you want), but yeah, automatic in Foreman would be cooler

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can drop you an example if you want

If you'd indulge me

Copy link
Member

@evgeni evgeni Dec 3, 2024

Choose a reason for hiding this comment

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

Untested:

- name: "Find all preseed templates"
  theforeman.foreman.resource_info:
    resource: provisioning_templates
    search: name ~ "Preseed default"
  register: result

- name: "Set default template for Debian 12" # noqa: args[module]                        
  theforeman.foreman.os_default_template:                                                
    operatingsystem: "Debian 12"                                                         
    template_kind: "{{ item.template_kind_name }}"                                                           
    provisioning_template: "{{ item.name }}"                                             
    state: present
  loop: "{{ result.resources }}"

Copy link
Member

Choose a reason for hiding this comment

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

But now I wonder, how should an OS have multiple default templates of the same kind?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, not of the same kind. The search should return several templates of different kinds. It would be nice to not have to do this https://github.com/theforeman/forklift/pull/1885/files

Copy link
Member

Choose a reason for hiding this comment

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

Right! Updated the snippet above to do that, can you try it?

Copy link
Member

Choose a reason for hiding this comment

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

Mhh, but it'd still be a problem for PXE* ones, as there are two of them? 🤔

        {
            "created_at": "2024-09-04 05:14:23 UTC",
            "description": "The template to render Grub2 bootloader configuration for preseed based distributions.\nThe output is deployed on the host's subnet TFTP proxy.",
            "id": 9,
            "name": "Preseed default PXEGrub2",
            "snippet": false,
            "template_kind_id": 4,
            "template_kind_name": "PXEGrub2",
            "updated_at": "2024-09-04 05:14:23 UTC"
        },
        {
            "created_at": "2024-09-04 05:14:23 UTC",
            "description": null,
            "id": 10,
            "name": "Preseed default PXEGrub2 Autoinstall",
            "snippet": false,
            "template_kind_id": 4,
            "template_kind_name": "PXEGrub2",
            "updated_at": "2024-09-04 05:14:23 UTC"
        },
        {
            "created_at": "2024-09-04 05:14:23 UTC",
            "description": "The template to render PXELinux bootloader configuration for preseed based distributions.\nThe output is deployed on the host's subnet TFTP proxy.",
            "id": 19,
            "name": "Preseed default PXELinux",
            "snippet": false,
            "template_kind_id": 2,
            "template_kind_name": "PXELinux",
            "updated_at": "2024-09-04 05:14:23 UTC"
        },
        {
            "created_at": "2024-09-04 05:14:23 UTC",
            "description": null,
            "id": 20,
            "name": "Preseed default PXELinux Autoinstall",
            "snippet": false,
            "template_kind_id": 2,
            "template_kind_name": "PXELinux",
            "updated_at": "2024-09-04 05:14:23 UTC"
        },

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') | unique(attribute='template_kind_name') }}"
Copy link
Member

Choose a reason for hiding this comment

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

I think Ubuntu 24 needs the "Autoinstall" type templates, not the classic ones.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is regular debian fine with the non-autoinstall ones?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, it's just ubuntu who switched to the new installer.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, let's just hope there won't be any other flavor of the preseed templates.

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'
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 'CentOS Stream 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.

In theforeman/foreman#10227 I'd like to rename this again to the generic CentOS mirror so I think the variable still makes sense.

--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