Skip to content

Commit

Permalink
Rely on FAM for much of the foreman_provisioning setup
Browse files Browse the repository at this point in the history
  • Loading branch information
ekohl committed Dec 3, 2024
1 parent 4f7e13e commit b12cb9c
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 141 deletions.
1 change: 1 addition & 0 deletions roles/foreman_provisioning/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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') }}"
13 changes: 2 additions & 11 deletions roles/foreman_provisioning/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 }}'
Expand Down
Original file line number Diff line number Diff line change
@@ -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'

Check warning on line 2 in roles/foreman_provisioning_infrastructure/tasks/compute_profiles.yml

View workflow job for this annotation

GitHub Actions / ansible-lint

args[module]

missing required arguments: password, server_url, username
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
158 changes: 48 additions & 110 deletions roles/foreman_provisioning_infrastructure/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -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'

Check warning on line 8 in roles/foreman_provisioning_infrastructure/tasks/main.yml

View workflow job for this annotation

GitHub Actions / ansible-lint

args[module]

missing required arguments: password, server_url, url, username
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'

Check warning on line 16 in roles/foreman_provisioning_infrastructure/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 }} 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'

Check warning on line 23 in roles/foreman_provisioning_infrastructure/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 }} 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'

Check warning on line 32 in roles/foreman_provisioning_infrastructure/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 }} 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'

Check warning on line 52 in roles/foreman_provisioning_infrastructure/tasks/main.yml

View workflow job for this annotation

GitHub Actions / ansible-lint

args[module]

missing required arguments: password, server_url, username
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'

Check warning on line 61 in roles/foreman_provisioning_infrastructure/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 query_local_nameservers --value true
theforeman.foreman.setting:
name: query_local_nameservers
value: true

0 comments on commit b12cb9c

Please sign in to comment.