ansible 获取当前日期到变量
要在Ansible中获取当前日期并将其存储到变量中,可以使用set_fact模块结合ansible_date_time模块。以下是一个示例Playbook:
- name: Get current date
hosts: localhost
gather_facts: False
tasks:
- name: Get current date
set_fact:
current_date: "{{ ansible_date_time.date }}"
- name: Print current date
debug:
var: current_date
在这个示例中,首先关闭了gather_facts来避免获取远程主机的日期。然后使用set_fact模块将ansible_date_time.date的值存储到名为current_date的变量中。最后使用debug模块打印出当前日期。
原文地址: https://www.cveoy.top/t/topic/iam8 著作权归作者所有。请勿转载和采集!