CRQNNMs1
2017-01-12 02:26:10

```
- hosts: "{{ hosts }}"
become: true
become_method: su
become_user: root
gather_facts: no
pre_tasks:
- name: Install Python
raw: sudo apt-get -y install python

tasks:
- name: Add 'admin' User
user:
name: admin
shell: /bin/bash

- name: Allow 'admin' user to have passwordless sudo
lineinfile:
dest: /etc/sudoers
state: present
regexp: '^%admin'
line: 'admin ALL=(ALL) NOPASSWD: ALL'

- name: Set authorized key took from file
authorized_key:
user: admin
state: present
key: "{{ lookup('file', '/home/admin/.ssh/id_rsa.pub') }}"
```
> sudo ansible-playbook default.yml -e "hosts=YOUR_HOSTS ansible_user=root ansible_ssh_pass=YOUR_PASSWORD" --ask-become-pass

- ansible_user, ansible_ssh_pass: ssh 인증이 아닌 password 인증을 하기 위한 명령어
- ask-become-pass: tasks 에 sudo 권한이 필요한 명령어가 있는 경우 become_user 의 비밀번호 전달