Created
March 24, 2014 13:52
-
-
Save shirou/9740486 to your computer and use it in GitHub Desktop.
create user ansible playbook
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| --- | |
| - hosts: all | |
| sudo: yes | |
| vars: | |
| - user_name: worker | |
| - github_name: shirou | |
| roles: | |
| - initilize_user |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| - name: create user | |
| user: name={{ user_name }} shell=/bin/bash | |
| - name: create ssh dir | |
| file: path=/home/{{ user_name }}/.ssh state=directory | |
| - name: copy authorized_key from github | |
| get_url: url=https://github.com/{{ github_name }}.keys | |
| dest=/home/{{ user_name }}/.ssh/authorized_keys | |
| - name: chown and chmod of ssh dir | |
| file: path=/home/{{ user_name }}/.ssh recurse=yes | |
| owner={{ user_name }} group={{ user_name }} mode=0700 | |
| state=directory | |
| - name: copy sudoers file for safety | |
| command: cp -f /etc/sudoers /etc/sudoers.tmp | |
| - name: add nopassword user | |
| lineinfile: dest=/etc/sudoers.tmp line="{{ user_name }} ALL=(ALL:ALL) NOPASSWD:ALL" | |
| - name: copy tmp file to real file with visudo check | |
| shell: visudo -q -c -f /etc/sudoers.tmp && cp -f /etc/sudoers.tmp /etc/sudoers |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment