Files
dotfiles/playbook.yml

209 lines
4.9 KiB
YAML

- hosts: localhost
connection: local
become: false
tasks:
- set_fact:
distro: "{{ ansible_distribution|lower }}"
- set_fact:
user: "{{ ansible_user_id }}"
- name: configure sudoers
lineinfile:
path: /etc/sudoers
line: "{{ user }} ALL=(ALL) NOPASSWD:ALL"
regexp: "^{{ user }}\\s+"
become: true
- name: set shell
user:
name: "{{ user }}"
shell: /usr/bin/zsh
become: true
- name: install selinux specials on fedora
package:
state: installed
name: libselinux-python
become: true
when: distro == 'fedora'
- name: load package list
include_vars:
file: packages.yml
- name: enable neovim ppa
apt_repository:
repo: 'ppa:neovim-ppa/stable'
update_cache: true
become: true
when: distro == 'ubuntu'
- set_fact:
defined_packages: "{{ packages|json_query('keys(list)') }}"
- set_fact:
distro_packages: "{{ packages|json_query('list.*.%s'|format(distro)) }}"
- name: check list
assert:
that: "defined_packages|length == distro_packages|length"
- name: install packages
package:
name: "{{ packages|json_query(query) }}"
state: installed
become: true
vars:
query: "{{ 'list.*.%s[]'|format(distro) }}"
- name: disable services
service:
state: stopped
enabled: false
name: "{{ item }}"
with_items: []
become: true
- name: enable services
service:
state: started
enabled: true
name: "{{ item }}"
with_items:
- NetworkManager
become: true
- name: set groups for fedora
user:
name: "{{ user }}"
groups:
- libvirt
- wheel
- vboxusers
- wireshark
- docker
become: true
when: distro == 'fedora'
- name: set groups for ubuntu
user:
name: "{{ user }}"
groups:
- adm
- cdrom
- sudo
- dip
- plugdev
- lpadmin
- sambashare
- docker
- libvirt
become: true
when: distro == 'ubuntu'
- name: get systemd boot target
command: systemctl get-default
register: systemd_target
changed_when: false
- set_fact:
default_target: multi-user.target
- name: set systemd boot target
command: systemctl set-default {{ default_target }}
when: systemd_target.stdout != default_target
become: true
- name: handle lid switch
lineinfile:
path: /etc/systemd/logind.conf
regexp: '^HandleLidSwitch='
line: 'HandleLidSwitch=ignore'
become: true
- name: handle power key
lineinfile:
path: /etc/systemd/logind.conf
regexp: '^HandlePowerKey='
line: 'HandlePowerKey=suspend'
become: true
- name: create directory for getty autologin
file:
state: directory
path: /etc/systemd/system/getty@tty1.service.d
owner: root
group: root
mode: '0755'
become: true
- name: enable getty autologin
copy:
dest: /etc/systemd/system/getty@tty1.service.d/override.conf
owner: root
group: root
mode: '0644'
content: |
[Service]
ExecStart=
ExecStart=-/sbin/agetty --autologin {{ user }} --noclear %I $TERM
become: true
- name: load dotfile list
include_vars:
file: dotfiles.yml
- name: link this folder to ~/.dotfiles
file:
state: link
force: true
path: "{{ ansible_user_dir }}/.dotfiles"
src: "{{ playbook_dir }}"
- name: link dotfiles
file:
state: link
force: true
path: "{{ ansible_user_dir }}/{{ item.to }}"
src: ~/.dotfiles/{{ item.from }}
with_items: "{{ dotfiles }}"
- name: create directories
file:
state: directory
path: "{{ item }}"
with_items:
- ~/.var/lib
- ~/.var/log
- ~/.var/run
- ~/.usr/lib
- name: create intermediate directories for vim-plug
file:
path: "{{ item }}"
state: directory
with_items:
- ~/.local/
- ~/.local/share/
- ~/.local/share/nvim/
- ~/.local/share/nvim/site/
- ~/.local/share/nvim/site/autoload/
- ~/.vim/
- ~/.vim/autoload
- name: install vim-plug
get_url:
dest: ~/.vim/autoload/plug.vim
url: https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
- name: symlink vim-plug for neovim
file:
state: link
path: ~/.local/share/nvim/site/autoload/plug.vim
src: ~/.vim/autoload/plug.vim
force: true
- name: install vim plugins
command: /usr/bin/vim -f -E -s -c "source ~/.vimrc" +PlugInstall +qall