【发布时间】:2021-06-18 04:09:44
【问题描述】:
Ansible 专家, 我正在尝试创建一个剧本,检索 Cisco 路由器和交换机的当前配置,然后将其保存到文件中。我还需要文件名附加本地日期时间。就像事实中的 ansible_date_time 字段一样,我在路由器/交换机的gather_facts 数据中没有看到任何内容。所以我试图从我运行ansible的本地主机获取这些信息。由于它不包含在主机清单文件中,我必须添加一个本地主机。 我面临的问题是,我成功地从 ansible_facts 获取 date_time,但是这个注册值似乎不适用于文件名。我猜这是由于我的任务中的“何时”声明。不确定。
TASK [Display Ansible date_time fact and register] *******************************************************************************************
skipping: [LAB_TKYAT07EXTRT03]
skipping: [LAB_TKYAT07EXTRT04]
ok: [localhost] => {
"msg": "2021-06-18"
}
skipping: [LAB_TKYAT07SPN01]
skipping: [LAB_TKYAT07SPN02]
skipping: [LAB_TKYAT07LF01]
skipping: [LAB_TKYAT07LF02]
skipping: [LAB_TKYAT07LF03]
skipping: [LAB_TKYAT07LF04]
我的输出文件名看起来是“LAB_TKYAT07LF01{'skip_reason': u'Conditional result was False', 'skipped': True, 'changed': False}_showrunn.txt”
---
-
connection: network_cli
gather_facts: false
hosts: LAB_ALL
tasks:
-
name: gather facts from apps
setup:
gather_subset:
- hardware
when: ansible_connection == 'local'
tags: linux
-
name: "Display Ansible date_time fact and register"
debug:
msg: "{{ ansible_date_time.date }}"
when: ansible_connection == 'local'
register: currenttime
tags: linux
-
name: "retrieve show runn all from Nexus "
nxos_command:
commands:
- command: show runn all
register: nexus_output
when: ansible_network_os == 'nxos'
-
name: "Save Nexus output to outputs folder"
copy:
content: "{{ nexus_output.stdout[0] }}"
dest: "./outputs/{{ inventory_hostname }}{{ currenttime }}_showrunn.txt"
when: ansible_network_os == 'nxos'
-
name: "retrieve show runn all from Routers "
ios_command:
commands:
- command: show runn all
register: ios_output
when: ansible_network_os == 'ios'
-
name: "Save IOS output to outputs folder"
copy:
content: "{{ ios_output.stdout[0] }}"
dest: "./outputs/{{ inventory_hostname }}{{ currenttime }}_showrunn.txt"
when: ansible_network_os == 'ios'
【问题讨论】:
标签: ios ansible nexus ansible-facts