繁体   English   中英

比较2个被管节点的Kernel版本

[英]Compare Kernel version of 2 managed nodes

我正在进行集群设置,需要比较两台机器的 kernel 版本是否相同,如果不使用“元”结束游戏,但它没有按预期运行并给出错误:

- name: Cluster setup
  hosts: cluster_nodes
  tasks:
    - name: Check kernel version of primary
      shell: uname -r
      when: inventory_hostname in groups['primary']
      register: primary

    - name: check kernel version of secondary
      shell: uname -r
      when: inventory_hostname in groups['secondary']
      register: secondary

    - meta: end_play
      when: primary.stdout != secondary.stdout

错误:

ERROR! The conditional check 'primary.stdout != secondary.stdout' failed. The error was: error while evaluating conditional (primary.stdout != secondary.stdout): 'dict object' has no attribute 'stdout'

The error appears to be in '/var/lib/awx/projects/pacemaker_RHEL_7_ST/main_2.yml': line 55, column 7, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:


    - meta: end_play
      ^ here

如果操作系统版本不是 RHEL7 并且两者都是相同的 kernel 版本,请建议如何编写一个 when 条件来停止播放。

当您需要的信息直接在收集的事实中时,为什么要触发shell

此外,您的上述逻辑是错误的:

  • cluster_nodes组 go 中的所有服务器通过不满足条件时跳过的所有任务(因此,为什么您没有在跳过的服务器上的注册中定义stdout
  • 您只是想比较 2 台服务器(每个primary组和secondary组中的一个),您的集群可以增长并包含许多服务器。 因此,您要检查 IMO 是否所有 kernel 版本都针对所有节点对齐。 如果这不是您想要的,您仍然可以从下面的示例中进行调整。

这是我将如何进行检查的方法。

- name: Cluster setup
  hosts: cluster_nodes

  vars:
    # Get all kernel versions from all nodes into a list
    # Note that this var will be undefined if facts are not gathered
    # prior to using it.
    kernels_list: "{{ groups['cluster_nodes']
      | map('extract', hostvars, 'ansible_kernel') }}"

  tasks:
   # Make sure the kernel list has a single unique value
   # (i.e. all kernel versions are identical)
   # We check only once for all servers in the play.
   - name: Make sure all kernel versions are aligned
     assert:
       that:
         - kernels_list | unique | count == 1
       fail_msg: "Node kernel versions are not aligned ({{ kernels_list | string }})"
     run_once: true

   - name: go on with install if assert was ok
     debug:
       msg: Go on.

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM