Advertisement
jtyr

Untitled

Apr 26th, 2017
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.03 KB | None | 0 0
  1. mkdir -p /tmp/test_inv/{tools,inventory/vars/{template,g1/g2/g3},group_vars}
  2. cd /tmp/test_inv
  3. git clone https://github.com/jtyr/ansible-yaml_inventory.git tools/yaml_inventory
  4. ln -s ./tools/yaml_inventory/yaml_inventory.py ./hosts
  5. cat > ./site.yaml <<END
  6. ---
  7.  
  8. - hosts: all
  9.   connection: local
  10.   gather_facts: no
  11.   tasks:
  12.     - debug:
  13.         msg: Host from the group {{ xxx }} are using template {{ yyy + ((' and ' + zzz) if zzz is defined else '') }}
  14. END
  15. cat > ./inventory/main.yaml <<END
  16. ---
  17.  
  18. g1:
  19.   g2:
  20.     :templates:
  21.       - template-app1
  22.     :hosts:
  23.       - g2h1
  24.     g3:
  25.       :templates:
  26.         - template-app1
  27.         - template-app2
  28.       :hosts:
  29.         - g3h1
  30. END
  31. cat > ./inventory/vars/g1/g2/all <<END
  32. ---
  33.  
  34. xxx: G2
  35. END
  36. cat > ./inventory/vars/g1/g2/g3/all <<END
  37. ---
  38.  
  39. xxx: G3
  40. END
  41. cat > ./inventory/vars/template/app1 <<END
  42. ---
  43.  
  44. yyy: APP1
  45. END
  46. cat > ./inventory/vars/template/app2 <<END
  47. ---
  48.  
  49. zzz: APP2
  50. END
  51. ansible-playbook -i hosts -l g2h1 site.yaml
  52. ansible-playbook -i hosts -l g3h1 site.yaml
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement