Advertisement
Guest User

Untitled

a guest
Oct 28th, 2016
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.41 KB | None | 0 0
  1. [root@websrv01 ansible]# cat hosts
  2.  
  3. [app]
  4. localhost
  5.  
  6. [app_bla]
  7. localhost
  8. [root@websrv01 ansible]# cat version
  9. app:
  10. - name: bla
  11. version: 1
  12.  
  13. app_bla:
  14. - name: blub
  15. version: 1
  16. [root@websrv01 ansible]# cat play.yml
  17. - hosts: app:app_bla
  18. remote_user: root
  19. pre_tasks:
  20. - include_vars: version
  21. tasks:
  22. - debug: var="{{item}}"
  23. with_items: group_names
  24. - debug: msg="going to install {{ hostvars[inventory_hostname][item]}} on {{inventory_hostname}}"
  25. with_items: group_names
  26. when: hostvars[inventory_hostname][item] is defined
  27. [root@websrv01 ansible]# ansible-playbook play.yml
  28.  
  29. PLAY [app:app_bla] *************************************************************
  30.  
  31. TASK [setup] *******************************************************************
  32. ok: [localhost]
  33.  
  34. TASK [include_vars] ************************************************************
  35. ok: [localhost]
  36.  
  37. TASK [debug] *******************************************************************
  38. [DEPRECATION WARNING]: Using bare variables is deprecated. Update your playbooks so that the environment value uses the full variable syntax
  39. ('{{group_names}}').
  40. This feature will be removed in a future release. Deprecation warnings can be disabled by setting deprecation_warnings=False in
  41. ansible.cfg.
  42. ok: [localhost] => (item=app) => {
  43. "app": [
  44. {
  45. "name": "bla",
  46. "version": 1
  47. }
  48. ],
  49. "item": "app"
  50. }
  51. ok: [localhost] => (item=app_bla) => {
  52. "app_bla": [
  53. {
  54. "name": "blub",
  55. "version": 1
  56. }
  57. ],
  58. "item": "app_bla"
  59. }
  60.  
  61. TASK [debug] *******************************************************************
  62. [DEPRECATION WARNING]: Using bare variables is deprecated. Update your playbooks so that the environment value uses the full variable syntax
  63. ('{{group_names}}').
  64. This feature will be removed in a future release. Deprecation warnings can be disabled by setting deprecation_warnings=False in
  65. ansible.cfg.
  66. ok: [localhost] => (item=app) => {
  67. "item": "app",
  68. "msg": "going to install [{u'version': 1, u'name': u'bla'}] on localhost"
  69. }
  70. ok: [localhost] => (item=app_bla) => {
  71. "item": "app_bla",
  72. "msg": "going to install [{u'version': 1, u'name': u'blub'}] on localhost"
  73. }
  74.  
  75. PLAY RECAP *********************************************************************
  76. localhost : ok=4 changed=0 unreachable=0 failed=0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement