Questions on automating the provisioning setup

Hello community,

we need to automate the setup of the Foreman instance itself.
After running the Foreman installer to install Foreman itself we send some hammer CLI commands to automate the required manual steps.

Creation of Mirror:

hammer medium create --name "CentOS 7 MAOF" --os-family "Redhat" --path "http://192.<cut>.3:80/mirror/CentOS/7.4.1708"

Associate templates with existing OS:

[root@maof isolinux]# hammer os list | grep "CentOS 7.4.1708"
1  | CentOS 7.4.1708 |              | Redhat
[root@maof isolinux]# hammer template add-operatingsystem --id 34 --operatingsystem-id 1
Operating system has been associated
[root@maof isolinux]# hammer template list | grep "Kickstart default finish"
33 | Kickstart default finish             | finish
[root@maof isolinux]# hammer template add-operatingsystem --id 33 --operatingsystem-id 1
Operating system has been associated
[root@maof isolinux]# hammer template list | grep "Kickstart default iPXE"
37 | Kickstart default iPXE               | iPXE
[root@maof isolinux]# hammer template add-operatingsystem --id 37 --operatingsystem-id 1
Operating system has been associated
[root@maof isolinux]#
[root@maof isolinux]# hammer template list | grep "Kickstart default" | grep provision | grep -v Atomic
31 | Kickstart default                    | provision
[root@maof isolinux]# hammer template add-operatingsystem --id 31 --operatingsystem-id 1
Operating system has been associated

And set as default-template for the OS:

31 | Kickstart default                    | provision
[root@maof isolinux]# hammer os list | grep 'CentOS 7.4.1708'
1  | CentOS 7.4.1708 |              | Redhat
[root@maof isolinux]# hammer os set-default-template --config-template-id 31 --id 1
[Kickstart default] was set as default provision template
[root@maof isolinux]# hammer template list | grep finish | grep -v Atomic | grep 'Kickstart default'
33 | Kickstart default finish             | finish
[root@maof isolinux]# hammer os set-default-template --config-template-id 33 --id 1
[Kickstart default finish] was set as default finish template
[root@maof isolinux]# hammer template list | grep PXELinux | grep -v Atomic | grep 'Kickstart default'
34 | Kickstart default PXELinux           | PXELinux
[root@maof isolinux]# hammer os set-default-template --config-template-id 34 --id 1
[Kickstart default PXELinux] was set as default PXELinux template
[root@maof isolinux]# hammer template list | grep iPXE | grep 'Kickstart default iPXE'
37 | Kickstart default iPXE               | iPXE
[root@maof isolinux]# hammer os set-default-template --config-template-id 37 --id 1
[Kickstart default iPXE] was set as default iPXE template

After doing those steps the provisioning setup needs to be called.
We did this using the GUI, but we want to automate this process also (preferred using hammer CLI).
With doing this I have problems.

In google I found out that I need to create a domain (default already exists) and a subnet.

Thus I tried to do some reverse engineering and started the provisioning setup in the GUI and checked the subnet which was created.

[root@maof bin]# hammer subnet list
---|-----------|--------------|---------------|--------
ID | NAME      | NETWORK      | MASK          | VLAN ID
---|-----------|--------------|---------------|--------
1  | mysubnet  | 192.168.66.0 | 255.255.255.0 |
---|-----------|--------------|---------------|--------
[root@maof bin]#

I created a new subnet with my own using this command with success:

[root@maof bin]# hammer subnet create --name mysubnet2 --domain-ids 1 --boot-mode "DHCP" --network 192.168.66.0 --mask 255.255.255.0 --ipam "DHCP"
Subnet created
[root@maof bin]#

After doing this even the association to domain seems to be fine:

[root@maof bin]# hammer domain info --name hostnet
Id:          1
Name:        hostnet
Description:
DNS Id:
Subnets:
    mysubnet (192.168.66.0/24)
    mysubnet2 (192.168.66.0/24)
Parameters:

Created at:  2018/05/18 14:12:14
Updated at:  2018/05/18 14:12:14

[root@maof bin]#

Now running the installer (with DHCP):

[root@maof bin]# foreman-installer \
>   --enable-foreman-proxy \
>   --foreman-proxy-tftp=true \
>   --foreman-proxy-tftp-servername=192.168.66.3 \
>   --foreman-proxy-dhcp=true \
>   --foreman-proxy-dhcp-interface=enp0s8 \
>   --foreman-proxy-dhcp-gateway= \
>   --foreman-proxy-dhcp-nameservers="192.168.66.3" \
>   --foreman-proxy-dns=true \
>   --foreman-proxy-dns-interface=enp0s8 \
>   --foreman-proxy-dns-zone=hostnet \
>   --foreman-proxy-dns-reverse=66.168.192.in-addr.arpa \
>   --foreman-proxy-dns-forwarders=<cut> \
>   --foreman-proxy-dns-forwarders=<cut> \
>   --foreman-proxy-foreman-base-url=https://maof.hostnet \
>   --foreman-proxy-oauth-consumer-key=immbt<cut>R \
>   --foreman-proxy-oauth-consumer-secret=5pe<cut>eUS
Installing             Done                                               [100%] [........................................................................................................]
  Success!
  * Foreman is running at https://maof.hostnet
      Initial credentials are admin / a<cut>5
  * Foreman Proxy is running at https://maof.hostnet:8443
  * Puppetmaster is running at port 8140
  The full log is at /var/log/foreman-installer/foreman.log
[root@maof bin]#

But I still have a problem with the following:

[root@maof bin]# hammer subnet info --name mysubnet
Id:            1
Name:          mysubnet
Network:       192.168.66.0
Mask:          255.255.255.0
VLAN ID:
Description:

Priority:
DNS:           maof.hostnet (https://maof.hostnet:8443)
Primary DNS:   192.168.66.3
Secondary DNS:
TFTP:          maof.hostnet (https://maof.hostnet:8443)
DHCP:          maof.hostnet (https://maof.hostnet:8443)
IPAM:          DHCP
Gateway:
From:
To:
Domains:
    hostnet
Parameters:
[root@maof bin]# hammer subnet info --name mysubnet2
Id:            2
Name:          mysubnet2
Network:       192.168.66.0
Mask:          255.255.255.0
VLAN ID:
Description:

Priority:
DNS:
Primary DNS:   192.168.66.3
Secondary DNS:
TFTP:
DHCP:
IPAM:          DHCP
Gateway:
From:
To:
Domains:
    hostnet
Parameters:

[root@maof bin]#

Open questions:
#1 So how can I set/switch the DNS, TFTP and DHCP using hammer to the “correct” subnet? I cannot find any arguments in hammer syntax. Or needs this initiated from the Proxy-side?

#2 Furthermore the next step (installation media) in Foreman installation needs to be automated, so associating the OS with the installation media. I tried everything but cannot find a hammer command for exactly doing this.

Many thanks for any hints.

Foreman and Proxy versions: 1.16

BR,
8Division

#1 Does “hammer subnet update” or “hammer subnet set-parameter” help?

#2 Maybe with “hammer os update --media” ?

I just used “hammer xyz --help” to lookup the commands, so no guarantee.

1 Like

Big thanks. Works. Fine!
“hammer full-help” was the thing I was missing, here we see all options we have.

[root@maof bin]# hammer subnet create --name mysubnet6 --domain-ids 1 --boot-mode “DHCP” --network 192.168.66.0 --mask 255.255.255.0 --ipam “DHCP” --from 192.168.66.100 --to 192.168.66.254 --dhcp-id 1 --dns-id 1 --tftp-id 1
Subnet created
[root@maof bin]#

And for the existing OS I have to work with “hammer os update” command for sure, as create won’t work, also works fine:

[root@maof bin]# hammer os update --id 1 --medium-ids 9
Operating system updated
[root@maof bin]#

Seems I can now all script.

1 Like