How to write cobbler.ini for multiple cobbler servers

44 views
Skip to first unread message

Joanna Delaporte

unread,
Nov 2, 2017, 4:55:34 PM11/2/17
to Ansible Project
I want to set up multiple cobbler servers' hosts in my cobbler.ini to use their inventory...how do I do that?

Soniya panwar

unread,
Nov 7, 2017, 2:29:46 AM11/7/17
to Ansible Project
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]
cache_path = /tmp
cache_max_age = 900 

[cobbler2]
cache_path = /tmp
cache_max_age = 900 

[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:

1. 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"

                                }

                   }

     }

}

2. 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


3. Execute required playbook on hosts returned in step 2 using the JSON output as the inventory file.


Thanks
Soniya
Reply all
Reply to author
Forward
0 new messages