Red Hat Training

A Red Hat training course is available for RHEL 8

35.12. 使用 Ansible 确保带有特定 UID 的 ID 视图中存在 IdM 用户

如果您在一个实验室工作,其中您有自己的计算机,但您的 /home/ 目录位于服务器导出的共享驱动器中,您可以有两个用户:

  • 一个是系统范围的用户,集中存储在身份管理(IdM)中。
  • 其帐户是本地的,该帐户存储在有问题的系统中。

如果您需要完全访问您的文件,无论您是以 IdM 用户或本地用户登录,您可以通过为这两个用户提供相同的 UID 来完成此操作。

完成此流程,使用 ansible-freeipa idoverrideuser 模块:

  • 将 ID 视图应用到名为 idview_for_host01 的 host01。
  • 在 idview_for_host01 中,确保 idm_user 存在用户 ID 覆盖,其 UID20001

先决条件

  • 您已配置了 Ansible 控制节点以满足以下要求:

    • 您使用 Ansible 版本 2.14 或更高版本。
    • 您已在 Ansible 控制器上安装了 ansible-freeipa 软件包。
    • 您使用 RHEL 8.10 或更高版本。
    • 示例假定在 ~/MyPlaybooks/ 目录中,您已创建了一个具有 IdM 服务器的完全限定域名(FQDN)的 Ansible 清单文件
    • 示例假定 secret.yml Ansible 库存储了 ipaadmin_password
  • idview_for_host1 ID 视图存在。

流程

  1. 在 Ansible 控制节点上,使用以下内容创建一个 ensure-idmuser-and-local-user-have-access-to-same-files.yml playbook:

    ---
    - name: Ensure both local user and IdM user have access to same files
      hosts: ipaserver
      become: false
      gather_facts: false
    
      tasks:
      - name: Ensure idview_for_host1 is applied to host1.idm.example.com
        ipaidview:
          ipaadmin_password: "{{ ipaadmin_password }}"
          name: idview_for_host01
          host: host1.idm.example.com
      - name: Ensure idmuser is present in idview_for_host01 with the UID of 20001
        ipaidoverrideuser:
          ipaadmin_password: "{{ ipaadmin_password }}"
          idview: idview_for_host01
          anchor: idm_user
          UID: 20001
  2. 保存该文件。
  3. 运行 playbook。指定 playbook 文件、存储密码的文件保护 secret.yml 文件以及清单文件:

    $ ansible-playbook --vault-password-file=password_file -v -i inventory ensure-idmuser-and-local-user-have-access-to-same-files.yml

其它资源