From b12cb9cf4f3b10217485a5479495d5a629dcc54e Mon Sep 17 00:00:00 2001 From: Ewoud Kohl van Wijngaarden Date: Tue, 3 Dec 2024 17:04:07 +0100 Subject: [PATCH] Rely on FAM for much of the foreman_provisioning setup --- roles/foreman_provisioning/defaults/main.yml | 1 + roles/foreman_provisioning/tasks/main.yml | 13 +- .../tasks/compute_profiles.yml | 39 +++-- .../tasks/main.yml | 158 ++++++------------ 4 files changed, 70 insertions(+), 141 deletions(-) diff --git a/roles/foreman_provisioning/defaults/main.yml b/roles/foreman_provisioning/defaults/main.yml index 88428bed8..ae8ee70d6 100644 --- a/roles/foreman_provisioning/defaults/main.yml +++ b/roles/foreman_provisioning/defaults/main.yml @@ -9,6 +9,7 @@ foreman_provisioning_ip_address: 192.168.73.1 foreman_provisioning_dhcp_start: 192.168.73.2 foreman_provisioning_dhcp_end: 192.168.73.254 foreman_provisioning_network: 192.168.73.0 +foreman_provisioning_network_cidr: 24 foreman_provisioning_installer_options: [] foreman_provisioning_domain: example.com foreman_provisioning_foreman_version: "{{ foreman_repositories_version | default('nightly') }}" diff --git a/roles/foreman_provisioning/tasks/main.yml b/roles/foreman_provisioning/tasks/main.yml index c5b07ab0f..c0804a317 100644 --- a/roles/foreman_provisioning/tasks/main.yml +++ b/roles/foreman_provisioning/tasks/main.yml @@ -22,15 +22,6 @@ register: foreman_provisioning_hostgroup_base ignore_errors: True -- name: 'prepare compute resource option' - set_fact: - foreman_provisioning_compute_resource_option: "{{ '--compute-resource libvirt' if foreman_provisioning_foreman_version == 'nightly' else '' }}" - -- name: 'prepare compute profile option' - set_fact: - foreman_provisioning_compute_profile_option: "{{ '--compute-profile libvirt-profile' if 'Error' not in foreman_provisioning_compute_profile_cmd.stderr else '' }}" - -# TODO compute-profile can't be specified by name until http://projects.theforeman.org/issues/21580/ so we hardcode 1 - name: 'create hostgroup Base' shell: > {{ foreman_provisioning_hammer }} hostgroup create @@ -41,8 +32,8 @@ --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 }} + --compute-profile libvirt-profile + --compute-resource libvirt --root-pass changeme --pxe-loader "PXELinux BIOS" --organization '{{ foreman_provisioning_organization }}' diff --git a/roles/foreman_provisioning_infrastructure/tasks/compute_profiles.yml b/roles/foreman_provisioning_infrastructure/tasks/compute_profiles.yml index 1ac18eb07..5f269cb40 100644 --- a/roles/foreman_provisioning_infrastructure/tasks/compute_profiles.yml +++ b/roles/foreman_provisioning_infrastructure/tasks/compute_profiles.yml @@ -1,22 +1,21 @@ --- -- name: 'find compute profile' - shell: > - {{ foreman_provisioning_hammer }} compute-profile info --name "libvirt-profile" - register: foreman_provisioning_compute_profile - ignore_errors: True - -- name: 'create compute profile' - shell: > - {{ foreman_provisioning_hammer }} compute-profile create - --name "libvirt-profile" - when: "'Error' in foreman_provisioning_compute_profile.stderr" - - name: 'create compute attributes' - shell: > - {{ foreman_provisioning_hammer }} compute-profile values create - --compute-profile libvirt-profile - --compute-resource libvirt - --volume pool_name=provision,capacity=15G,format_type=qcow2 - --interface type=network,network=provision,model=virtio - --compute-attributes cpus=1,memory=2400000000,start=1 - when: "'Error' in foreman_provisioning_compute_profile.stderr" + theforeman.foreman.compute_profile: + name: libvirt-profile + compute_resource: libvirt + compute_attributes: + - compute_resource: libvirt + vm_attrs: + cpus: 1 + memory: 2400000000 + start: 1 + nics_attributes: + 0: + type: network + network: provision + model: virtio + volume_attributes: + 0: + pool_name: provision + capacity: 15G + format_type: qcow2 diff --git a/roles/foreman_provisioning_infrastructure/tasks/main.yml b/roles/foreman_provisioning_infrastructure/tasks/main.yml index 5df78025b..05a98c8f6 100644 --- a/roles/foreman_provisioning_infrastructure/tasks/main.yml +++ b/roles/foreman_provisioning_infrastructure/tasks/main.yml @@ -1,126 +1,64 @@ --- # Make sure admin does not default to any taxonomy - name: 'disable default context for admin' + # TODO: how to pass org and location IDs 0 to FAM? shell: > {{ foreman_provisioning_hammer }} user update --login admin --default-organization-id 0 --default-location-id 0 -# Get the smart proxy ID of the local katello: -- name: 'get smart proxy id' - shell: > - {{ foreman_provisioning_hammer }} --output json proxy info --name {{ foreman_provisioning_proxy_name }} - register: foreman_provisioning_smart_proxy_json - -- name: 'set smart proxy id' - set_fact: - foreman_provisioning_smart_proxy: "{{ foreman_provisioning_smart_proxy_json.stdout|from_json }}" - -- name: 'refresh features' - shell: > - {{ foreman_provisioning_hammer }} proxy refresh-features --id {{ foreman_provisioning_smart_proxy.Id }} - -- name: 'prepare hammer taxonomy options' - set_fact: - foreman_provisioning_hammer_taxonomy_params: "--organizations '{{ foreman_provisioning_organization }}' --locations '{{ foreman_provisioning_location }}'" - - name: 'Set taxonomies for proxy' - shell: > - {{ foreman_provisioning_hammer }} proxy update --id {{ foreman_provisioning_smart_proxy.Id }} {{ foreman_provisioning_hammer_taxonomy_params }} - -# Compute Resource -- name: 'find compute resource' - shell: > - {{ foreman_provisioning_hammer }} compute-resource info --name "libvirt" - register: foreman_provisioning_compute_resource - ignore_errors: True + theforeman.foreman.smart_proxy: + name: "{{ foreman_provisioning_proxy_name }}" + organizations: + - "{{ foreman_provisioning_organization }}" + locations: + - "{{ foreman_provisioning_location }}" - name: 'create compute resource' - shell: > - {{ foreman_provisioning_hammer }} compute-resource create - --name "libvirt" - --url "qemu:///system" - --provider libvirt - --set-console-password false - {{ foreman_provisioning_hammer_taxonomy_params }} - when: foreman_provisioning_compute_resource.stderr.find('not found') != -1 - -- name: 'Find out if compute profile command is available' - shell: > - {{ foreman_provisioning_hammer }} compute-profile - register: foreman_provisioning_compute_profile_cmd - ignore_errors: True - -- include_tasks: compute_profiles.yml - when: "'Error' not in foreman_provisioning_compute_profile_cmd.stderr" - -# Domain -- name: 'find domain' - shell: > - {{ foreman_provisioning_hammer }} domain info --name "{{ foreman_provisioning_domain }}" - register: foreman_provisioning_domain_task - ignore_errors: True + theforeman.foreman.compute_resource: + name: "libvirt" + url: "qemu:///system" + provider: libvirt + set_console_password: false - name: 'create domain' - shell: > - {{ foreman_provisioning_hammer }} domain create - --name {{ foreman_provisioning_domain }} - --dns-id {{ foreman_provisioning_smart_proxy.Id }} - {{ foreman_provisioning_hammer_taxonomy_params }} - when: foreman_provisioning_domain_task.stderr.find('not found') != -1 - -- name: 'update domain' - shell: > - {{ foreman_provisioning_hammer }} domain update - --name {{ foreman_provisioning_domain }} - --dns-id {{ foreman_provisioning_smart_proxy.Id }} - {{ foreman_provisioning_hammer_taxonomy_params }} - when: "'Error' not in foreman_provisioning_domain_task.stderr" - -# Subnet -- name: 'find subnet' - shell: > - {{ foreman_provisioning_hammer }} subnet info --name "{{ foreman_provisioning_network }}/24" - register: foreman_provisioning_subnet - ignore_errors: True + theforeman.foreman.domain: + name: "{{ foreman_provisioning_domain }}" + dns_proxy: "{{ foreman_provisioning_proxy_name }}" + organizations: + - "{{ foreman_provisioning_organization }}" + locations: + - "{{ foreman_provisioning_location }}" - name: 'create subnet' - shell: > - {{ foreman_provisioning_hammer }} subnet create - --name "{{ foreman_provisioning_network }}/24" - --dhcp-id {{ foreman_provisioning_smart_proxy.Id }} - --dns-id {{ foreman_provisioning_smart_proxy.Id }} - --tftp-id {{ foreman_provisioning_smart_proxy.Id }} - --domains {{ foreman_provisioning_domain }} - --from {{ foreman_provisioning_dhcp_start }} - --to {{ foreman_provisioning_dhcp_end }} - --network {{ foreman_provisioning_network }} - --mask 255.255.255.0 - --ipam DHCP - --gateway {{ foreman_provisioning_ip_address }} - --dns-primary {{ foreman_provisioning_ip_address }} - {{ foreman_provisioning_hammer_taxonomy_params }} - when: foreman_provisioning_subnet.stderr.find('not found') != -1 - -# Puppet -- name: 'find environment' - shell: > - {{ foreman_provisioning_hammer }} environment info --name "production" - register: foreman_provisioning_environment - ignore_errors: True - -- name: 'create environment' - shell: > - {{ foreman_provisioning_hammer }} 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 - --name production - {{ foreman_provisioning_hammer_taxonomy_params }} + theforeman.foreman.subnet: + name: "{{ foreman_provisioning_network }}/{{ foreman_provisioning_network_cidr }}" + dhcp_proxy: "{{ foreman_provisioning_smart_proxy }}" + dns_proxy: "{{ foreman_provisioning_smart_proxy }}" + tftp_proxy: "{{ foreman_provisioning_smart_proxy }}" + domains: + - "{{ foreman_provisioning_domain }}" + from_ip: "{{ foreman_provisioning_dhcp_start }}" + to_ip: "{{ foreman_provisioning_dhcp_end }}" + network: "{{ foreman_provisioning_network }}" + cidr: "{{ foreman_provisioning_network_cidr }} " + ipam: DHCP + gateway: "{{ foreman_provisioning_ip_address }}" + dns_primary: "{{ foreman_provisioning_ip_address }}" + organizations: + - "{{ foreman_provisioning_organization }}" + locations: + - "{{ foreman_provisioning_location }}" + +- name: 'create Puppet environment' + theforeman.foreman.puppet_environment: + name: production + organizations: + - "{{ foreman_provisioning_organization }}" + locations: + - "{{ foreman_provisioning_location }}" # query local nameservers http://projects.theforeman.org/issues/13419 - name: 'query local nameservers' - shell: > - {{ foreman_provisioning_hammer }} settings set --name query_local_nameservers --value true + theforeman.foreman.setting: + name: query_local_nameservers + value: true