簡體   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