Team,
Моя цель - запустить команду dig для fqdn и получить его IP-адрес.Затем по IP возвращается или не печатается сообщение.вроде как если и еще.этот подход правильный, потому что я получаю ошибку в первый раз и работает во второй раз работает.
-
name: Test connectivity to target servers
hosts: all
vars_files:
- vars.yaml
tasks:
- name: Ping test
ping:
- name: DNS test
command: "dig +short {{ target_dns_host }} a"
register: dns_result
- name: "Validate DNS server"
debug:
msg: "Could not resolve DNS server '{{ target_dns_host }}' "
when: dns_result.stdout == ""
- name: "Validate DNS server"
debug:
msg: "Resolved DNS server '{{ target_dns_host }}' '{{ dns_result.stdout }}' "
when: dns_result.stdout != ""
выход из первого запуска ниже
ansible-playbook playbook-ping-dns-test.yaml -i inventory.txt
PLAY [Test connectivity to target servers] ********************************************************************************************************************
TASK [Gathering Facts] ****************************************************************************************************************************************
ok: [target1]
TASK [Ping test] **********************************************************************************************************************************************
ok: [target1]
TASK [DNS test] ***********************************************************************************************************************************************
fatal: [target1]: FAILED! => {"changed": true, "cmd": ["dig", "+short", "www.google.com", "a"], "delta": "0:00:15.011879", "end": "2019-09-25 16:25:23.808746", "msg": "non-zero return code", "rc": 9, "start": "2019-09-25 16:25:08.796867", "stderr": "", "stderr_lines": [], "stdout": ";; connection timed out; no servers could be reached", "stdout_lines": [";; connection timed out; no servers could be reached"]}
to retry, use: --limit @/home/osboxes/ansible-validate-maglev/playbook-ping-dns-test.retry
PLAY RECAP ****************************************************************************************************************************************************
target1 : ok=2 changed=0 unreachable=0 failed=1
выход из второго запуска ниже
PLAY [Test connectivity to target servers] ********************************************************************************************************************
TASK [Gathering Facts] ****************************************************************************************************************************************
ok: [target1]
TASK [Ping test] **********************************************************************************************************************************************
ok: [target1]
TASK [DNS test] ***********************************************************************************************************************************************
changed: [target1]
TASK [Validate DNS server] ************************************************************************************************************************************
skipping: [target1]
TASK [Validate DNS server] ************************************************************************************************************************************
ok: [target1] => {
"msg": "Resolved DNS server 'www.google.com' '172.217.11.164' "
}
PLAY RECAP ****************************************************************************************************************************************************
target1 : ok=4 changed=1 unreachable=0 failed=0