24-Jul-2020
08:27
- last edited on
04-Jun-2023
21:21
by
JimmyPackets
Hello all
I know this is basic but I'm starting off learning about Ansible and F5s. I'm following this lab guide:
https://github.com/ansible/workshops/tree/devel/exercises/ansible_f5/1.2-add-node
I have configured a basic inventory as such:
[lb]
f5 ansible_host=X.X.X.X ansible_user=admin private_ip=X.X.X.X ansible_ssh_pass=XXXXXXXX
[webservers]
host1 ansible_host=X.X.X.X
host2 ansible_host=X.X.X.X
I then have my YAML file as follows:
---
- name: BIG-IP SETUP
hosts: lb
connection: local
gather_facts: false
tasks:
- name: CREATE NODES
bigip_node:
provider:
server: X.X.X.X
user: XXXX
password: XXXXXXX
server_port: 443
validate_certs: false
host: "{{hostvars[webservers].ansible_host}}"
name: "{{hostvars[webservers].inventory_hostname}}"
loop: "{{ groups[webservers] }}"
When I try to run this playbook I get the following error:
devlin@ubuntu-v20:~/ansible/f5/lab2$ ansible-playbook -i inventory bigip-node.yaml
PLAY [BIG-IP SETUP] *****************************************************************************************************************
TASK [CREATE NODES] *****************************************************************************************************************
fatal: [f5]: FAILED! => {"msg": "'webservers' is undefined"}
PLAY RECAP **************************************************************************************************************************
f5 : ok=0 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0
What does it mean "webservers is undefined"?
Thank you?
24-Jul-2020 09:29
how about you take a look at https://clouddocs.f5.com/products/orchestration/ansible/devel/usage/playbook_tutorial.html
have a read at the instructions.. it seems, the "{"msg": "'webservers' is undefined"}" error maybe not finding the inventory..
also when you run your playbook, try adding -vvvv for more verbose output
24-Jul-2020
11:03
- last edited on
04-Jun-2023
21:21
by
JimmyPackets
Thanks ArvinF
Even if I explicitly tell the playbook which inventory file I get the same thing:
devlin@ubuntu-v20:~/ansible/f5/lab2$ ansible-playbook -i ~/ansible/f5/lab2/inventory bigip-node-3.yaml -vvv
ansible-playbook 2.9.6
config file = /etc/ansible/ansible.cfg
configured module search path = ['/home/devlin/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3/dist-packages/ansible
executable location = /usr/bin/ansible-playbook
python version = 3.8.2 (default, Jul 16 2020, 14:00:26) [GCC 9.3.0]
Using /etc/ansible/ansible.cfg as config file
host_list declined parsing /home/devlin/ansible/f5/lab2/inventory as it did not pass its verify_file() method
script declined parsing /home/devlin/ansible/f5/lab2/inventory as it did not pass its verify_file() method
auto declined parsing /home/devlin/ansible/f5/lab2/inventory as it did not pass its verify_file() method
Parsed /home/devlin/ansible/f5/lab2/inventory inventory source with ini plugin
PLAYBOOK: bigip-node-3.yaml ************************************************************************************************************************************************************************************************
1 plays in bigip-node-3.yaml
PLAY [BIG-IP SETUP] ********************************************************************************************************************************************************************************************************
META: ran handlers
TASK [CREATE NODES] ********************************************************************************************************************************************************************************************************
task path: /home/devlin/ansible/f5/lab2/bigip-node-3.yaml:9
fatal: [f5]: FAILED! => {
"msg": "The task includes an option with an undefined variable. The error was: \"hostvars['webservers']\" is undefined\n\nThe error appears to be in '/home/devlin/ansible/f5/lab2/bigip-node-3.yaml': line 9, column 5, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n - name: CREATE NODES\n ^ here\n"
}
PLAY RECAP *****************************************************************************************************************************************************************************************************************
f5 : ok=0 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0
24-Jul-2020
12:39
- last edited on
04-Jun-2023
21:21
by
JimmyPackets
Hello,
I think you must loop on "webservers" group and interact on each "item":
---
- name: BIG-IP SETUP
hosts: lb
connection: local
gather_facts: false
tasks:
- name: CREATE NODES
bigip_node:
provider:
server: X.X.X.X
user: XXXX
password: XXXXXXX
server_port: 443
validate_certs: false
host: "{{hostvars[item].ansible_host}}"
name: "{{hostvars[item].inventory_hostname}}"
loop: "{{ groups[webservers] }}"
Regards.
25-Jul-2020 01:09
Hi cjunior
You were spot on, thank you very much. Reading the various Ansible documentation and blog posts I convinced myself the hostvars must refer to an actual name in the inventory. But looking at it like this, it makes much more sense now.