Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [root@websrv01 ansible]# cat hosts
- [app]
- localhost
- [app_bla]
- localhost
- [root@websrv01 ansible]# cat version
- app:
- - name: bla
- version: 1
- app_bla:
- - name: blub
- version: 1
- [root@websrv01 ansible]# cat play.yml
- - hosts: app:app_bla
- remote_user: root
- pre_tasks:
- - include_vars: version
- tasks:
- - debug: var="{{item}}"
- with_items: group_names
- - debug: msg="going to install {{ hostvars[inventory_hostname][item]}} on {{inventory_hostname}}"
- with_items: group_names
- when: hostvars[inventory_hostname][item] is defined
- [root@websrv01 ansible]# ansible-playbook play.yml
- PLAY [app:app_bla] *************************************************************
- TASK [setup] *******************************************************************
- ok: [localhost]
- TASK [include_vars] ************************************************************
- ok: [localhost]
- TASK [debug] *******************************************************************
- [DEPRECATION WARNING]: Using bare variables is deprecated. Update your playbooks so that the environment value uses the full variable syntax
- ('{{group_names}}').
- This feature will be removed in a future release. Deprecation warnings can be disabled by setting deprecation_warnings=False in
- ansible.cfg.
- ok: [localhost] => (item=app) => {
- "app": [
- {
- "name": "bla",
- "version": 1
- }
- ],
- "item": "app"
- }
- ok: [localhost] => (item=app_bla) => {
- "app_bla": [
- {
- "name": "blub",
- "version": 1
- }
- ],
- "item": "app_bla"
- }
- TASK [debug] *******************************************************************
- [DEPRECATION WARNING]: Using bare variables is deprecated. Update your playbooks so that the environment value uses the full variable syntax
- ('{{group_names}}').
- This feature will be removed in a future release. Deprecation warnings can be disabled by setting deprecation_warnings=False in
- ansible.cfg.
- ok: [localhost] => (item=app) => {
- "item": "app",
- "msg": "going to install [{u'version': 1, u'name': u'bla'}] on localhost"
- }
- ok: [localhost] => (item=app_bla) => {
- "item": "app_bla",
- "msg": "going to install [{u'version': 1, u'name': u'blub'}] on localhost"
- }
- PLAY RECAP *********************************************************************
- localhost : ok=4 changed=0 unreachable=0 failed=0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement