LoginSignup
17
18

More than 5 years have passed since last update.

Ansibleでユーザを追加

Last updated at Posted at 2014-10-06
  • /etc/sudoers の更新をミスると sudo できなくなるので rollback の準備をしてからやる

使用するモジュール

パスワード生成

生パスワードは使えないので以下で変換する。

openssl passwd -salt hoge -1 fuga

設定ファイル

hosts
[target]
192.168.43.52
ansible.cfg
[defaults]
hostfile = ./hosts
playbook.yml
---
- hosts: all
  sudo: true
  vars:
    password: ****
  tasks:
    - name: add a new user
      user: name=kiarina password={{password}} state=present
    - name: add a sudo user
      lineinfile: "dest=/etc/sudoers backup=yes state=present regexp='^kiarina' line='kiarina ALL=(ALL) NOPASSWD: ALL'"

実行

ansible-playbook playbook.yml

参考

17
18
0

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
17
18