Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationEventAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
17
Help us understand the problem. What are the problem?

More than 5 years have passed since last update.

Ansibleでユーザを追加

  • /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

参考

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
17
Help us understand the problem. What are the problem?