출력은 어떻게 하나?
먼저 변수를 선언하고 결과 값을 변수에 담아야한다.
#yml파일
---
- hosts: localhost
tasks:
- name: check hostname
shell: hostname -f
register: "check_hostname"
- name: debug result
debug:
msg: "{{ check_hostname }}"
# 실행
# ansible-playbook expect.yml
PLAY [localhost] **********************************************************************************************************************************************************************
TASK [Gathering Facts] ****************************************************************************************************************************************************************
ok: [localhost]
TASK [check hostname] *****************************************************************************************************************************************************************
changed: [localhost]
TASK [debug result] *******************************************************************************************************************************************************************
ok: [localhost] => {
"msg": {
"changed": true,
"cmd": "hostname -f",
"delta": "0:00:00.009930",
"end": "2022-06-01 04:52:07.325563",
"failed": false,
"rc": 0,
"start": "2022-06-01 04:52:07.315633",
"stderr": "",
"stderr_lines": [],
"stdout": "seo-node00-centos.c.gcp-ie1.internal",
"stdout_lines": [
"seo-node00-centos.c.gcp-ie1.internal"
]
}
}
PLAY RECAP ****************************************************************************************************************************************************************************
localhost : ok=3 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
그런데 위 결과 값은 쓸데없이 많은 정보를 담고 있다.
우리가 알고 싶은 결과 값만 알고 싶을 땐 아래와 같이" {{ 변수명.stdout }}" 와같이 .stdout을 붙여준다.
#yml파일
---
- hosts: localhost
tasks:
- name: check hostname
shell: hostname -f
register: "check_hostname"
- name: debug result
debug:
msg: "{{ check_hostname.stdout}}"
## 실행
# ansible-playbook expect.yml
PLAY [localhost] **********************************************************************************************************************************************************************
TASK [Gathering Facts] ****************************************************************************************************************************************************************
ok: [localhost]
TASK [check hostname] *****************************************************************************************************************************************************************
changed: [localhost]
TASK [debug result] *******************************************************************************************************************************************************************
ok: [localhost] => {
"msg": "seo-node00-centos.c.gcp-ie1.internal"
}
PLAY RECAP ****************************************************************************************************************************************************************************
localhost : ok=3 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
반응형
'인프라 > 앤서블(Ansible)' 카테고리의 다른 글
[Ansible] Distribution Ubuntu 18.04 on host x.x.x.x should use /usr/bin/python3, but is using /usr/bin/python for backward compatibility with prior Ansible releases (0) | 2022.06.29 |
---|---|
[Ansible] AWX OpenLDAP 연동 설정 (0) | 2022.06.14 |
[ansible] 앤서블 yml 특수문자 ecaspe 처리 (0) | 2022.06.01 |
[ansible] The error was: ImportError: No module named pexpect (0) | 2022.05.31 |
Ansible awx hostname으로 찍히게 하려면 (0) | 2022.05.26 |
댓글