7.3.2. 配置Ansible inventory文件以使用 hook

您可以在 hosts inventory 文件的all:vars 部分中定义 Red Hat Enterprise Linux(RHEL)compute 机器(也称为 worker 机器)更新时使用的 hook 。

先决条件

  • 您可以访问用于添加RHEL compute 系统集群的计算机。您必须有访问定义RHEL系统的hosts Ansible 清单文件的权限。

流程

  1. 在设计了 hook 后,创建一个YAML文件,为其定义Ansible任务。此文件必须是一组任务,不能是一个 playbook,如以下示例所示:

    ---
    # Trivial example forcing an operator to acknowledge the start of an upgrade
    # file=/home/user/openshift-ansible/hooks/pre_compute.yml
    
    - name: note the start of a compute machine update
      debug:
          msg: "Compute machine upgrade of {{ inventory_hostname }} is about to start"
    
    - name: require the user agree to start an upgrade
      pause:
          prompt: "Press Enter to start the compute machine update"
  2. 修改 hosts Ansible inventory 文件来指定 hook 文件。hook 文件作为参数值在 [all:vars] 部分指定。如下所示:

    清单文件中的 hook 定义示例

    [all:vars]
    openshift_node_pre_upgrade_hook=/home/user/openshift-ansible/hooks/pre_node.yml
    openshift_node_post_upgrade_hook=/home/user/openshift-ansible/hooks/post_node.yml

    为了避免歧义,请在其定义中使用 hook 文件的绝对路径而不要使用相对路径。