Add ffhh-basics role
This commit is contained in:
parent
81ccb6e583
commit
4dee59fad1
|
@ -3,3 +3,5 @@
|
|||
roles:
|
||||
- role: basics
|
||||
tags: basics
|
||||
- role: ffhh-basics
|
||||
tags: basics
|
||||
|
|
|
@ -1,7 +1,2 @@
|
|||
---
|
||||
basics_autoupdate_reboot: "false"
|
||||
basics_install_packages:
|
||||
- mosh
|
||||
- nano
|
||||
- virtualenv
|
||||
- zsh
|
||||
|
|
68
roles/ffhh-basics/files/new-user
Executable file
68
roles/ffhh-basics/files/new-user
Executable file
|
@ -0,0 +1,68 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
# This script assumes that you want to add a user with name
|
||||
# equal to a keyfile in the freiunkhamburg/ssh-keys repo
|
||||
# on github.
|
||||
#
|
||||
# This script assumes you know what you are doing. ;)
|
||||
#
|
||||
# .. ohrensessel, 2017
|
||||
#
|
||||
|
||||
echoerr() { echo "$@" 1>&2; }
|
||||
|
||||
if [ $# -eq 0 ]; then
|
||||
echoerr Missing username
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ $EUID -ne 0 ]]; then
|
||||
echoerr This script must be run as root
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if id "$1" >/dev/null 2>&1; then
|
||||
echoerr This user exists
|
||||
exit 1
|
||||
fi
|
||||
|
||||
wget -P /tmp https://raw.githubusercontent.com/freifunkhamburg/ssh-keys/master/"$1".pub &>/dev/null
|
||||
|
||||
if [ $? -ne 0 ]
|
||||
then
|
||||
echoerr Could not download key file, username not equal to name of key file?
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo
|
||||
echo Adding user with name "$1" and ssh keys:
|
||||
echo
|
||||
cat /tmp/"$1".pub
|
||||
echo
|
||||
|
||||
read -p "Are you sure? " -n 1 -r
|
||||
echo
|
||||
if [[ ! $REPLY =~ ^[Yy]$ ]]
|
||||
then
|
||||
echoerr Aborting...
|
||||
rm /tmp/"$1".pub
|
||||
exit 1
|
||||
fi
|
||||
|
||||
useradd -m -G sudo "$1"
|
||||
|
||||
if [ $? -ne 0 ]
|
||||
then
|
||||
echoerr Could not add user
|
||||
rm /tmp/"$1".pub
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "$1":test123 | chpasswd &>/dev/null
|
||||
chage -d0 "$1" &>/dev/null
|
||||
|
||||
mkdir /home/"$1"/.ssh
|
||||
mv /tmp/"$1".pub /home/"$1"/.ssh/authorized_keys
|
||||
chown "$1":"$1" /home/"$1"/.ssh -R
|
||||
chmod 700 /home/"$1"/.ssh
|
||||
chmod 600 /home/"$1"/.ssh/authorized_keys
|
18
roles/ffhh-basics/tasks/main.yml
Normal file
18
roles/ffhh-basics/tasks/main.yml
Normal file
|
@ -0,0 +1,18 @@
|
|||
---
|
||||
- name: install popular user packages
|
||||
apt:
|
||||
name: "{{ item }}"
|
||||
state: present
|
||||
with_items:
|
||||
- mosh
|
||||
- nano
|
||||
- wget
|
||||
- zsh
|
||||
|
||||
- name: copy new-user script
|
||||
copy:
|
||||
src: new-user
|
||||
dest: /usr/local/sbin
|
||||
owner: root
|
||||
group: root
|
||||
mode: 0550
|
Loading…
Reference in a new issue