My playbook uses routers as the hosts to perform tasks on. I have disabled facts for the hosts but I need to get access to ansible_date_time from the local host that I'm running the playbook on. The local host is an Ubuntu VM.
This is what my playbook looks like:
---
- hosts: lab
gather_facts: no
tasks:
- name: Run block tasks
delegate_to: 127.0.0.1
block:
- name: Get cert serial number using OpenSSL
shell: |
openssl s_client -connect {{ inventory_hostname }}:50051 2>/dev/null | sed -n -e '/BEGIN\ CERTIFICATE/,/END\ CERTIFICATE/ p' |openssl x509 -noout -serial | cut -d'=' -f2 | sed -e 's/\(.*\)/\L\1/'
register: serialNum
- name: Print Serial Numbers
debug:
msg: "{{ serialNum.stdout_lines }}"
- name: Ansible fact - ansible_date_time
# gather_facts: yes
delegate_to: 127.0.0.1
debug:
var: ansible_date_time.date
I can't put gather_facts: yes in the last task since that errors out.
If I enable gather_facts: yes at the play level then I get the facts of the routers which is not what I want.
Running the playbook as above gives me the following message:
TASK [Ansible fact - ansible_date_time] ***************************************************************************************************************************************************
ok: [router1.mgt.net] => {
"ansible_date_time.date": "VARIABLE IS NOT DEFINED!"
}
Is this possible to do with Ansible?