Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ryan@ryan-VirtualBox:~/ch4$ cat loadbalancer.yml
- ---
- - name: write load balancer config file
- hosts: web
- gather_facts: True
- tasks:
- - name: Gather data for host and display
- debug: msg="For your host {{ inventory_hostname }}, the IP address is {{ ansible_enp0s3.ipv4.address }}. We'll add this to the load balancer config."
- - name: Generate config file
- template: src=lbconfig.j2 dest="~/ch4/configs/loadbalancer.cfg"
- --
- ryan@ryan-VirtualBox:~/ch4$ cat templates/lbconfig.j2
- # Load balancer config file
- name web-backend
- {% for host in groups.web %}
- server {{ host.inventory_hostname }} {{ host.ansible_enp0s3.ipv4.address }}:80
- {% endfor %}
- ryan@ryan-VirtualBox:~/ch4$ cat inventory
- testhost ansible_ssh_host=127.0.0.1 ansible_ssh_user=ryan ansible_ssh_pass=lab
- testhost2 ansible_ssh_host=127.0.0.1 ansible_ssh_user=ryan ansible_ssh_pass=lab
- testhost3 ansible_ssh_host=127.0.0.1 ansible_ssh_user=ryan ansible_ssh_pass=lab
- [web]
- testhost
- testhost2
- testhost3
- ERROR:
- ansible-playbook loadbalancer.yml -i inventory
- PLAY [write load balancer config file] *********************************************************************************************************************************************************************
- TASK [Gathering Facts] *************************************************************************************************************************************************************************************
- ok: [testhost]
- ok: [testhost3]
- ok: [testhost2]
- TASK [Gather data for host and display] ********************************************************************************************************************************************************************
- ok: [testhost] => {
- "msg": "For your host testhost, the IP address is 10.0.2.15. We'll add this to the load balancer config."
- }
- ok: [testhost2] => {
- "msg": "For your host testhost2, the IP address is 10.0.2.15. We'll add this to the load balancer config."
- }
- ok: [testhost3] => {
- "msg": "For your host testhost3, the IP address is 10.0.2.15. We'll add this to the load balancer config."
- }
- TASK [Generate config file] ********************************************************************************************************************************************************************************
- fatal: [testhost3]: FAILED! => {"changed": false, "failed": true, "msg": "AnsibleUndefinedVariable: 'unicode object' has no attribute 'ansible_enp0s3'"}
- fatal: [testhost2]: FAILED! => {"changed": false, "failed": true, "msg": "AnsibleUndefinedVariable: 'unicode object' has no attribute 'ansible_enp0s3'"}
- fatal: [testhost]: FAILED! => {"changed": false, "failed": true, "msg": "AnsibleUndefinedVariable: 'unicode object' has no attribute 'ansible_enp0s3'"}
- to retry, use: --limit @/home/ryan/ch4/loadbalancer.retry
- PLAY RECAP *************************************************************************************************************************************************************************************************
- testhost : ok=2 changed=0 unreachable=0 failed=1
- testhost2 : ok=2 changed=0 unreachable=0 failed=1
- testhost3 : ok=2 changed=0 unreachable=0 failed=1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement