ディクショナリ
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# test04.yml --- - hosts: all vars: user: name: "James" email: "james@example.com" age: 21 tasks: - name: debug debug: var: user - name: debug debug: msg: "User's name is {{ user['name'] }}" - name: debug debug: msg: "User's email is {{ user.email }}" |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
$ ansible-playbook test04.yml -i localhost, -e ansible_connection=local TASK [debug] ******************** ok: [localhost] => { "user": { "age": 21, "email": "james@example.com", "name": "James" } } TASK [debug] ****************** ok: [localhost] => { "msg": "User's name is James" } TASK [debug] ******************** ok: [localhost] => { "msg": "User's email is james@example.com" } |
リスト
1 2 3 4 5 6 7 8 9 10 11 12 |
# test05.yml --- - hosts: all vars: list_example: - "item1" - "item2" - "item3" tasks: - name: debug debug: msg: "{{ list_example[1] }}" |
1 2 3 4 5 |
$ ansible-playbook test05.yml -i localhost, -e ansible_connection=local TASK [debug] ***** ok: [localhost] => { "msg": "item2" } |
参考サイト
Ansible で扱う変数 – 赤帽エンジニアブログ
https://rheb.hatenablog.com/entry/ansible_variables
2022-04-07