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:

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


On Friday, November 3, 2017 at 2:25:34 AM UTC+5:30, Joanna Delaporte wrote:
>
> I want to set up multiple cobbler servers' hosts in my cobbler.ini to use 
> their inventory...how do I do that? 

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/3893567d-4399-4f2c-9ea6-ab1d9d798ddf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to