Red Hat Training

A Red Hat training course is available for RHEL 8

10.3. 使用 Ansible playbook 为 IdM 用户配置默认 shell

shell 是一个接受和解释命令的程序。Red Hat Enterprise Linux (RHEL) 中提供了多个 shell,如 bashshkshzshfish 等。Bash/bin/bash 是大多数 Linux 系统中常用的 shell,它通常是 RHEL 上用户帐户的默认 shell。

以下流程描述了如何使用 Ansible playbook 将 sh (替代 shell)配置为 IdM 用户的默认 shell。

先决条件

  • 您知道 IdM 管理员密码。
  • 您已配置了 Ansible 控制节点以满足以下要求:

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

流程

  1. 可选: 使用 retrieve-config.yml Ansible playbook 来识别 IdM 用户的当前 shell。详情请参阅 使用 Ansible playbook 检索 IdM 配置
  2. 创建一个清单文件,如 inventory.file,并在该文件中定义 ipaserver

    [ipaserver]
    server.idm.example.com
  3. 打开 /usr/share/doc/ansible-freeipa/playbooks/config/ensure-config-options-are-set.yml Ansible playbook 文件进行编辑:

    ---
    - name: Playbook to ensure some config options are set
      hosts: ipaserver
      vars_files:
      - /home/user_name/MyPlaybooks/secret.yml
    
      tasks:
      # Set defaultlogin and maxusername
      - ipaconfig:
          ipaadmin_password: "{{ ipaadmin_password }}"
          defaultshell: /bin/bash
          maxusername: 64
  4. 通过更改以下内容来调整文件:

    • ipaadmin_password 变量设置的 IdM 管理员密码。
    • IdM 用户的默认 shell 由 /bin/sh 中的 defaultshell 设置。
  5. 保存该文件。
  6. 运行 Ansible playbook。指定 playbook 文件、存储密码的文件保护 secret.yml 文件以及清单文件:

    $ ansible-playbook --vault-password-file=password_file -v -i path_to_inventory_directory/inventory.file /usr/share/doc/ansible-freeipa/playbooks/config/ensure-config-options-are-set.yml

验证步骤

您可以通过在 IdM 中启动一个新会话来验证默认用户 shell 是否已更改:

  1. 以 IdM 管理员身份登录到 ipaserver

    $ ssh admin@server.idm.example.com
    Password:
    [admin@server /]$
  2. 显示当前的 shell:

    [admin@server /]$ echo "$SHELL"
    /bin/sh

    登录用户正在使用 sh shell。