Feat: init refact with test
This commit is contained in:
33
roles/dotfiles/.yamllint
Normal file
33
roles/dotfiles/.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
|
||||
7
roles/dotfiles/defaults/main.yml
Normal file
7
roles/dotfiles/defaults/main.yml
Normal file
@@ -0,0 +1,7 @@
|
||||
---
|
||||
user:
|
||||
username: 'vagrant'
|
||||
|
||||
dotusers: ["{{ user }}"]
|
||||
|
||||
config2stow: ["nvim", "tmux", "zsh"]
|
||||
33
roles/dotfiles/molecule/.yamllint
Normal file
33
roles/dotfiles/molecule/.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
|
||||
23
roles/dotfiles/molecule/default/INSTALL.rst
Normal file
23
roles/dotfiles/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'
|
||||
7
roles/dotfiles/molecule/default/converge.yml
Normal file
7
roles/dotfiles/molecule/default/converge.yml
Normal file
@@ -0,0 +1,7 @@
|
||||
---
|
||||
- name: Converge
|
||||
hosts: all
|
||||
tasks:
|
||||
- name: "Include dotfiles"
|
||||
include_role:
|
||||
name: "dotfiles"
|
||||
14
roles/dotfiles/molecule/default/molecule.yml
Normal file
14
roles/dotfiles/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.
Binary file not shown.
Binary file not shown.
22
roles/dotfiles/molecule/default/tests/conftest.py
Normal file
22
roles/dotfiles/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
|
||||
)
|
||||
23
roles/dotfiles/molecule/default/tests/test_default.py
Normal file
23
roles/dotfiles/molecule/default/tests/test_default.py
Normal file
@@ -0,0 +1,23 @@
|
||||
"""Role testing files using testinfra."""
|
||||
|
||||
|
||||
def test_stow_installed(host):
|
||||
stow = host.package("stow")
|
||||
assert stow.is_installed
|
||||
|
||||
def test_dotfile_cloned(host):
|
||||
homepath = host.run("pwd").stdout[:-1]
|
||||
dotfiles = host.file(homepath + "/.dotfiles")
|
||||
assert dotfiles.exists
|
||||
|
||||
def test_dotfile_stowed(host):
|
||||
homepath = host.run("pwd").stdout[:-1]
|
||||
nvim = host.file(homepath + "/.config/nvim/")
|
||||
assert nvim.exists
|
||||
tmux = host.file(homepath + "/.tmux/")
|
||||
assert tmux.exists
|
||||
zshenv = host.file(homepath + "/.zshenv")
|
||||
assert zshenv.exists
|
||||
zsh = host.file(homepath + "/.config/zsh/")
|
||||
assert zsh.exists
|
||||
|
||||
14
roles/dotfiles/tasks/arch.yml
Normal file
14
roles/dotfiles/tasks/arch.yml
Normal file
@@ -0,0 +1,14 @@
|
||||
---
|
||||
- name: Install stow
|
||||
community.general.pacman:
|
||||
name: stow
|
||||
state: present
|
||||
update_cache: yes
|
||||
become: true
|
||||
|
||||
- name: Install git
|
||||
community.general.pacman:
|
||||
name: git
|
||||
state: present
|
||||
update_cache: yes
|
||||
become: true
|
||||
14
roles/dotfiles/tasks/debian.yml
Normal file
14
roles/dotfiles/tasks/debian.yml
Normal file
@@ -0,0 +1,14 @@
|
||||
---
|
||||
- name: Install stow
|
||||
apt:
|
||||
name: stow
|
||||
state: present
|
||||
update_cache: yes
|
||||
become: true
|
||||
|
||||
- name: Install git
|
||||
apt:
|
||||
name: git
|
||||
state: present
|
||||
update_cache: yes
|
||||
become: true
|
||||
20
roles/dotfiles/tasks/main.yml
Normal file
20
roles/dotfiles/tasks/main.yml
Normal file
@@ -0,0 +1,20 @@
|
||||
---
|
||||
- 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: 'https://git.opytex.org/lafrite/dotfiles.git'
|
||||
dest: /home/{{ item.username }}/.dotfiles
|
||||
with_items: "{{ dotusers }}"
|
||||
|
||||
- name: stow configs
|
||||
ansible.builtin.command:
|
||||
cmd: stow {{ item }}
|
||||
chdir: ~/.dotfiles/
|
||||
with_items: "{{ config2stow }}"
|
||||
Reference in New Issue
Block a user