bsd 向けに ansible でユーザ作成
環境
- DragonFlyBSD v5.0.0
ansible でユーザ作成をする方法
一般的な方法
- ユーザ http://docs.ansible.com/ansible/latest/user_module.html
- グループ http://docs.ansible.com/ansible/latest/group_module.html
BSD 的な方法
コマンドの useradd , groupadd 的なものがないと動かないので動かない。
代わりに pw を使う方法を検討。user, group ともに pw でよいらしい。普通に使うと二度目の実行時などすでに存在している場合にエラーになるので存在チェックのタスクを追加する。
- pw show によって存在してるかどうかを確認
- 存在する場合は 正常終了、しない場合は異常終了。
- そのままだと必ず changed になり結果のノイズになるので changed にならないように
- pw useradd または pw groupadd で追加
下記は prometheus のユーザを作成したときの例です。
使用モジュール
- name: check prometheus system group via pw command: pw show group "{{ prometheus_group }}" register: prometheus_group_check changed_when: False - name: check prometheus system user via pw command: pw show user "{{ prometheus_user }}" register: prometheus_user_check changed_when: False - name: create prometheus system group via pw command: pw groupadd -n "{{ prometheus_group }}" when: prometheus_group_check.rc != 0 - name: create prometheus system user via pw command: pw useradd -n "{{ prometheus_user }}" -g "{{ prometheus_group }}" -s /sbin/nlogin when: prometheus_user_check.rc != 0