Inital commit

Good start
Added roles for setting up a user with zsh config and ssh keys
Also installation and configuriation of some packages
This commit is contained in:
Sivert V. Sæther 2022-03-14 01:16:44 +01:00
parent 27a60cb898
commit b3d85445c5
18 changed files with 209 additions and 2 deletions

View File

@ -1,3 +1,3 @@
# ansible # Ansible
Ansible playbooks for setting up configs I like. Ansible playbooks for setting up configs I like.

7
ansible.cfg Normal file
View File

@ -0,0 +1,7 @@
[defaults]
interpreter_python = python3
ansible_become_exe = doas
private_key_file = ~/.ssh/id_rsa
remote_user = siv
[privilege_escalation]
become = yes

5
docker.ini Normal file
View File

@ -0,0 +1,5 @@
[docker]
docker-alpine-test ansible_connection=docker ansible_user=root ansible_host=ansible
[alpine:children]
docker

10
group_vars/all.yml Normal file
View File

@ -0,0 +1,10 @@
name: siv
shell: /bin/zsh
user_groups: [adm,wheel,kvm,libvirt,docker]
packages: neofetch openssh doas git zsh bat lsd
pubkeys:
- ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQC1O7dXSrkDZ0l2kQMDnUPcALEYrq9l+fCKANb4sKZebRr+CkvO0Yat6f/O1a4OJWKeIpOMNIG60aiQB4Npn1ACosQ5Jgw1GypEr6QWDKdWqTEQ4qQaJk2sAKbUpEHTvtwlRTZy5zxC0TrRSjXcNmPR5O4GGMPLAdWFmD9iIRA+tjGvB6U4NY8KafxzBmje95oVP8erayEZT90IgljLisg29uAofAfAhjP/KV/z1ppmwrL7Et6N2ZcOfFl+KOcefzjt0bdkV0gFXqYKEFK9WEpVXEHE7CpOu/dJZgVvTT+jfHhWhANkl66dDbv80nfHAINASCBCoUi6CFb8TBru4WABeoyKEQnC04IqHXvgOMr5/f9Sx1PHZNxkXNVuSPbkSnA7Qk4OnHG5c/rEeZ850eM8j0or29PyNFvZjWjBrIG1iReRTdSDkzdwojLuCKMrN8qxmDMuYW0Ey9DCsC2iKyYzJ+3dhilXkaUtQYHrtCM4DB4rcAWV2hRS1mRZwWmKH4QWvwVbjipKAzHg3i2hMFIC6HbN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BvaDqB1ihqkF/1mZLiUrsij/7sEUxI3ZIiLPEVRHPnOb+6oFomWPOGbhwPbl98lOgarsNQzQaOe36KFGC6zHPwN/d5PT5TNCgUQ7Gg8igTlXKSH/XUNy4ArQrjTisWt6k93zrAn0HK2Mh774Bvf9eAXqkvlIoti+r8X8nbiIpVAKvm8Q== siv@billy
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQC6HmJQGvQghh8g8JWoUkQf6d3rokSJad4on69WahrvyBUzDASwOnACX0yztDYYu7UzH8TtJqknbp2P5JSKVR+PFvNxo24QYC671QzGyRq4urL8YDsWj5feSL4MEvFY0ivNRNxAKxLHXg+i0jQtiDwBOkhQl0VFrqsKdGlEVcghVeogBAdzHFQNQ7ENZMS30qzW1wrcwWbUBF8ZSvwEQgCXH0UHcIWi3Rzd0g0LfvfbOtI1UjuBzT0gd5F1RSHh0XJWK7jcVrNShMVQqmWWLuHVd8T2k7flGQDBeZPKo3GXdnB4cXgkfNJrsyNDLoJXimj8UryNpn3ejV9DkreL985uAmkLPY11bkD6vWgdZgXA3aWpLQm05crOu4GEn1bGhbnIORm4mjxlANJB0QC9FliCAVkLk4OY7UGnx4mgqMyYjb2LCdgGKVVto97UAisJxWikLiM5nCNrCaGBe05d2nVxPXVKwALI3E2AeIYSmjE4N3mBgUIxWuGS6KoOZsnoSYS3+blQV0W/POuFw4NhlWgZUi8GAaGPfWj8pM/u9dH8FKxhK/PabVKtltLkn4ntgewaeNl18n1NFkQtcDD7Kkg/ZIQ9SiNchK0SxR0/Pgwo/A5GacF+nwTgxGwDJbQ0OPaVlbQd/cCaXl1AX9s7R5Xd8D35KFHTJ1IVnZohDGVQvQ== mob

View File

View File

@ -0,0 +1 @@
permit nopass siv as root

View File

@ -0,0 +1,44 @@
- name: Install and configure packages
block:
- name: Install the good stuff (pacman)
pacman: name={{ packages }} state=latest
when: "'pacman' in group_names"
tags: pacman
- name: Add some repos (alpine)
become: yes
shell: cmd="cat > /etc/apk/repositories << EOF; $(echo)
https://dl-cdn.alpinelinux.org/alpine/v$(cat /etc/alpine-release | cut -d'.' -f1,2)/main/
https://dl-cdn.alpinelinux.org/alpine/v$(cat /etc/alpine-release | cut -d'.' -f1,2)/community/
https://dl-cdn.alpinelinux.org/alpine/edge/testing/
EOF"
when: "'alpine' in group_names"
- name: Install the good stuff (apk)
apk: name={{ packages }} state=latest
when: "'apk' in group_names or 'alpine' in group_names"
tags: apk
- name: Install the good stuff (apt)
apt: package={{ packages }} state=latest
when: "'apt' in group_names"
tags: apt
- name: Add /etc/doas.conf
copy: src=doas.conf dest=/etc/doas.conf owner=root group=root mode=0644
tags: system
rescue:
- name: Uninstall the good stuff (pacman)
pacman: name={{ packages }} state=absent
when: "'pacman' in group_names"
tags: pacman
- name: Uninstall the good stuff (apk)
apk: name={{ packages }} state=absent
when: "'apk' in group_names or 'alpine' in group_names"
tags: apk
- name: Uninstall the good stuff (apt)
apt: package={{ packages }} state=absent
when: "'apt' in group_names"
tags: apt
- name: Remove /etc/doas.conf
file: state=absent path=/etc/doas.conf
tags: system

17
roles/update/main.yml Normal file
View File

@ -0,0 +1,17 @@
- name: Update and upgrade pacman packages
pacman:
update_cache: yes
upgrade: yes
tags: pacman
- name: Update and upgrade apk packages
become: true
apk:
update_cache: yes
upgrade: yes
tags: apk
- name: Update and upgrade apt packages
become: true
apt:
update_cache: yes
upgrade: yes
tags: apt

15
roles/user/tasks/main.yml Normal file
View File

@ -0,0 +1,15 @@
- name: Create user
user:
name="{{ name }}"
groups="{{ item }}"
shell="{{ shell }}"
append=yes
ignore_errors: yes
with_items:
- "{{ user_groups }}"
- name: Add SSH pubkeys
authorized_key:
user="{{ name }}"
key="{{ item }}"
with_items:
- "{{ pubkeys }}"

View File

@ -0,0 +1,7 @@
#!/bin/sh
alias\
ls="lsd -h --color=auto --group-dirs first"\
ll="ls -l"\
la="ls -a"\
diff="diff --color=auto"\
grep="grep --color=auto -n"

6
roles/zsh/files/bat.conf Normal file
View File

@ -0,0 +1,6 @@
--theme "Solarized (dark)"
--style "numbers,changes,header"
--map-syntax "*.ino:C++"
--decorations auto
--color auto
--tabs 2

16
roles/zsh/files/env.sh Normal file
View File

@ -0,0 +1,16 @@
#!/bin/sh
export LS_COLORS='di=1;35:fi=0:ln=31:pi=5:so=5:bd=5:cd=5:or=31:mi=0:ex=35:*.rpm=90:*.png=35:*.gif=36:*.jpg=35:*.c=92:*.jar=33:*.py=93:*.h=90:*.txt=94:*.doc=104:*.docx=104:*.odt=104:*.csv=102:*.xlsx=102:*.xlsm=102:*.rb=31:*.cpp=92:*.sh=92:*.html=96:*.zip=4;33:*.tar.gz=4;33:*.mp4=105:*.mp3=106'
[ -d ~/.npm/node_modules/.bin ] && PATH=~/.npm/node_modules/.bin:$PATH
[ -d ~/.go/bin ] && PATH=~/.go/bin:$PATH
[ -d ~/.cargo/bin ] && PATH=~/.cargo/bin:$PATH
[ -d ~/.local/bin ] && PATH=~/.local/bin:$PATH
[ -d ~/.emacs.d/bin ] && PATH=~/.emacs.d/bin:$PATH
[ -e ~/.aliases ] && source ~/.aliases
export EDITOR=/usr/bin/vim
export HISTFILE=~/.histfile
export HISTSIZE=42069
export SAVEHIST=42069
export PAGER="less"
export BAT_CONFIG_PATH=~/.bat.conf
export GOPATH=~/.go
export PATH

15
roles/zsh/files/zshrc.zsh Normal file
View File

@ -0,0 +1,15 @@
[[ $- != *i* ]] && return
PROMPT="%F{yellow}% %n%F{green}% @%F{blue}% %m %F{#bb33bb}% %1~%f > "
setopt autocd extendedglob nomatch notify prompt_subst
autoload -Uz compinit && compinit
unsetopt beep
bindkey -v
[ -e ~/.zstyles ] && source ~/.zstyles
[ -e ~/.env ] && source ~/.env
for src in `/bin/ls ~/.zshrc.d`; do
[ -e $src ] && source $src
done
source ~/.zshrc.d/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh

View File

@ -0,0 +1,13 @@
zstyle ':completion:*' auto-description 'specify: %d'
zstyle ':completion:*' completer _expand _complete _ignored _correct _approximate
zstyle ':completion:*' format 'Completing %d'
zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
zstyle ':completion:*' list-prompt %SAt %p: Hit TAB for more, or the character to insert%s
zstyle ':completion:*' max-errors 1
zstyle ':completion::complete:*' use-cache 1
zstyle ':vcs_info:*' enable git
zstyle ':vcs_info:git*+set-message:*' hooks untracked-git
zstyle ':vcs_info:*' check-for-changes true
zstyle ':vcs_info:*' unstagedstr '!'
zstyle ':vcs_info:*' stagedstr '+'
zstyle ':vcs_info:*' formats "%f%s(%F{red}%r/%b%f)%c "$'\n'" %F{#bb33bb}% %S%f"

33
roles/zsh/tasks/main.yml Normal file
View File

@ -0,0 +1,33 @@
- name: Setup user zsh config
block:
- name: Add .zshrc
copy: src=zshrc.zsh dest=/home/{{ name }}/.zshrc owner={{ name }} group={{ name }} mode=0755
- name: Add zsh zstyles config
copy: src=zstyles.zsh dest=/home/{{ name }}/.zstyles owner={{ name }} group={{ name }} mode=0755
- name: Add .env file
copy: src=env.sh dest=/home/{{ name }}/.env owner={{ name }} group={{ name }} mode=0755
- name: Add .aliases
copy: src=aliases.sh dest=/home/{{ name }}/.aliases owner={{ name }} group={{ name }} mode=0755
- name: Add .bat.conf
copy: src=bat.conf dest=/home/{{ name }}/.bat.conf owner={{ name }} group={{ name }} mode=0755
- name: Install zsh syntax highlighting
git:
repo: https://github.com/zsh-users/zsh-syntax-highlighting.git
dest: /home/{{ name }}/.zshrc.d/zsh-syntax-highlighting
update: yes
clone: yes
rescue:
- name: Remove .zshrc
file: state=absent path=/home/{{ name }}/.zshrc
- name: Remove zsh zstyles config
file: state=absent path=/home/{{ name }}/.zstyles
- name: Remove .env file
file: state=absent path=/home/{{ name }}/.env
- name: Remove .aliases
file: state=absent path=/home/{{ name }}/.aliases
- name: Remove .bat.conf
file: state=absent path=/home/{{ name }}/.bat.conf
# - name: Remove zsh syntax highlighting
# file: state=absent path=/home/{{ name }}/.zshrc.d/zsh-syntax-highlighting

11
servers.ini Normal file
View File

@ -0,0 +1,11 @@
[linode]
archy.42069.no
[kjellern]
42069.no
stor
[apt:children]
42069.no
[pacman:children]
archy.42069.no
stor

2
site.yml Normal file
View File

@ -0,0 +1,2 @@
- hosts: all
roles: [update, common, user, { role: zsh, tags: "syntax,extra" }]

5
test-docker.sh Executable file
View File

@ -0,0 +1,5 @@
#!/bin/sh
[ "$1" == "stop" ] && docker kill ansible && exit 0
docker run --rm --name ansible -id alpine
[ $? == 0 ] && docker exec ansible /bin/sh -c "apk update && apk add python3"
ansible -i docker.ini all -m ping