Automating Foreman and Katello with Ansible

Foreman is a great tool to automate all the things around your infrastructure, but how can you automate Foreman itself?


This is a companion discussion topic for the original entry at https://theforeman.org/2019/09/automating-foreman-and-katello-with-ansible.html
2 Likes

Looks great. Are all those tasks idempotent?

Can I automate initial setup of Foreman provisioning? That’d be: domain, subnet, os, installation media, templates, association of all templates, architecture, hostgroup.

Thanks lzap!

most of the tasks are idempotent. From the examples I gave in the post, katello_sync is not – mostly because it just triggers a sync, that can’t really be idempotent and katello_content_view_version is not in the way I used it – have a look at the module docs to see what’s needed to make it idempotent.

And yes, I think we should have all of the mentioned tasks for provisioning covered.
@sthirugn is currently working on a “zero to hero” setup for katello content and I think the same for provisioning would be a good addition.

1 Like

Is there a way with this module to change the virtual interface in a VMware-provisioned VM? I can do it in hammer by passing the name of the vmware interface to use.

Can you show us the full hammer command you’re using for that? The answer is probably “yes, but not as straight forward as with hammer currently”.

  hammer  host create \
            --name "$hostname" \
            --hostgroup-id $hostgroupid \
            --operatingsystem "$operatingsystem" \
            --architecture "$arch" \
            --subnet "$subnet" \
            --ip "$ip" \
            --compute-resource-id 3 \
            --provision-method build \
            --compute-attributes "cpus=1,corespersocket=1,cluster=$VM_CLUSTER,path=$PATH,guest_id=$VmWare_guest_ID,memory_mb=2048,start=1,scsi_controller_type=ParaVirtualSCSIController" \
            --interface "primary=true,managed=true,provision=true,execution=true,compute_type=VirtualVmxnet3,type=interface,compute_network=$VM_Compute_Network,_destroy=0,virtual=0" \
            --volume "datastore="VM_StorageTier",thin=true,eager_zero=false,size_gb=20G" \
            --compute-profile-id 1 \
            --build=true \
            --ask-root-password no

And the --interface part is the important one I guess?

I think interface handling is the one thing we can’t do properly right now: https://github.com/theforeman/foreman-ansible-modules/issues/757

yes, we need to be able to pass to VMWare which network to connect to. For every VM we’re using the first NIC, however we have several networks we provision on and need to be able to kickstart on multiple networks. is there a way to alter the VM after host creation if it can’t be created on the correct vmware network?

checking back. Rereading this thread I think I have muddied the waters. What I need to be able to do with the module is change value of “compute_network” so I can assign the primary interface to whatever network we are kickstarting on. is it possible to do that with this module?

Hah, I meant to reply and forgot.

No, sadly today this is not possible.

There is an PR open for changing interfaces: https://github.com/theforeman/foreman-ansible-modules/pull/792 but we had some issues to get it working properly and didn’t yet have time to follow up.

I’m sorry.

Any news on this?
I’m starting to play with FAM but the host module is useless for me if I can’t select the network for the VM! :slight_smile:

As you found out, and also raised a PR for, we did not :slight_smile:

Yeah, I’ve asked before looking into the code :slight_smile: