Foreman as ENC for ansible using automatic ansible groups

Hello, not sure if its maintained or supported or Im reading obsolete code/docs

Im going withj that :

It runs pretty much out of the box , but Im facing a problem, reading from the github repo instructions it states :

Automatic Ansible groups
The inventory will provide a set of groups, by default prefixed by ‘foreman_’. If you want to customize this prefix, change the group_prefix option in /etc/ansible/foreman.ini. The rest of this guide will assume the default prefix of ‘foreman’

The problem here is that there are no groups created called foreman_${groupname} , so far I created 3 groups (host_groups) following the instructions via the web console :

  • myclient
  • PRO
  • webserver

Every group has the following parametres :
myclient : {client: myclient}
PRO : {environment : PRO}
webserver : {functionality : webserver}

And I have my foreman.ini with that content for group_patterns :
[ansible]
group_patterns = [“{functionality}-{environment}-{client}”,
“{functionality}-{environment}”,
“{client}”,
“{environment}”,
“{functionality}”]

The problem is that Im not sure how to implement that part :

Lets assume you have a host that is built using this nested hostgroup:

myapp / webtier / datacenter1

When I try to assign the host to he groups via the web console as hostname > edit > host > host_group only allows me to select one hostgroup (myclient PRO or webserver) but there is no option to select and make an assignment to the 3 groups

Hello,

I don’t have a full answer but at least some information that may be useful

I believe the script has been moved out of ansible core project recently again and now it lives at https://github.com/theforeman/foreman-ansible-modules/blob/master/plugins/inventory/foreman.py

Also there was a patch to improve nested host groups use that may help in your case https://github.com/ansible/ansible/pull/66980

Thanks Marek, it seems like there is lot of confusion out there because of several versions from. the script, defenitively I will take a look at what youre pointing, tha will help me a lot.

My concern however was because of the behauviour of nested host groups, I mean I want to dessign hosts as. members of several groups, for examenple the typical 3 layers, environment client and cpd.

With nested host groups I think I need to combine all of them into final host groups, let see that with an example, I have 2 hosts host1 and host2

Both of them are environment production, same cpd but different client, now I nest production inside client1 and client1 inside mycpd, and the I see that when I assign mycpd which contáis client1 and production mixing the clasificación, so Im think ing the correct approach is create full path hostgroups I mean, a host group calle client1-cpd1-prudction- and inside that I nest a hostgroup called cpd1-production,but that is weird, and is so weird and lacks any essence of elegance