How to address multiple BIG-IP servers in one Ansible task?
How to address multiple BIG-IP servers in one Ansible task?
Ansible noob here, I'm trying to automate the configuration of large numbers of pools (and other things) using Ansible.
I have a hosts file that just contains a group of two BIG-IPs:
[f5lab]
f5-1-hostname
f5-2-hostneme
I have a very simple playbook:
name: Create a pool
hosts: f5lab
connection: local
tasks:
- name: Create app1 server pool
bigip_pool:
name: app1_pl
monitors: "/Common/http"
lb_method: round-robin
password: "adminpassword"
server: f5-1-hostname
user: "adminuser"
validate_certs: no
delegate_to: localhost
This works fine, but will only create the pool on the one server. I'm trying to find out how to essentially loop through my group of hosts without having to write the same task for each one. The server argument is mandatory for the bigip_pool task, so I can't remove it and have it use the playbook hosts. What is the best procedure for this? Thanks!
Resolved: the answer is to use the "inventory_hostname" variable like this:
tasks: - name: Create app1 server pool bigip_pool: name: app1_pl monitors: "/Common/http" lb_method: round-robin password: "adminpassword" server: "{{inventory_hostname}}" user: "adminuser" validate_certs: no delegate_to: localhost
This will cause Ansible to loop through the servers in the inventory/hosts group that we pass it. In my case the group is called "f5lab".