Compare commits
No commits in common. "e346a61cedb1b049d877ebd2764f697ba92c6394" and "c61e3a78264ea2e659cb274839b4434a5b3eec5a" have entirely different histories.
e346a61ced
...
c61e3a7826
@ -37,12 +37,3 @@ 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
|
||||
|
@ -3,9 +3,10 @@
|
||||
community.general.pacman:
|
||||
name: stow
|
||||
state: present
|
||||
become: true
|
||||
|
||||
- name: Install git
|
||||
community.general.pacman:
|
||||
name: git
|
||||
state: present
|
||||
|
||||
become: true
|
||||
|
@ -1,37 +0,0 @@
|
||||
---
|
||||
- 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 }}"
|
||||
|
@ -27,6 +27,27 @@
|
||||
when: user.public_key
|
||||
|
||||
# Dotfiles
|
||||
- name: set dotfiles
|
||||
import_tasks: dotfiles.yml
|
||||
- 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 }}"
|
||||
|
||||
|
@ -1,24 +0,0 @@
|
||||
---
|
||||
- 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 }}"
|
||||
|
@ -1,23 +0,0 @@
|
||||
---
|
||||
- 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
|
@ -1,23 +0,0 @@
|
||||
---
|
||||
- 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 }}"
|
||||
|
33
roles/users/.yamllint
Normal file
33
roles/users/.yamllint
Normal file
@ -0,0 +1,33 @@
|
||||
---
|
||||
# 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
|
38
roles/users/README.md
Normal file
38
roles/users/README.md
Normal file
@ -0,0 +1,38 @@
|
||||
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).
|
21
roles/users/defaults/main.yml
Normal file
21
roles/users/defaults/main.yml
Normal file
@ -0,0 +1,21 @@
|
||||
---
|
||||
# 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
|
1
roles/users/files/id_encrypt_fool.pub
Normal file
1
roles/users/files/id_encrypt_fool.pub
Normal file
@ -0,0 +1 @@
|
||||
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFdDO8452/DpTR8taSKa/i+rgAvrYP9Fv9hYLMuphHQ+ user1@fool
|
2
roles/users/handlers/main.yml
Normal file
2
roles/users/handlers/main.yml
Normal file
@ -0,0 +1,2 @@
|
||||
---
|
||||
# handlers file for users
|
23
roles/users/molecule/default/INSTALL.rst
Normal file
23
roles/users/molecule/default/INSTALL.rst
Normal file
@ -0,0 +1,23 @@
|
||||
*********************************
|
||||
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'
|
8
roles/users/molecule/default/converge.yml
Normal file
8
roles/users/molecule/default/converge.yml
Normal file
@ -0,0 +1,8 @@
|
||||
---
|
||||
- name: Converge
|
||||
hosts: all
|
||||
become: true
|
||||
tasks:
|
||||
- name: "Include users"
|
||||
include_role:
|
||||
name: "users"
|
14
roles/users/molecule/default/molecule.yml
Normal file
14
roles/users/molecule/default/molecule.yml
Normal file
@ -0,0 +1,14 @@
|
||||
---
|
||||
dependency:
|
||||
name: galaxy
|
||||
driver:
|
||||
name: vagrant
|
||||
platforms:
|
||||
- name: archlinux
|
||||
box: "archlinux/archlinux"
|
||||
- name: Debian
|
||||
box: "debian/bullseye64"
|
||||
provisioner:
|
||||
name: ansible
|
||||
verifier:
|
||||
name: testinfra
|
Binary file not shown.
Binary file not shown.
22
roles/users/molecule/default/tests/conftest.py
Normal file
22
roles/users/molecule/default/tests/conftest.py
Normal file
@ -0,0 +1,22 @@
|
||||
"""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
|
||||
)
|
10
roles/users/molecule/default/tests/test_default.py
Normal file
10
roles/users/molecule/default/tests/test_default.py
Normal file
@ -0,0 +1,10 @@
|
||||
"""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"
|
25
roles/users/tasks/main.yml
Normal file
25
roles/users/tasks/main.yml
Normal file
@ -0,0 +1,25 @@
|
||||
---
|
||||
# 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 }}"
|
2
roles/users/tests/inventory
Normal file
2
roles/users/tests/inventory
Normal file
@ -0,0 +1,2 @@
|
||||
localhost
|
||||
|
5
roles/users/tests/test.yml
Normal file
5
roles/users/tests/test.yml
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
- hosts: localhost
|
||||
remote_user: root
|
||||
roles:
|
||||
- users
|
2
roles/users/vars/main.yml
Normal file
2
roles/users/vars/main.yml
Normal file
@ -0,0 +1,2 @@
|
||||
---
|
||||
# vars file for users
|
Loading…
Reference in New Issue
Block a user