How to define hosts when you integrate Ansible into external system

13 views
Skip to first unread message

Sander Descamps

unread,
Jul 2, 2021, 11:39:50 AM7/2/21
to Ansible Development

Hi,

I need to integrate Ansible into our automation platform. I'm planning to create an Flask service that uses ansible-runner to run the playbooks. I'm wondering how I should implement the variable set of hosts where my playbook need to run? At the moment I see two solutions:
* Via the inventory. I can generate a custom inventory for every run and configure the 'hosts' in the playbook file as 'all'. This way of working is okay but will cause problems when I'm using things like 'delegate_to', because you can't delegate to a host which is not defined in the inventory. (I know there are workarounds but I like to do it properly.)
* Via the hosts parameter in the playbook file. I could modify the playbook before every run and set a custom value for the hosts parameter. Then I can use the same full (static) inventory for every run. This looks like a good solution but I never saw anyone using this on the internet and I'm not sure if this is the intended way of doing it?

I know both options could work, but I'm interested to know the proper way of doing it. Also if there are other ways to tackle this problem I'm interested to know how.

Kind Regards
Sander Descamps 


Brian Coca

unread,
Jul 2, 2021, 11:48:21 AM7/2/21
to Sander Descamps, Ansible Development
You also have --limit , which avoids playbook rewrites and per run
custom inventories


--
----------
Brian Coca

Bob Harold

unread,
Jul 2, 2021, 11:57:19 AM7/2/21
to Brian Coca, Sander Descamps, Ansible Development
I use:

ansible-playbook myplaybook.yml -i hosts -e host=myhost.mydomain.com

and in the playbook:

hosts: "{{ host }}"

That works well for me.  I think "all" is much too dangerous, and hardcoding a host or group is too limiting.

--
Bob Harold



--
You received this message because you are subscribed to the Google Groups "Ansible Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-deve...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-devel/CACVha7dFb_W1inZ%2ByDXYDDEzofFYTbewnh7toWfCqzd%2BLVk4vQ%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages