ansible 2.2.0.0
config file = /etc/ansible/ansible.cfg
configured module search path = Default w/o overrides
Ubuntu 14.04
Ubuntu 16.04
int ๋ณ์๋ ์กฐ์ ์ค์ ๋ฌธ์์ด๋ก ๋ณ๊ฒฝ๋ฉ๋๋ค.
- hosts: localhost
vars:
a: 1
b: "{{ a }}"
c: "{{ a+1 }}"
tasks:
- debug: msg="{{ a + 0 }}"
- debug: msg="{{ b + 0 }}"
- debug: msg="{{ c + 0 }}"
ignore_errors: yes
- debug: msg="{{ c + '0' }}"
์ธ ๋ฒ์งธ ์์
์ int 2๋ฅผ ๋ฐํํด์ผํ๋ฉฐ ๋ค ๋ฒ์งธ ์์
์ ์คํจ ํ ๊ฐ๋ฅ์ฑ์ด ๋์ต๋๋ค.
์ธ ๋ฒ์งธ ์์
์คํจ
$ ansible-playbook a.yml -vvvvv
Using /etc/ansible/ansible.cfg as config file
[WARNING]: provided hosts list is empty, only localhost is available
Loading callback plugin default of type stdout, v2.0 from /usr/lib/python2.7/dist-packages/ansible/plugins/callback/__init__.pyc
PLAYBOOK: a.yml ****************************************************************
1 plays in a.yml
PLAY [localhost] ***************************************************************
TASK [setup] *******************************************************************
Using module file /usr/lib/python2.7/dist-packages/ansible/modules/core/system/setup.py
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: yurii
<127.0.0.1> EXEC /bin/sh -c '/usr/bin/python && sleep 0'
ok: [localhost]
TASK [debug] *******************************************************************
task path: /home/yurii/sandbox/ans/a.yml:7
ok: [localhost] => {
"msg": "1"
}
TASK [debug] *******************************************************************
task path: /home/yurii/sandbox/ans/a.yml:8
ok: [localhost] => {
"msg": "1"
}
TASK [debug] *******************************************************************
task path: /home/yurii/sandbox/ans/a.yml:9
fatal: [localhost]: FAILED! => {
"failed": true,
"msg": "Unexpected templating type error occurred on ({{ c + 0 }}): coercing to Unicode: need string or buffer, int found"
}
...ignoring
TASK [debug] *******************************************************************
task path: /home/yurii/sandbox/ans/a.yml:11
ok: [localhost] => {
"msg": "20"
}
PLAY RECAP *********************************************************************
localhost : ok=5 changed=0 unreachable=0 failed=0
์ด๊ฒ์ ์ ๋ง๋ก Jinja์ ์ฌ๋ฏธ ์ผ๋ฟ์
๋๋ค. var์ ์์ค๋ฅผ ํญ์ ์ ์๋ ์๊ธฐ ๋๋ฌธ์ (์ : ๋ช
๋ น ์ค -e
vars๋ YAML ์ ํ ์ถ๋ก ์ ๊ฑฐ์น์ง ์์ผ๋ฏ๋ก ํญ์ ๋ฌธ์์ด ์) ๋จ์ธํด์ผํฉ๋๋ค. / ์ํ์ ์ฐ์ฐ์ํ๊ธฐ ์ ์ ๊ฐ์ํ์ญ์์ค. ์ด๋ฅผ ์ํํ๋ ์ฌ๋ฐ๋ฅธ ๋ฐฉ๋ฒ์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
- debug: msg="{{ c | int + 0 }}"
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
์ด๊ฒ์ ์ ๋ง๋ก Jinja์ ์ฌ๋ฏธ ์ผ๋ฟ์ ๋๋ค. var์ ์์ค๋ฅผ ํญ์ ์ ์๋ ์๊ธฐ ๋๋ฌธ์ (์ : ๋ช ๋ น ์ค
-e
vars๋ YAML ์ ํ ์ถ๋ก ์ ๊ฑฐ์น์ง ์์ผ๋ฏ๋ก ํญ์ ๋ฌธ์์ด ์) ๋จ์ธํด์ผํฉ๋๋ค. / ์ํ์ ์ฐ์ฐ์ํ๊ธฐ ์ ์ ๊ฐ์ํ์ญ์์ค. ์ด๋ฅผ ์ํํ๋ ์ฌ๋ฐ๋ฅธ ๋ฐฉ๋ฒ์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.