Ansible list variable
Let's see an example of an ansible-playbook for list variables.
# cat listvariable.yaml
---
- hosts: all
vars:
teams:
- csk
- srh
- mi
- rcb
tasks:
- name: pring list variables
debug:
msg="{{ teams[0] }}"
Then run the playbook
# ansible-playbook -i hosts listvariable.yaml
PLAY [all] **************************************************************************************************************************************************
TASK [Gathering Facts] **************************************************************************************************************************************
ok: [192.168.1.2]
TASK [pring list variables] *********************************************************************************************************************************
ok: [192.168.1.2] => {
"msg": "csk"
}
PLAY RECAP **************************************************************************************************************************************************
192.168.1.2 : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
Another example of list variable
# cat listvar.yaml
---
- hosts: all
vars:
teams:
- csk
- srh
- mi
- rcb
tasks:
- name: pring list variables
debug:
msg="{{ item }}"
with_items:
- "{{ teams }}"
# ansible-playbook -i hosts listvariable2.yaml
PLAY [all] **************************************************************************************************************************************************
TASK [Gathering Facts] **************************************************************************************************************************************
ok: [192.168.1.2]
TASK [pring list variables] *********************************************************************************************************************************
ok: [192.168.1.2] => (item=csk) => {
"msg": "csk"
}
ok: [192.168.1.2] => (item=srh) => {
"msg": "srh"
}
ok: [192.168.1.2] => (item=mi) => {
"msg": "mi"
}
ok: [192.168.1.2] => (item=rcb) => {
"msg": "rcb"
}
PLAY RECAP **************************************************************************************************************************************************
192.168.1.2 : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
Relevant Blogs:
Recent Comments
No comments
Leave a Comment
We will be happy to hear what you think about this post