问题描述
下面是一个有趣的剧本,用于获取当前内核详细信息,重新启动服务器,然后附加新内核,但未按预期进行。它提供了与重启后相同的内核版本:
- name: Header
lineinfile:
path: /tmp/summary.csv
line: "HOST,PREVIOUS_KERNEL,UPTIME,CURRENT_KERNEL"
create: yes
delegate_to: localhost
- name: Inventory
lineinfile:
path: /tmp/summary.csv
line: "{{ ansible_fqdn }},{{ ansible_kernel }},{{ ansible_uptime_seconds }}"
delegate_to: localhost
- name: reboot
reboot:
reboot_timeout: 300
- name:
lineinfile:
path: /tmp/summary.csv
line: "{{ ansible_fqdn }},{{ ansible_uptime_seconds }},{{ ansible_kernel }}"
delegate_to: localhost
任何建议如何在包含旧内核的报告中重新启动后添加当前内核
解决方法
您正在使用的变量(例如ansible_kernel
,ansible_xxx
...)是在播放开始时默认自动收集的主机事实。如果计算机在重新引导后运行其他内核,则需要再次收集事实以进行更新。您可以将第二个csv任务放在剧本中的一个新剧本中,该剧本将默认情况下再次收集事实,也可以在重启后手动收集事实:
- name: refresh facts as the machine rebooted
setup: