Ansible Documentation
user – Manage user accounts機能
ユーザーアカウントを作成/削除/変更するパラメータ
| パラメータ | 選択肢/ Default | 説明 |
|---|---|---|
| comment | - | ユーザーの説明 |
| group | - | ユーザーのプライマリグループ |
| name ※必須※ | - | 作成/削除/変更するユーザーアカウント名 |
| password | - | ユーザーのパスワード ※参考 How do I generate crypted passwords for the user module |
| remove | ・ no ・ yes | "state: absent"と併用し、ホームディレクトリを削除するかどうか指定する ・ no : 削除しない ・ yes : 削除する |
| state | ・ absent ・ present | ・ absent : ユーザーアカウントを削除する ・ present : ユーザーアカウントを作成する |
| uid | - | ユーザー番号(UID) |
パスワードのハッシュ化
パスワードはハッシュ化して /etc/shadow ファイルに記録します。しかし、 user モジュールの password パラメータはパスワードとして指定した値をハッシュ化しません。- name: ユーザーアカウント staff-kato を作成する
user:
name: staff-kato
password: passwd123
state: present
そのため上記の user モジュールを実行すると、次の警告が表示されます。
[WARNING]: The input password appears not to have been hashed. The 'password' argument must be encrypted for this module to work properly.
password パラメータを指定する場合、 password_hash 関数を使用してハッシュ化します。
- name: ユーザーアカウント staff-kato を作成する
user:
name: staff-kato
password: "{{ 'passwd123' | password_hash('sha512') }}"
state: present
例
- name: ユーザーアカウント staff-tanaka を作成する
user:
name: staff-tanaka
uid: 1001
group: staff
password: "{{ 'passwd123' | password_hash('sha512') }}"
comment: staff group
state: present
- name: ユーザーアカウント staff-tanaka のパスワードを変更する
user:
name: staff-tanaka
password: "{{ 'xyz-123' | password_hash('sha512') }}"
- name: ユーザーアカウント staff-tanaka を削除する
user:
name: staff-tanaka
state: absent