我的剧本使用路由器作为执行任务的主机。我已禁用主机的事实,但我需要ansible_date_time从运行剧本的本地主机进行访问。本地主机是 Ubuntu 虚拟机。
这就是我的剧本的样子:
---
- 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: …Run Code Online (Sandbox Code Playgroud) ansible ×1