Skip to content

Instantly share code, notes, and snippets.

@jiahut
Last active June 6, 2019 13:07
Show Gist options
  • Select an option

  • Save jiahut/f3106b2cfe580e4a608902e87c530381 to your computer and use it in GitHub Desktop.

Select an option

Save jiahut/f3106b2cfe580e4a608902e87c530381 to your computer and use it in GitHub Desktop.

user groups basic

groups

usermod -a -G wheel admin

https://superuser.com/questions/547966/whats-the-difference-between-adduser-and-useradd

ls -l $(which adduser)

add user and sudo privileges at centos

https://www.digitalocean.com/community/tutorials/how-to-create-a-sudo-user-on-centos-quickstart

adduser admin usermod -aG wheel admin passwd admin su - admin sudo ls -la /root # The first time you use sudo in a session, you will be prompted for the password of the user account sh -c "$(curl -fsSL https://raw.githubusercontent.com/Linuxbrew/install/master/install.sh)"

add user and sudo privileges at debain

https://www.digitalocean.com/community/tutorials/how-to-add-delete-and-grant-sudo-privileges-to-users-on-a-debian-vps

adduser admin usermod -aG sudo admin passwd admin su - admin sh -c "$(curl -fsSL https://raw.githubusercontent.com/Linuxbrew/install/master/install.sh)"

install ansible

yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

yum install -y ansible

add user with ansible

curl -LOk https://gist.githubusercontent.com/jiahut/f3106b2cfe580e4a608902e87c530381/raw/add-user-with-group.yml

ansible-playbook --connection=local -i 127.0.0.1, add-user-with-group.yml -e 'user=jazz' -e 'password=Password!'

curl -LOk https://gist.githubusercontent.com/jiahut/f3106b2cfe580e4a608902e87c530381/raw/setup-user-to-wheel-group.yml

ansible-playbook --connection=local -i 127.0.0.1, setup-user-to-wheel-group.yml -e 'sudo_user=admin'

curl -LOk https://gist.githubusercontent.com/jiahut/f3106b2cfe580e4a608902e87c530381/raw/install-docker-ce-centos.yaml

curl -LOk https://gist.githubusercontent.com/jiahut/f3106b2cfe580e4a608902e87c530381/raw/install-docker-ce-ubuntu.yaml

sudo ansible-playbook --connection=local -i 127.0.0.1, install-docker-ce-centos.yaml

usage at debian

gsed -i 's/ubuntu/debian/g' install-docker-ce-ubuntu.yaml

- hosts: all
become: yes
tasks:
- name: add user
user: name="{{user}}"
state=present
password="{{password}}"
shell=/bin/bash
append=yes
comment="add User by ansible"
- name: Check if group exists
shell: /usr/bin/getent group | awk -F":" '{print $1}'
register: etc_groups
- name: Add secondary Groups to user
user: name="{{user}}" groups="{{item}}" append=yes
when: '"{{item}}" in etc_groups.stdout_lines'
with_items:
- wheel
- hosts: all
become: true
tasks:
- name: "Installing Docker Prerequisite packages"
yum:
name: ['yum-utils', 'device-mapper-persistent-data', 'lvm2']
state: present
update_cache: yes
- name: "Configuring docker-ce repo"
get_url:
url: https://download.docker.com/linux/centos/docker-ce.repo
dest: /etc/yum.repos.d/docker-ce.repo
mode: 0644
- name: " Installing Docker latest version"
yum:
name: docker-ce
state: present
- name: " Starting and Enabling Docker service"
service:
name: docker
state: started
enabled: yes
- hosts: all
tasks:
- name: Install base Packages
apt:
name: ['python','gpg','apt-transport-https']
state: present
update_cache: yes
- name: Add Docker GPG key
apt_key: url=https://download.docker.com/linux/ubuntu/gpg
- name: Add Docker APT repository
apt_repository:
repo: deb [arch=amd64] https://download.docker.com/linux/ubuntu {{ansible_distribution_release}} stable
- name: Install docker packages
apt:
name: ['ca-certificates','curl','software-properties-common','docker-ce']
state: present
update_cache: yes
- name: Starting and Enabling Docker service
service:
name: docker
state: started
enabled: yes
- hosts: all
become: true
tasks:
- name: Make sure we have a 'wheel' group
group:
name: wheel
state: present
- name: Allow 'wheel' group to have passwordless sudo
lineinfile:
dest: /etc/sudoers
state: present
regexp: '^%wheel'
line: '%wheel ALL=(ALL) NOPASSWD: ALL'
validate: 'visudo -cf %s'
- name: Add sudoers {{ sudo_user }} to wheel group
user: name={{ sudo_user }} groups=wheel append=yes state=present createhome=yes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment