Skip to content

Commit

Permalink
update algernon_version (#3)
Browse files Browse the repository at this point in the history
* update algernon_version
* rewrite installation and configuration
  • Loading branch information
bodsch authored Jun 16, 2022
1 parent c472877 commit df9ec36
Show file tree
Hide file tree
Showing 26 changed files with 478 additions and 241 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GH_REGISTRY_TOKEN }}
VALIDATE_ALL_CODEBASE: true
VALIDATE_ANSIBLE: true
VALIDATE_MARKDOWN: true
# VALIDATE_MARKDOWN: true
VALIDATE_YAML: true

arch:
Expand Down Expand Up @@ -170,4 +170,3 @@ jobs:
with:
galaxy_api_key: ${{ secrets.galaxy_api_key }}
git_branch: main

20 changes: 20 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#
export TOX_SCENARIO ?= default
export TOX_PYTHON ?= py310
export TOX_ANSIBLE ?= ansible510

.PHONY: converge destroy verify lint

default: converge

converge:
@hooks/converge

destroy:
@hooks/destroy

verify:
@hooks/verify

lint:
@hooks/lint
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,13 @@ Algernon is an stand-alone process to deliver markdown files.
### default configuration

```yaml
algernon_version: '1.12.12'
algernon_version: '1.13.0'

algernon_archive_name: "algernon-{{ algernon_version }}-linux.tar.xz"
algernon_direct_download: false

algernon_system_user: algernon
algernon_system_group: algernon

algernon_bin: /usr/local/bin/algernon

algernon_service_state: started

algernon_data_directory: /var/www/algernon
Expand Down
6 changes: 2 additions & 4 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
---

algernon_version: '1.12.14'
algernon_version: '1.13.0'

algernon_archive_name: "algernon-{{ algernon_version }}-linux.tar.xz"
algernon_direct_download: false

algernon_system_user: algernon
algernon_system_group: algernon

algernon_bin: /usr/local/bin/algernon

algernon_service_state: started

algernon_data_directory: /var/www/algernon
Expand Down
10 changes: 10 additions & 0 deletions hooks/converge
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

TOX_ARGS=

if [ -n "${TOX_SCENARIO}" ]
then
TOX_ARGS="--scenario-name ${TOX_SCENARIO}"
fi

tox -e ${TOX_PYTHON}-${TOX_ANSIBLE} -- molecule converge ${TOX_ARGS} # -- -v
10 changes: 10 additions & 0 deletions hooks/destroy
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

TOX_ARGS=

if [ -n "${TOX_SCENARIO}" ]
then
TOX_ARGS="--scenario-name ${TOX_SCENARIO}"
fi

tox -e ${TOX_PYTHON}-${TOX_ANSIBLE} -- molecule destroy ${TOX_ARGS}
10 changes: 10 additions & 0 deletions hooks/lint
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

TOX_ARGS=

if [ -n "${TOX_SCENARIO}" ]
then
TOX_ARGS="--scenario-name ${TOX_SCENARIO}"
fi

tox -e ${TOX_PYTHON}-${TOX_ANSIBLE} -- molecule lint ${TOX_ARGS}
10 changes: 10 additions & 0 deletions hooks/verify
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

TOX_ARGS=

if [ -n "${TOX_SCENARIO}" ]
then
TOX_ARGS="--scenario-name ${TOX_SCENARIO}"
fi

tox -e ${TOX_PYTHON}-${TOX_ANSIBLE} -- molecule verify ${TOX_ARGS}
71 changes: 59 additions & 12 deletions molecule/default/tests/test_default.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# coding: utf-8
from __future__ import unicode_literals

from ansible.parsing.dataloader import DataLoader
from ansible.template import Templar
Expand All @@ -8,8 +10,10 @@

import testinfra.utils.ansible_runner

HOST = 'instance'

testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts(HOST)


def pp_json(json_thing, sort=True, indents=2):
Expand All @@ -21,6 +25,7 @@ def pp_json(json_thing, sort=True, indents=2):


def base_directory():
""" ... """
cwd = os.getcwd()

if('group_vars' in os.listdir(cwd)):
Expand All @@ -33,34 +38,76 @@ def base_directory():
return directory, molecule_directory


def read_ansible_yaml(file_name, role_name):
ext_arr = ["yml", "yaml"]

read_file = None

for e in ext_arr:
test_file = "{}.{}".format(file_name, e)
if os.path.isfile(test_file):
read_file = test_file
break

return "file={} name={}".format(read_file, role_name)


@pytest.fixture()
def get_vars(host):
"""
parse ansible variables
- defaults/main.yml
- vars/main.yml
- vars/${DISTRIBUTION}.yaml
- molecule/${MOLECULE_SCENARIO_NAME}/group_vars/all/vars.yml
"""
base_dir, molecule_dir = base_directory()

file_defaults = "file={}/defaults/main.yml name=role_defaults".format(base_dir)
file_vars = "file={}/vars/main.yml name=role_vars".format(base_dir)
file_molecule = "file={}/group_vars/all/vars.yml name=test_vars".format(molecule_dir)

defaults_vars = host.ansible("include_vars", file_defaults).get("ansible_facts").get("role_defaults")
vars_vars = host.ansible("include_vars", file_vars).get("ansible_facts").get("role_vars")
molecule_vars = host.ansible("include_vars", file_molecule).get("ansible_facts").get("test_vars")
distribution = host.system_info.distribution

if distribution in ['debian', 'ubuntu']:
os = "debian"
elif distribution in ['redhat', 'ol', 'centos', 'rocky', 'almalinux']:
os = "redhat"
elif distribution in ['arch']:
os = "archlinux"

# print(" -> {} / {}".format(distribution, os))
# print(" -> {}".format(base_dir))

file_defaults = read_ansible_yaml("{}/defaults/main".format(base_dir), "role_defaults")
file_vars = read_ansible_yaml("{}/vars/main".format(base_dir), "role_vars")
file_distibution = read_ansible_yaml("{}/vars/{}".format(base_dir, os), "role_distibution")
file_molecule = read_ansible_yaml("{}/group_vars/all/vars".format(molecule_dir), "test_vars")
# file_host_molecule = read_ansible_yaml("{}/host_vars/{}/vars".format(base_dir, HOST), "host_vars")

defaults_vars = host.ansible("include_vars", file_defaults).get("ansible_facts").get("role_defaults")
vars_vars = host.ansible("include_vars", file_vars).get("ansible_facts").get("role_vars")
distibution_vars = host.ansible("include_vars", file_distibution).get("ansible_facts").get("role_distibution")
molecule_vars = host.ansible("include_vars", file_molecule).get("ansible_facts").get("test_vars")
# host_vars = host.ansible("include_vars", file_host_molecule).get("ansible_facts").get("host_vars")

ansible_vars = defaults_vars
ansible_vars.update(vars_vars)
ansible_vars.update(distibution_vars)
ansible_vars.update(molecule_vars)
# ansible_vars.update(host_vars)

templar = Templar(loader=DataLoader(), variables=ansible_vars)
result = templar.template(ansible_vars, fail_on_undefined=False)

return result


def local_facts(host):
"""
return local facts
"""
return host.ansible("setup").get("ansible_facts").get("ansible_local").get("algernon")


def test_files(host):
files = [
"/usr/local/bin/algernon"
"/usr/bin/algernon"
]
for file in files:
f = host.file(file)
Expand All @@ -72,7 +119,7 @@ def test_user(host):
assert host.group("algernon").exists
assert "algernon" in host.user("algernon").groups
assert host.user("algernon").shell == "/usr/sbin/nologin"
assert host.user("algernon").home == "/"
assert host.user("algernon").home == "/nonexistent"


def test_service(host):
Expand Down
71 changes: 59 additions & 12 deletions molecule/with-redis/tests/test_default.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# coding: utf-8
from __future__ import unicode_literals

from ansible.parsing.dataloader import DataLoader
from ansible.template import Templar
Expand All @@ -8,8 +10,10 @@

import testinfra.utils.ansible_runner

HOST = 'instance'

testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts(HOST)


def pp_json(json_thing, sort=True, indents=2):
Expand All @@ -21,6 +25,7 @@ def pp_json(json_thing, sort=True, indents=2):


def base_directory():
""" ... """
cwd = os.getcwd()

if('group_vars' in os.listdir(cwd)):
Expand All @@ -33,34 +38,76 @@ def base_directory():
return directory, molecule_directory


def read_ansible_yaml(file_name, role_name):
ext_arr = ["yml", "yaml"]

read_file = None

for e in ext_arr:
test_file = "{}.{}".format(file_name, e)
if os.path.isfile(test_file):
read_file = test_file
break

return "file={} name={}".format(read_file, role_name)


@pytest.fixture()
def get_vars(host):
"""
parse ansible variables
- defaults/main.yml
- vars/main.yml
- vars/${DISTRIBUTION}.yaml
- molecule/${MOLECULE_SCENARIO_NAME}/group_vars/all/vars.yml
"""
base_dir, molecule_dir = base_directory()

file_defaults = "file={}/defaults/main.yml name=role_defaults".format(base_dir)
file_vars = "file={}/vars/main.yml name=role_vars".format(base_dir)
file_molecule = "file={}/group_vars/all/vars.yml name=test_vars".format(molecule_dir)

defaults_vars = host.ansible("include_vars", file_defaults).get("ansible_facts").get("role_defaults")
vars_vars = host.ansible("include_vars", file_vars).get("ansible_facts").get("role_vars")
molecule_vars = host.ansible("include_vars", file_molecule).get("ansible_facts").get("test_vars")
distribution = host.system_info.distribution

if distribution in ['debian', 'ubuntu']:
os = "debian"
elif distribution in ['redhat', 'ol', 'centos', 'rocky', 'almalinux']:
os = "redhat"
elif distribution in ['arch']:
os = "archlinux"

# print(" -> {} / {}".format(distribution, os))
# print(" -> {}".format(base_dir))

file_defaults = read_ansible_yaml("{}/defaults/main".format(base_dir), "role_defaults")
file_vars = read_ansible_yaml("{}/vars/main".format(base_dir), "role_vars")
file_distibution = read_ansible_yaml("{}/vars/{}".format(base_dir, os), "role_distibution")
file_molecule = read_ansible_yaml("{}/group_vars/all/vars".format(molecule_dir), "test_vars")
# file_host_molecule = read_ansible_yaml("{}/host_vars/{}/vars".format(base_dir, HOST), "host_vars")

defaults_vars = host.ansible("include_vars", file_defaults).get("ansible_facts").get("role_defaults")
vars_vars = host.ansible("include_vars", file_vars).get("ansible_facts").get("role_vars")
distibution_vars = host.ansible("include_vars", file_distibution).get("ansible_facts").get("role_distibution")
molecule_vars = host.ansible("include_vars", file_molecule).get("ansible_facts").get("test_vars")
# host_vars = host.ansible("include_vars", file_host_molecule).get("ansible_facts").get("host_vars")

ansible_vars = defaults_vars
ansible_vars.update(vars_vars)
ansible_vars.update(distibution_vars)
ansible_vars.update(molecule_vars)
# ansible_vars.update(host_vars)

templar = Templar(loader=DataLoader(), variables=ansible_vars)
result = templar.template(ansible_vars, fail_on_undefined=False)

return result


def local_facts(host):
"""
return local facts
"""
return host.ansible("setup").get("ansible_facts").get("ansible_local").get("algernon")


def test_files(host):
files = [
"/usr/local/bin/algernon"
"/usr/bin/algernon"
]
for file in files:
f = host.file(file)
Expand All @@ -72,7 +119,7 @@ def test_user(host):
assert host.group("algernon").exists
assert "algernon" in host.user("algernon").groups
assert host.user("algernon").shell == "/usr/sbin/nologin"
assert host.user("algernon").home == "/"
assert host.user("algernon").home == "/nonexistent"


def test_service(host):
Expand Down
Loading

0 comments on commit df9ec36

Please sign in to comment.