Feat: concatenate users and dotfiles into user
This commit is contained in:
23
roles/user/molecule/default/INSTALL.rst
Normal file
23
roles/user/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'
|
||||
46
roles/user/molecule/default/converge.yml
Normal file
46
roles/user/molecule/default/converge.yml
Normal file
@@ -0,0 +1,46 @@
|
||||
---
|
||||
- name: Converge
|
||||
hosts: all
|
||||
become: yes
|
||||
vars:
|
||||
users:
|
||||
- username: user
|
||||
password: "$y$j9T$PR8GfM2MjGudOCd7hF9NP1$/qRGtuNuWaRVVGmB1A4rgtaT0MMB9IoB4fnaxW1kvf4" #plop
|
||||
shell: "/bin/zsh"
|
||||
config:
|
||||
giturl: "https://git.opytex.org/lafrite/dotfiles.git"
|
||||
stowing: ["nvim", "tmux", "zsh"]
|
||||
- username: admin
|
||||
password: "$y$j9T$PR8GfM2MjGudOCd7hF9NP1$/qRGtuNuWaRVVGmB1A4rgtaT0MMB9IoB4fnaxW1kvf4" #plop
|
||||
groups: ["wheel"]
|
||||
system: yes
|
||||
config:
|
||||
giturl: "https://git.opytex.org/lafrite/dotfiles.git"
|
||||
stowing: ["tmux"]
|
||||
|
||||
pre_tasks:
|
||||
- name: update_cache for arch
|
||||
pacman:
|
||||
name:
|
||||
- zsh
|
||||
state: present
|
||||
update_cache: yes
|
||||
become: yes
|
||||
when: ansible_os_family == "Archlinux"
|
||||
|
||||
- name: update_cache for debian
|
||||
apt:
|
||||
name:
|
||||
- zsh
|
||||
state: present
|
||||
update_cache: yes
|
||||
become: yes
|
||||
when: ansible_os_family == "Debian"
|
||||
|
||||
tasks:
|
||||
- name: "Include user"
|
||||
include_role:
|
||||
name: "user"
|
||||
loop: "{{ users }}"
|
||||
loop_control:
|
||||
loop_var: user
|
||||
16
roles/user/molecule/default/molecule.yml
Normal file
16
roles/user/molecule/default/molecule.yml
Normal file
@@ -0,0 +1,16 @@
|
||||
---
|
||||
dependency:
|
||||
name: galaxy
|
||||
driver:
|
||||
name: vagrant
|
||||
platforms:
|
||||
- name: archlinux
|
||||
box: "archlinux/archlinux"
|
||||
- name: Debian
|
||||
box: "debian/bullseye64"
|
||||
provisioner:
|
||||
name: ansible
|
||||
verifier:
|
||||
name: testinfra
|
||||
options:
|
||||
sudo: true
|
||||
22
roles/user/molecule/default/tests/conftest.py
Normal file
22
roles/user/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
|
||||
)
|
||||
31
roles/user/molecule/default/tests/test_default.py
Normal file
31
roles/user/molecule/default/tests/test_default.py
Normal file
@@ -0,0 +1,31 @@
|
||||
"""Role testing files using testinfra."""
|
||||
|
||||
|
||||
def test_create_users(host):
|
||||
""" Validate user creation """
|
||||
user = host.user("user")
|
||||
assert user.exists
|
||||
assert user.uid >= 1000
|
||||
assert user.shell == "/bin/zsh"
|
||||
assert user.home == f"/home/{user.name}"
|
||||
|
||||
|
||||
admin = host.user("admin")
|
||||
assert admin.exists
|
||||
assert admin.uid < 1000
|
||||
assert admin.shell == "/bin/bash"
|
||||
assert admin.home == f"/home/{admin.name}"
|
||||
|
||||
def test_install_git_stow(host):
|
||||
pass
|
||||
|
||||
def test_clone_dotfiles(host):
|
||||
user = host.user("user")
|
||||
dotfiles = host.file(user.home + "/.dotfiles")
|
||||
assert dotfiles.exists
|
||||
assert dotfiles.user == user.name
|
||||
|
||||
admin = host.user("admin")
|
||||
dotfiles = host.file(admin.home + "/.dotfiles")
|
||||
assert dotfiles.exists
|
||||
assert dotfiles.user == admin.name
|
||||
Reference in New Issue
Block a user