首页 > 解决方案 > Making a hosts file group into an input in Ansible playbook

问题描述

I have an ansible playbook that calls an API. I have a delegate_to: localhost.

I want to run my playbook "against" every host in a group Linux.

I want the API call to do 2 things.

  1. I want it to run once for every host in the Linux group

  2. For every run, it should have a different host IP/hostname as the input

linux looks like:

[linux]
10.234.0.13
10.234.0.12

I run my like this: ansible-playbook -i linux my_playbook

How do I make the inventory group an input?

标签: ansible

解决方案


when ansible executes on the remote host it collects some meta data of the hosts. One of the meta data is ip address. The meta data is called ansible facts. There is an ansible fact to get the ip address

ansible_default_ipv4.address

推荐阅读