4.5. Ansible Playbook を使用してユーザーが存在しない状態にする
次の手順では、Ansible Playbook を使用して特定のユーザーが IdM に存在しない状態にする方法を説明します。
前提条件
コントロールノードの場合:
- Ansible バージョン 2.13 以降を使用している。
-
ansible-freeipaパッケージをインストールしている。 - この例では、~/MyPlaybooks/ ディレクトリーに、IdM サーバーの完全修飾ドメイン名 (FQDN) を使用して Ansible インベントリーファイル を作成したことを前提としている。
-
この例では、secret.yml Ansible Vault に
ipaadmin_passwordが保存されていることを前提としています。
-
ターゲットノード (
ansible-freeipaモジュールが実行されるノード) が、IdM クライアント、サーバー、またはレプリカとして IdM ドメインに含まれている。
手順
inventory.fileなどのインベントリーファイルを作成して、そのファイルにipaserverを定義します。[ipaserver] server.idm.example.comIdM に存在させないユーザーを指定して Ansible Playbook ファイルを作成します。この手順は、
/usr/share/doc/ansible-freeipa/playbooks/user/ensure-users-present.ymlファイルのサンプルをコピーして変更し、簡素化できます。たとえば、ユーザー idm_user_1、idm_user_2、idm_user_3 を削除するには、次のコマンドを実行します。--- - name: Playbook to handle users hosts: ipaserver vars_files: - /home/user_name/MyPlaybooks/secret.yml tasks: - name: Delete users idm_user_1, idm_user_2, idm_user_3 ipauser: ipaadmin_password: "{{ ipaadmin_password }}" users: - name: idm_user_1 - name: idm_user_2 - name: idm_user_3 state: absentAnsible Playbook を実行します。Playbook ファイル、secret.yml ファイルを保護するパスワードを格納するファイル、およびインベントリーファイルを指定します。
$ ansible-playbook --vault-password-file=password_file -v -i path_to_inventory_directory/inventory.file path_to_playbooks_directory/delete-users.yml
検証
ipa user-show コマンドを使用して、ユーザーアカウントが IdM に存在しないことを確認できます。
管理者として
ipaserverにログインします。$ ssh administrator@server.idm.example.com Password: [admin@server /]$idm_user_1 に関する要求情報:
$ ipa user-show idm_user_1 ipa: ERROR: idm_user_1: user not foundidm_user_1 という名前のユーザーは IdM に存在しません。