Advertisement
Guest User

unicode error

a guest
Jul 29th, 2017
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.26 KB | None | 0 0
  1. ryan@ryan-VirtualBox:~/ch4$ cat loadbalancer.yml
  2. ---
  3. - name: write load balancer config file
  4. hosts: web
  5. gather_facts: True
  6.  
  7. tasks:
  8.  
  9. - name: Gather data for host and display
  10. debug: msg="For your host {{ inventory_hostname }}, the IP address is {{ ansible_enp0s3.ipv4.address }}. We'll add this to the load balancer config."
  11.  
  12. - name: Generate config file
  13. template: src=lbconfig.j2 dest="~/ch4/configs/loadbalancer.cfg"
  14.  
  15. --
  16.  
  17.  
  18. ryan@ryan-VirtualBox:~/ch4$ cat templates/lbconfig.j2
  19. # Load balancer config file
  20. name web-backend
  21. {% for host in groups.web %}
  22. server {{ host.inventory_hostname }} {{ host.ansible_enp0s3.ipv4.address }}:80
  23. {% endfor %}
  24.  
  25. ryan@ryan-VirtualBox:~/ch4$ cat inventory
  26. testhost ansible_ssh_host=127.0.0.1 ansible_ssh_user=ryan ansible_ssh_pass=lab
  27. testhost2 ansible_ssh_host=127.0.0.1 ansible_ssh_user=ryan ansible_ssh_pass=lab
  28. testhost3 ansible_ssh_host=127.0.0.1 ansible_ssh_user=ryan ansible_ssh_pass=lab
  29.  
  30. [web]
  31. testhost
  32. testhost2
  33. testhost3
  34.  
  35.  
  36. ERROR:
  37.  
  38. ansible-playbook loadbalancer.yml -i inventory
  39.  
  40. PLAY [write load balancer config file] *********************************************************************************************************************************************************************
  41.  
  42. TASK [Gathering Facts] *************************************************************************************************************************************************************************************
  43. ok: [testhost]
  44. ok: [testhost3]
  45. ok: [testhost2]
  46.  
  47. TASK [Gather data for host and display] ********************************************************************************************************************************************************************
  48. ok: [testhost] => {
  49. "msg": "For your host testhost, the IP address is 10.0.2.15. We'll add this to the load balancer config."
  50. }
  51. ok: [testhost2] => {
  52. "msg": "For your host testhost2, the IP address is 10.0.2.15. We'll add this to the load balancer config."
  53. }
  54. ok: [testhost3] => {
  55. "msg": "For your host testhost3, the IP address is 10.0.2.15. We'll add this to the load balancer config."
  56. }
  57.  
  58. TASK [Generate config file] ********************************************************************************************************************************************************************************
  59. fatal: [testhost3]: FAILED! => {"changed": false, "failed": true, "msg": "AnsibleUndefinedVariable: 'unicode object' has no attribute 'ansible_enp0s3'"}
  60. fatal: [testhost2]: FAILED! => {"changed": false, "failed": true, "msg": "AnsibleUndefinedVariable: 'unicode object' has no attribute 'ansible_enp0s3'"}
  61. fatal: [testhost]: FAILED! => {"changed": false, "failed": true, "msg": "AnsibleUndefinedVariable: 'unicode object' has no attribute 'ansible_enp0s3'"}
  62. to retry, use: --limit @/home/ryan/ch4/loadbalancer.retry
  63.  
  64. PLAY RECAP *************************************************************************************************************************************************************************************************
  65. testhost : ok=2 changed=0 unreachable=0 failed=1
  66. testhost2 : ok=2 changed=0 unreachable=0 failed=1
  67. testhost3 : ok=2 changed=0 unreachable=0 failed=1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement