1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Ansible Automation Platform でユーザーにロール割り当てて実行を制御する

Last updated at Posted at 2025-04-05

はじめに

Ansible Automation Platform でユーザーにロールを割り当てて実行制御を確認したログです。

マニュアル: ユーザー


環境

・HW: IBM Power10 S1022
 仮想マシン:
  OS: RHEL 9.4 ppc64le (PU Desired 0.5, VP Max 1, Memory 32GB で設定)
・Ansible Automation Platform 2.5.9 (1 ノード構成)


ユーザーの作成

admin ユーザーでログインします。

ユーザーの画面に移動し、"ユーザーの作成" を押します。

1.png

ユーザー名は job_user を指定していています。
パスワードは任意に入力しています。その他は特に指定していません。"ユーザーの作成" を押します。

2.png

無事、作成されました。

3.png


事前定義のロール確認

ユーザーの下のロールに移動し、デフォルトで定義されているロールを確認します。
AAP 2.5.9 コンテナ版ではデフォルトでは 37 個のロールが定義されていました。

4.png

job に関連する ロールを抽出します。その中に JobTemplate Execute というロールがありました。

5.png


ユーザーにロールを設定

マニュアル: ユーザーへのロールの追加

上で作成した job_user の詳細ページで "ロール" に移動します。

1.png

リソースタイプの選択

2.png

Job Template を選びます。

3.png

この作業の前に作成していた 3 つの Job Template がリストされました。
create_user_group を選択します。

4.png

Select roles to apply では、 "JobTemplate Execute" を選択します。

5.png

Review 画面で確認です。

 ・リソースタイプ: Job Template
 ・Resources: create_user_group
 ・ロール: JobTemplate Execute

6.png

Finish を押し、Add roles が実行されます。

7.png

job_user へのロール設定が完了しました。

8.png

admin ユーザーをログアウトします。


稼働確認

job_user でログインしなおします。

1.png

ログイン直後、ユーザーの画面に飛びました。

2.png

左列の (ジョブ) テンプレートに移動します。
create_user_group のみしか見えていません。(admin ユーザーでは他のテンプレートも見えていました)

3.png

テンプレート create_user_group の詳細に移動し、変数が埋め込まれていることを確認し、"テンプレートの起動" を実行します。

4.png

問題なくジョブテンプレートが実行されました。

5.png



なお、他のコンテントは見ることができません。一例で、下記のインベントリー画面では何も表示されていません。
ユーザーに割り当てられたロールが特定のジョブテンプレートに対する実行権限のみであるためと考えられます。

6.png


参考 playbook と変数

JobTemplate create_user_group はRHEL でユーザー・グループを作成する playbook を実行していました。

playbook をご参考までに記載します。


create_user.yml (折りたたんでいます)
create_user.yml
---
- name: ユーザーとグループを作成
  hosts: all
  become: yes

  tasks:
  - name: グループの作成
    group:
      name: "{{ groups.group_name }}"
      gid: "{{ groups.group_id }}"
      state: present
    loop: "{{ group_list }}"
    loop_control:
       loop_var: groups

  - name: ユーザーの作成
    user:
      name: "{{ users.user_name }}"
      uid: "{{ users.user_uid }}"
      group: "{{ users.primary_group }}"
      password: "{{ 'password' | password_hash('sha512') }}"
      shell: "{{ users.shell | default('/bin/bash') }}"
    loop: "{{ user_list }}"
    loop_control:
       loop_var: users

  - name: セカンダリグループへのユーザー追加
    user:
       name: "{{ users2.user_name }}"
       groups: "{{ users2.secondary_groups | join(',') }}"
       append: yes
    loop: "{{ user_list }}"
    loop_control:
       loop_var: users2
    when: users2.secondary_groups is defined and (users2.secondary_groups|length > 0)

変数はテンプレートのGUIに設定していました。

変数 (折りたたんでいます)
group_list:
  - group_name: testgroup
    group_id: 1501
  - group_name: testgroup2
    group_id: 1502
  - group_name: testgroup3
    group_id: 1503
user_list:
  - user_name: developer1
    user_uid: 1501
    primary_group: testgroup
    secondary_groups:
      - testgroup3
    shell: /bin/bash
  - user_name: admin1
    user_uid: 1601
    primary_group: testgroup
    secondary_groups:
      - testgroup2
      - wheel
    shell: /bin/bash
  - user_name: user1
    user_uid: 1701
    primary_group: testgroup3
    shell: /bin/bash

おわりに

ユーザーでロール付与による制御の動きを確認しました。

AAP 参考設定ログ

以上です。

1
0
4

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?