ansible - Can I use inventory data from a web service within a playbook? -


i run playbooks via

# ansible-playbook -i myscript.py myplaybook.yaml 

where myscript.py generates relevant host information (per documentation) , myplaybook.py starts with

--- - hosts: (...) 

this works fine.

i to

  • receive inventory via web service: include within playbook call web service , receive inventory in appropriate format, whatever (i control web service)
  • as make use of inventory directly within playbook, without -i parameter, having host: all directive understand supposed use it.

is possible in ansible? under impression inventory needed @ start of playbook (= cannot generated within playbook)

you can create inventory dynamically add_host module.
start , modify needs:

--- - hosts: localhost   tasks:     - add_host: name={{item}} group=hosts_from_webservice       with_url: https://mywebservice/host_list_as_simple_strings       # in example web service should return 1 ip/hostname line:       # 10.1.1.1       # 10.1.1.2       # 10.1.1.3      - add_host: name={{(item | from_json).host}} group=hosts_from_webservice description={{(item | from_json).desc}}       with_url: https://mywebservice/host_list_as_json_strings       # in example web service should return json object on every line:       # {"host":"10.1.1.1","desc":"hello"}       # {"host":"10.1.1.2","desc":"world"}       # {"host":"10.1.1.3","desc":"test"}  - hosts: hosts_from_webservice   tasks:     - debug: msg="i'm host webservice" 

Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -