Compare commits

...

2 Commits

Author SHA1 Message Date
e346a61ced Feat: modularie user and dotfiles 2022-01-12 06:06:12 +01:00
5ffb1dbfa8 Feat: remove users role 2022-01-12 06:05:35 +01:00
23 changed files with 119 additions and 231 deletions

View File

@ -37,3 +37,12 @@ def test_clone_dotfiles(host):
dotfiles = host.file(admin.home + "/.dotfiles")
assert dotfiles.exists
assert dotfiles.user == admin.name
def test_stow_config(host):
user = host.user("user")
nvim_config = host.files(user.home + "/.config/nvim/")
assert nvim_config.exists
admin = host.user("admin")
nvim_config = host.files(admin.home + "/.config/nvim/")
assert not nvim_config.exists

View File

@ -3,10 +3,9 @@
community.general.pacman:
name: stow
state: present
become: true
- name: Install git
community.general.pacman:
name: git
state: present
become: true

View File

@ -0,0 +1,37 @@
---
- name: Install for arch
import_tasks: arch.yml
when: ansible_os_family == "Archlinux"
- name: Install for debian
import_tasks: debian.yml
when: ansible_os_family == "Debian"
- name: init neovim
import_tasks: neovim.yml
when: '"nvim" in user.config.stowing'
- name: init vim
import_tasks: vim.yml
when: '"vim" in user.config.stowing'
- name: init sway
import_tasks: sway.yml
when: '"sway" in user.config.stowing'
- name: Clone dotfiles
ansible.builtin.git:
repo: "{{ user.config.giturl }}"
dest: "/home/{{ user.username }}/.dotfiles"
- name: user owns its dotfiles
ansible.builtin.file:
path: "/home/{{ user.username }}/.dotfiles"
owner: "{{ user.username }}"
- name: stow configs
ansible.builtin.command:
cmd: stow {{ item }}
chdir: "/home/{{ user.username }}/.dotfiles"
with_items: "{{ user.config.stowing }}"

View File

@ -27,27 +27,6 @@
when: user.public_key
# Dotfiles
- name: Install for arch
import_tasks: arch.yml
when: ansible_os_family == "Archlinux"
- name: Install for debian
import_tasks: debian.yml
when: ansible_os_family == "Debian"
- name: Clone dotfiles
ansible.builtin.git:
repo: "{{ user.config.giturl }}"
dest: "/home/{{ user.username }}/.dotfiles"
- name: user owns its dotfiles
ansible.builtin.file:
path: "/home/{{ user.username }}/.dotfiles"
owner: "{{ user.username }}"
- name: stow configs
ansible.builtin.command:
cmd: stow {{ item }}
chdir: "/home/{{ user.username }}/.dotfiles"
with_items: "{{ user.config.stowing }}"
- name: set dotfiles
import_tasks: dotfiles.yml

View File

@ -0,0 +1,24 @@
---
- name: Install neovim
community.general.pacman:
name: neovim
state: present
when: ansible_os_family == "Archlinux"
- name: Install neovim
apt:
name: neovim
state: present
when: ansible_os_family == "Debian"
- name: Install packer
ansible.builtin.git:
repo: "https://github.com/wbthomason/packer.nvim"
dest: "/home/{{ user.username }}/.local/share/nvim/site/pack/packer/start/packer.nvim"
depth: 1
- name: user owns packer
ansible.builtin.file:
path: "/home/{{ user.username }}/.local/share/nvim/site/pack/packer/start/packer.nvim"
owner: "{{ user.username }}"

23
roles/user/tasks/sway.yml Normal file
View File

@ -0,0 +1,23 @@
---
- name: Install sway packages
community.general.pacman:
name:
- sway
- gammastep
- mako
- rofi
- rofi-pass
- grim
- kanshi
- blueman
- pamixer
- waybar
- network-manager-applet
- wlroots
- xdg-desktop-portal-wlr
- wl-clipboard
state: present
- name: Install sway AUR packages
aut:
- avizo

23
roles/user/tasks/vim.yml Normal file
View File

@ -0,0 +1,23 @@
---
- name: Install vim
community.general.pacman:
name: vim
state: present
when: ansible_os_family == "Archlinux"
- name: Install vim
apt:
name: vim
state: present
when: ansible_os_family == "Debian"
- name: Install vim-plug
get_url:
url: "https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim"
dest: "/home/{{ user.username }}/.vim/autoload/plug.vim"
- name: user owns vim-plug
ansible.builtin.file:
path: "/home/{{ user.username }}/.vim/autoload/plug.vim"
owner: "{{ user.username }}"

View File

@ -1,33 +0,0 @@
---
# Based on ansible-lint config
extends: default
rules:
braces:
max-spaces-inside: 1
level: error
brackets:
max-spaces-inside: 1
level: error
colons:
max-spaces-after: -1
level: error
commas:
max-spaces-after: -1
level: error
comments: disable
comments-indentation: disable
document-start: disable
empty-lines:
max: 3
level: error
hyphens:
level: error
indentation: disable
key-duplicates: enable
line-length: disable
new-line-at-end-of-file: disable
new-lines:
type: unix
trailing-spaces: disable
truthy: disable

View File

@ -1,38 +0,0 @@
Role Name
=========
A brief description of the role goes here.
Requirements
------------
Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required.
Role Variables
--------------
A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well.
Dependencies
------------
A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles.
Example Playbook
----------------
Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too:
- hosts: servers
roles:
- { role: username.rolename, x: 42 }
License
-------
BSD
Author Information
------------------
An optional section for the role authors to include contact information, or a website (HTML is not allowed).

View File

@ -1,21 +0,0 @@
---
# defaults file for users
user1:
username: 'user1'
password: 'user1'
group: users
groups:
shell: '/bin/zsh'
user2:
username: 'user2'
password: 'user2'
group: users
groups: wheel
system: yes
users: ["{{ user1 }}", "{{ user2 }}"]
public_key:
- user: "{{ user1 }}"
key: id_encrypt_fool.pub

View File

@ -1 +0,0 @@
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFdDO8452/DpTR8taSKa/i+rgAvrYP9Fv9hYLMuphHQ+ user1@fool

View File

@ -1,2 +0,0 @@
---
# handlers file for users

View File

@ -1,23 +0,0 @@
*********************************
Vagrant driver installation guide
*********************************
Requirements
============
* Vagrant
* Virtualbox, Parallels, VMware Fusion, VMware Workstation or VMware Desktop
Install
=======
Please refer to the `Virtual environment`_ documentation for installation best
practices. If not using a virtual environment, please consider passing the
widely recommended `'--user' flag`_ when invoking ``pip``.
.. _Virtual environment: https://virtualenv.pypa.io/en/latest/
.. _'--user' flag: https://packaging.python.org/tutorials/installing-packages/#installing-to-the-user-site
.. code-block:: bash
$ pip install 'molecule_vagrant'

View File

@ -1,8 +0,0 @@
---
- name: Converge
hosts: all
become: true
tasks:
- name: "Include users"
include_role:
name: "users"

View File

@ -1,14 +0,0 @@
---
dependency:
name: galaxy
driver:
name: vagrant
platforms:
- name: archlinux
box: "archlinux/archlinux"
- name: Debian
box: "debian/bullseye64"
provisioner:
name: ansible
verifier:
name: testinfra

View File

@ -1,22 +0,0 @@
"""PyTest Fixtures."""
from __future__ import absolute_import
import os
import pytest
def pytest_runtest_setup(item):
"""Run tests only when under molecule with testinfra installed."""
try:
import testinfra
except ImportError:
pytest.skip("Test requires testinfra", allow_module_level=True)
if "MOLECULE_INVENTORY_FILE" in os.environ:
pytest.testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
os.environ["MOLECULE_INVENTORY_FILE"]
).get_hosts("all")
else:
pytest.skip(
"Test should run only from inside molecule.", allow_module_level=True
)

View File

@ -1,10 +0,0 @@
"""Role testing files using testinfra."""
def test_hosts_file(host):
"""Validate /etc/hosts file."""
f = host.file("/etc/hosts")
assert f.exists
assert f.user == "root"
assert f.group == "root"

View File

@ -1,25 +0,0 @@
---
# tasks file for users
- name: users -- Ensure wheel group exists
group:
name: wheel
state: present
- name: create users
ansible.builtin.user:
name: "{{ item.username }}"
update_password: on_create
password: "{{ item.password | password_hash('sha512')}}"
group: "{{ item.group }}"
groups: "{{ item.groups }}"
shell: "{{ item.shell | default('/bin/bash') }}"
state: present
system: "{{ item.system | default('no') }}"
with_items: "{{ users }}"
- name: ssh -- Add public key
authorized_key:
user: "{{ item.user.username }}"
key: "{{ lookup('file', item.key) }}"
state: present
with_items: "{{ public_key }}"

View File

@ -1,2 +0,0 @@
localhost

View File

@ -1,5 +0,0 @@
---
- hosts: localhost
remote_user: root
roles:
- users

View File

@ -1,2 +0,0 @@
---
# vars file for users