从剧本中提取以前的内核和当前内核

Extract previous kernel and current kernel from the playbook

下面是获取当前内核详细信息、重启服务器然后附加新内核的 ansible 剧本,但它没有按预期发生。它提供重启后相同的内核版本:

- 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_kernel }},{{ ansible_uptime_seconds }},{{ ansible_kernel }}"
  delegate_to: localhost

关于如何在包含先前内核的报告中重新启动后附加当前内核的任何建议

您正在使用的变量(例如 ansible_kernelansible_xxx...)是在游戏开始时默认自动收集的主机信息。如果您的机器在重新启动后 运行 是一个不同的内核,您将需要再次收集事实以更新这些信息。您可以将您的第二个 csv 任务放在您的剧本中的新剧本中,默认情况下将再次收集事实,或者您可以在重启后手动收集事实:

- name: refresh facts as the machine rebooted
  setup: