diff --git a/.github/workflows/pylint.yml b/.github/workflows/pylint.yml new file mode 100644 index 0000000..876c6ad --- /dev/null +++ b/.github/workflows/pylint.yml @@ -0,0 +1,15 @@ +--- +name: 'Pylint GitHub Actions' + +# yamllint disable-line rule:truthy +on: [push, pull_request] + +jobs: + pylint: + name: 'Pylint' + runs-on: ubuntu-latest + steps: + - name: 'Checkout' + uses: actions/checkout@master + - name: GitHub Action for pylint + uses: cclauss/GitHub-Action-for-pylint@0.7.0 diff --git a/.github/workflows/yamllint.yaml b/.github/workflows/yamllint.yaml index 39c49f8..c4894bd 100644 --- a/.github/workflows/yamllint.yaml +++ b/.github/workflows/yamllint.yaml @@ -18,5 +18,3 @@ jobs: yamllint_config_filepath: './.yamllint' yamllint_strict: false yamllint_comment: true -# env: -# GITHUB_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN } diff --git a/README.md b/README.md index 90b1e27..f174d10 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,20 @@ Ansible Linux Desktop Setup ========================== -This ansible playbook collection creates [L3D](https://chaos.social/@l3d)s Desktop enviroment. Including window manager and some pre-installed programms like [Firefox](https://www.mozilla.org/de/firefox/new/) and some usefull shell programms. +This ansible playbook collection manages some of my workstations and laptops. Because of this it sometimes contains very specific variables like my username, SSH keys or similar data that may not be the best choice for your system. - ATTENTION +Nevertheless, this ansible playbook is not only publicly available on the internet, but by the MIT license a part of free open-source ansible, which may serve you as inspiration within the framework of the MIT license. + + + Inventory ------------- -Different to my other ansible playbooks: +This is my first ansible with dynamic inventory. The [inventory.py](inventory.py) script looks at which hostname it was lauched on. If the hostname is known, the host is mapped to the group stored for it and a local connection to the host is established. -### THIS PLAYBOOK HAS TO BE EXECUTET AT THE TARGET HOST DIRECTLY! +This has the advantage that different environments are automatically recognized and significantly less danger of accidentally rolling out the ansible with the variables for a completely different host and thus configuring things that were not intended for this device. -*It requires some GUI stuff and I did not find the time to forward X or wayland correctly to make it remotely working. Sorry. Feel free to create a Issue or pull-request* +Obviously, this also means that **this playbook must always be run on the host you want to manage** and this ansible playbook is not meant to be run remotely. - Install tipps: + +Install tipps: ----------------------- ```bash # Clone Git diff --git a/ansible.cfg b/ansible.cfg index 0578235..51c1513 100644 --- a/ansible.cfg +++ b/ansible.cfg @@ -1,5 +1,5 @@ [defaults] -inventory = ./hosts.ini +inventory = ./inventory.py retry_files_enabled = False nocows = True ansible_connection = 'local' diff --git a/inventory.py b/inventory.py new file mode 100755 index 0000000..d119343 --- /dev/null +++ b/inventory.py @@ -0,0 +1,73 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Create a dynamic inventory for this ansible playbook +""" +import socket +import sys +import json + +# create a dict to match hostnames to enviroments +env_dict = { + 'work': + ['workstation.local'], + 'private': + ['derpy.local', 'foo.bar'] +} + +def fqdn(): + """ + return fully qualified domain name + """ + return socket.getfqdn() + +def env(domain): + """ + map a hostname to a space + or print empty list if no one matched and exit + """ + for key, values in env_dict.items(): + if domain in values: + return key + print(json.dumps(empty_host_list(), sort_keys=True, indent=2)) + sys.exit() + +def empty_host_list(): + """ + return empty host list + """ + comment = "No valid host found. returning empty host list!" + return json.loads('{"_meta": {"comment": "' + comment + + '", "hostvars": {}}, "instances": {"hosts": []}}') + +def formated_host_group_list(host, group): + """ + build inventory and return it + """ + # pylint: disable=line-too-long + return json.loads('{"_meta": {"hostvars": {}},"' + str(group) + '": {"hosts": ["' + str(host) + '"]},"instances": {"children": ["' + str(group) + '"]}}') + +def main(): + """ + main funktion + will analyse on which host this script is started + and will print the dynamic inventory to tell ansible + which host_vars and group_vars should be used + """ + host = fqdn() + group = env(host) + print(json.dumps(formated_host_group_list(host, group), sort_keys=True, indent=2)) + + + +#{ +# "_meta": { +# "hostvars": { } +# }, +# +# "instances": { +# "hosts": ["10.66.70.33"] +# } +# } + +main() diff --git a/setup_desk_minni.yml b/setup_desk_minni.yml index 3a573a0..dec07ef 100644 --- a/setup_desk_minni.yml +++ b/setup_desk_minni.yml @@ -21,7 +21,7 @@ hosts: desk_minni.local roles: - {role: akku-warning, tags: akku} - # - {role: pulseaudio, tags: [pulse, audio, pulseaudio]} + # - {role: pulseaudio, tags: [pulse, audio, pulseaudio]} - {role: networkmanager, tags: networkmanager, when: ansible_os_family == 'Archlinux'} - {role: openvpn, tags: ovpn} - {role: nextcloud, tags: nextcloud, when: ansible_os_family == 'Archlinux'} @@ -32,7 +32,7 @@ - {role: ntp, tags: ntp} - {role: xrandr, tags: xrandr} - {role: arch-fonts, tags: fonts} - # - {role: winehq, tags: wine} + # - {role: winehq, tags: wine} - {role: no-sleep, tags: sleep} - {role: do1jlr.avahi_daemon, tags: [avahi_daemon, avahi]} - {role: do1jlr.avahi_client, tags: [avahi_client, mdns]} diff --git a/setup_l14.yml b/setup_l14.yml index e87c712..3fc3975 100644 --- a/setup_l14.yml +++ b/setup_l14.yml @@ -22,7 +22,7 @@ hosts: l14.local roles: - {role: akku-warning, tags: akku} -# - {role: pulseaudio, tags: [pulse, audio, pulseaudio]} + # - {role: pulseaudio, tags: [pulse, audio, pulseaudio]} - {role: networkmanager, tags: networkmanager, when: ansible_os_family == 'Archlinux'} - {role: openvpn, tags: ovpn} - {role: nextcloud, tags: nextcloud, when: ansible_os_family == 'Archlinux'} @@ -33,7 +33,7 @@ - {role: ntp, tags: ntp} - {role: xrandr, tags: xrandr} - {role: arch-fonts, tags: fonts} -# - {role: winehq, tags: wine} + # - {role: winehq, tags: wine} - {role: no-sleep, tags: sleep} - {role: do1jlr.avahi_daemon, tags: [avahi_daemon, avahi]} - {role: do1jlr.avahi_client, tags: [avahi_client, mdns]} diff --git a/setup_t460p.yml b/setup_t460p.yml index 6bf5acf..00f38a8 100644 --- a/setup_t460p.yml +++ b/setup_t460p.yml @@ -21,7 +21,7 @@ hosts: t460p.local roles: - {role: akku-warning, tags: akku} -# - {role: pulseaudio, tags: [pulse, audio, pulseaudio]} + # - {role: pulseaudio, tags: [pulse, audio, pulseaudio]} - {role: networkmanager, tags: networkmanager, when: ansible_os_family == 'Archlinux'} - {role: openvpn, tags: ovpn} - {role: nextcloud, tags: nextcloud, when: ansible_os_family == 'Archlinux'}