I want to set up multiple cobbler servers' hosts in my cobbler.ini to use their inventory...how do I do that?
Hello,
You can easily add multiple cobbler servers in cobbler.ini file by creating a diffenrent tag for each cobbler server. Please refer to the below example:
eg:
[cobbler1]
host = http://cobler1
cache_path = /tmp
cache_max_age = 900
[cobbler2]
host = http://cobbler2
cache_path = /tmp
cache_max_age = 900
[cobbler3]
host = http://cobbler3
cache_path = /tmp
cache_max_age = 900
This approach however has a limitation if you are dealing with a very large set of cobbler servers. Making different entries for a large set of cobbler servers could get tedious and result into a very large inventory file.
Therfore you may use the feature of External script and Dynamic Inventory to overcome this limitation.
Below are the steps involved:
- write a script that returns a JSON containing the list of cobbler servers. It has to be ensured in the script that the JSON output contains a group, meta and hostvars directory in below format for ansible to interpret
correctly.
Below is the sample JSON example:
{
“group”: {
“hosts”: [
“cobbler1”,
“cobbler2”,
“cobbler3”,
],
“vars”: {
“ansible_user”: “root”
}
},
“_meta”: {
“hostvars”: {
“cobbler1”{
“host”: “testhost1”
“cache_path”: “/tmp”
“cache_max_age”: “900”
},
“cobbler2”{
“host”: “testhost2”
“cache_path”: “/tmp”
“cache_max_age”: “900”
},
“cobbler3”{
“host”: “testhost3”
“cache_path”: “/tmp”
“cache_max_age”: “900”
}
}
}
}
- Create another script (say Jsonscript.py) that will be executed on each cobbler server returned by script in step 1. This script will generate another JSON output containing the list of cobblers hosts from each
cobbler server. You may execute this script on each cobbler server using below playbook.
Sample external script can be found at following location: https://raw.githubusercontent.com/ansible/ansible/devel/contrib/inventory/cobbler.py
eg;
$main.yml
- name: Return Cobbler Host
hosts: all
gather_facts: False
tasks:
- name: Script to return cobbler host
shell: Jsonscript.py >> JSONOutput
- Execute required playbook on hosts returned in step 2 using the JSON output as the inventory file.
Thanks
Soniya