Last active
February 24, 2017 08:05
-
-
Save hsunami/b986273e38567d0d147e5bccb6860e41 to your computer and use it in GitHub Desktop.
Ansible script to add user to edge node and HDFS
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: edge | |
sudo: True | |
vars: | |
users: [hsunami] | |
tasks: | |
- name: Create users | |
with_items: "{{ users }}" | |
user: | |
name: "{{ item }}" | |
shell: /bin/bash | |
generate_ssh_key: yes | |
ssh_key_bits: 2048 | |
ssh_key_file: .ssh/id_rsa | |
groups: writers,hadoop | |
- name: Create authorized keys file | |
with_items: "{{ users }}" | |
command: creates="/home/{{item}}/.ssh/authorized_keys" cp /home/{{item}}/.ssh/id_rsa.pub /home/{{item}}/.ssh/authorized_keys | |
- name: Create HDFS home dirs for users | |
with_items: "{{ users }}" | |
action: | | |
command sudo -u hdfs -- /bin/sh -c ' | |
hadoop fs -mkdir -p /user/{{item}} | |
hadoop fs -chown {{item}}:hadoop /user/{{item}} | |
hadoop fs -chmod -R 755 /user/{{item}}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment