Forum Discussion
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".
- RicoCirrus
With Ansible, you can create an Inventory file that stores variables for use in your playbooks. As you can see in this guide, you can create this Inventory file and then specify the host group you want to run the tasks on in the playbook.
If you have any more questions, I am sure I can help.
- ml4den_387195Nimbostratus
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".
- NisargNimbostratus
Hello,
I am
l looking for a help on similar issue. Trying to manage 2 BIG IP Server and tried your method mentioned above. However I am getting an errors.
Regards,
Nisarg S
Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com