From b6f1b8d7984ff2a67a4dab7b6759b83b2cd76f90 Mon Sep 17 00:00:00 2001 From: "aynic.os" Date: Wed, 14 Jul 2021 23:03:00 +0100 Subject: [PATCH] myos --- CHANGELOG.md | 6 ++++-- ansible/inventories/host_vars/default | 3 ++- ansible/inventories/host_vars/localhost | 3 ++- ansible/inventories/host_vars/myos | 3 +++ ansible/roles/hosts/README.md | 7 ------- ansible/roles/hosts/defaults/main.yml | 3 --- ansible/roles/hosts/files/etc/init.d/myos | 24 ++++++++++++++++++++++ ansible/roles/hosts/files/etc/init.d/myos-openrc | 18 ++++++++++++++++ .../hosts/files/etc/systemd/system/myos.service | 11 ++++++++++ ansible/roles/hosts/tasks/files.yml | 11 +++------- ansible/roles/hosts/tasks/main.yml | 3 --- ansible/roles/hosts/templates/Makefile.j2 | 6 +++--- ansible/roles/hosts/templates/env.j2 | 1 - ansible/roles/remotes/README.md | 9 ++++++++ ansible/roles/remotes/defaults/main.yml | 3 +++ ansible/roles/remotes/tasks/files.yml | 10 +++++++++ ansible/roles/{hosts => remotes}/tasks/git.yml | 2 +- ansible/roles/remotes/tasks/main.yml | 6 ++++++ 18 files changed, 99 insertions(+), 30 deletions(-) create mode 100755 ansible/roles/hosts/files/etc/init.d/myos create mode 100755 ansible/roles/hosts/files/etc/init.d/myos-openrc create mode 100644 ansible/roles/hosts/files/etc/systemd/system/myos.service create mode 100644 ansible/roles/remotes/tasks/files.yml rename ansible/roles/{hosts => remotes}/tasks/git.yml (83%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2fb4f18..db94be6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # CHANGELOG -## v1.0-alpha +## v1.0-alpha - 2021-07-14 -First public release. Code is doc. +First public release, code is doc + +* Licenses update to GPL, as freedom should not allow evil to move faster than god diff --git a/ansible/inventories/host_vars/default b/ansible/inventories/host_vars/default index f43b8e2..4ae18f6 100644 --- a/ansible/inventories/host_vars/default +++ b/ansible/inventories/host_vars/default @@ -8,7 +8,7 @@ aws_secret_access_key: "{{ lookup('env','ANSIBLE_AWS_SECRET_ACCESS_KEY') }}" disks_packages: - { "name": "e2fsprogs-extra", "state": "present" } - { "name": "nfs-utils", "state": "present" } -hosts_git_repositories: +git_repositories: - { "repo": "{{ lookup('env','ANSIBLE_GIT_REPOSITORY') }}", "dest": "{{ lookup('env','ANSIBLE_GIT_DIRECTORY') }}", "key_file": "{{ lookup('env','ANSIBLE_GIT_KEY_FILE') or '~/.ssh/id_rsa' }}", "version": "{{ lookup('env','ANSIBLE_GIT_VERSION') }}" } hosts_packages: - { "name": "ansible", "state": "present" } @@ -31,6 +31,7 @@ hosts_user_env: - ANSIBLE_INVENTORY - ANSIBLE_PLAYBOOK - ENV +- MYOS hosts_user_rc_enable: true hosts_user_rc_functions: - { "path": "10_prompt_set", "state": "touch" } diff --git a/ansible/inventories/host_vars/localhost b/ansible/inventories/host_vars/localhost index 2030fa3..e959cea 100644 --- a/ansible/inventories/host_vars/localhost +++ b/ansible/inventories/host_vars/localhost @@ -6,7 +6,7 @@ disks_packages: - { "name": "xfsprogs", "state": "present" } docker_image_tag: "{{ lookup('env','ANSIBLE_DOCKER_IMAGE_TAG') or 'latest' }}" docker_registry: "{{ lookup('env','ANSIBLE_DOCKER_REGISTRY') }}" -hosts_git_repositories: +git_repositories: - { "repo": "{{ lookup('env','ANSIBLE_GIT_REPOSITORY') }}", "dest": "{{ lookup('env','ANSIBLE_GIT_DIRECTORY') }}", "key_file": "{{ lookup('env','ANSIBLE_GIT_KEY_FILE') or '~/.ssh/id_rsa' }}", "version": "{{ lookup('env','ANSIBLE_GIT_VERSION') }}" } hosts_packages: - { "name": "ansible", "state": "present" } @@ -24,4 +24,5 @@ hosts_user_env: - ANSIBLE_INVENTORY - ANSIBLE_PLAYBOOK - ENV +- MYOS hosts_user_rc_enable: true diff --git a/ansible/inventories/host_vars/myos b/ansible/inventories/host_vars/myos index 9227b57..57b4ac9 100644 --- a/ansible/inventories/host_vars/myos +++ b/ansible/inventories/host_vars/myos @@ -40,7 +40,10 @@ hosts_user_env: - ANSIBLE_GIT_REPOSITORY - ANSIBLE_INVENTORY - ANSIBLE_PLAYBOOK +- COMPOSE_PROJECT_NAME - ENV +- MYOS +- MYOS_TAGS hosts_user_rc_enable: true hosts_user_rc_functions: - { "path": "10_prompt_set", "state": "touch" } diff --git a/ansible/roles/hosts/README.md b/ansible/roles/hosts/README.md index 4bef5cf..711e6b2 100644 --- a/ansible/roles/hosts/README.md +++ b/ansible/roles/hosts/README.md @@ -23,13 +23,6 @@ hosts_cloudinit_config: hosts_cloudinit_enable: false ``` -* `hosts_git_repositories` - Clone git repositories - -``` yaml -hosts_git_repositories: -- { "repo": "https://github.com/aya/myos", "dest": "/src/com/github/aya/myos", "key_file": "~/.ssh/id_rsa", "version": "master" } -``` - * `hosts_packages` - List of packages to install/remove on your hosts, should be overrided for a specific distro ``` yaml diff --git a/ansible/roles/hosts/defaults/main.yml b/ansible/roles/hosts/defaults/main.yml index 819b89a..63c9786 100644 --- a/ansible/roles/hosts/defaults/main.yml +++ b/ansible/roles/hosts/defaults/main.yml @@ -78,9 +78,6 @@ hosts_cloudinit_config: # enable cloud-init hosts_cloudinit_enable: false -# git repositories to clone -hosts_git_repositories: [] - # packages to install/remove hosts_packages: [] diff --git a/ansible/roles/hosts/files/etc/init.d/myos b/ansible/roles/hosts/files/etc/init.d/myos new file mode 100755 index 0000000..dae2f70 --- /dev/null +++ b/ansible/roles/hosts/files/etc/init.d/myos @@ -0,0 +1,24 @@ +#!/bin/sh +### BEGIN INIT INFO +# Provides: myos +# Required-Start: +# Required-Stop: +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Description: System calls from https://github.com/aynicos/myos +### END INIT INFO + +set -e + +# load system configs +[ -r /etc/default/myos ] && . /etc/default/myos +[ -r /etc/sysconfig/myos ] && . /etc/sysconfig/myos + +# check system config +[ -r ~/.env ] && . ~/.env || exit 1 +type make >/dev/null 2>&1 && [ -d "${MYOS}" ] || exit 2 + +case "$1" in + *) + IFS=$'\n'; exec env $(cat ~/.env 2>/dev/null) make -C "${MYOS}" $@ +esac diff --git a/ansible/roles/hosts/files/etc/init.d/myos-openrc b/ansible/roles/hosts/files/etc/init.d/myos-openrc new file mode 100755 index 0000000..b3f7776 --- /dev/null +++ b/ansible/roles/hosts/files/etc/init.d/myos-openrc @@ -0,0 +1,18 @@ +#!/sbin/openrc-run + +depend() { + need localmount swap + after bootmisc modules +} + +start() { + /etc/init.d/myos start +} + +stop() { + /etc/init.d/myos stop +} + +status() { + /etc/init.d/myos status +} diff --git a/ansible/roles/hosts/files/etc/systemd/system/myos.service b/ansible/roles/hosts/files/etc/systemd/system/myos.service new file mode 100644 index 0000000..9a9c668 --- /dev/null +++ b/ansible/roles/hosts/files/etc/systemd/system/myos.service @@ -0,0 +1,11 @@ +[Unit] +Description=System calls from https://github.com/aynicos/myos + +[Service] +Type=oneshot +RemainAfterExit=yes +ExecStart=/etc/init.d/myos start +ExecStop=/etc/init.d/myos stop + +[Install] +WantedBy=sysinit.target diff --git a/ansible/roles/hosts/tasks/files.yml b/ansible/roles/hosts/tasks/files.yml index 159015d..3742b8f 100644 --- a/ansible/roles/hosts/tasks/files.yml +++ b/ansible/roles/hosts/tasks/files.yml @@ -11,6 +11,7 @@ - name: files - copy binary files with_items: + - /etc/init.d/myos - /etc/init.d/zram copy: src=../files/{{item}} dest={{item}} owner=root group=root mode=0755 become: yes @@ -18,6 +19,7 @@ - name: files - systemd - copy files when: ansible_service_mgr|lower == "systemd" with_items: + - /etc/systemd/system/myos.service - /etc/systemd/system/zram.service copy: src=../files/{{item}} dest={{item}} owner=root group=root mode=0644 become: yes @@ -25,15 +27,8 @@ - name: files - openrc - copy files when: ansible_service_mgr|lower == "openrc" with_items: + - /etc/init.d/myos-openrc - /etc/init.d/zram-openrc - - /etc/local.d/ansible.start copy: src=../files/{{item}} dest={{item}} owner=root group=root mode=0755 become: yes -- name: files - get remote binary files - with_items: - - https://raw.githubusercontent.com/dylanaraps/pfetch/master/pfetch - get_url: url={{item}} dest=/usr/local/bin owner=root group=root mode=0755 - ignore_errors: true - become: yes - diff --git a/ansible/roles/hosts/tasks/main.yml b/ansible/roles/hosts/tasks/main.yml index 9195e65..aa7ccc8 100644 --- a/ansible/roles/hosts/tasks/main.yml +++ b/ansible/roles/hosts/tasks/main.yml @@ -16,9 +16,6 @@ - import_tasks: files.yml tags: - files -- import_tasks: git.yml - tags: - - git - import_tasks: groups.yml tags: - groups diff --git a/ansible/roles/hosts/templates/Makefile.j2 b/ansible/roles/hosts/templates/Makefile.j2 index 2ceb8ad..bee34ef 100644 --- a/ansible/roles/hosts/templates/Makefile.j2 +++ b/ansible/roles/hosts/templates/Makefile.j2 @@ -3,13 +3,13 @@ SERVICE ?= cli -include .env ansible: - @make -C $(ANSIBLE_GIT_DIRECTORY) ansible-run-localhost $(foreach var,$(ENV_USER_VARS),$(if $($(var)),$(var)='$($(var))')) + @make -C $(ANSIBLE_GIT_DIRECTORY) ansible-run-localhost ansible-%: - @make -C $(ANSIBLE_GIT_DIRECTORY) ansible-run-localhost $(foreach var,$(ENV_USER_VARS),$(if $($(var)),$(var)='$($(var))')) ANSIBLE_TAGS=$* + @make -C $(ANSIBLE_GIT_DIRECTORY) ansible-run-localhost ANSIBLE_TAGS=$* ansible-pull: - @$(foreach var,$(ENV_USER_VARS),$(if $($(var)),$(var)='$($(var))')) $(if $(ANSIBLE_CONFIG),ANSIBLE_CONFIG=$(ANSIBLE_GIT_DIRECTORY)/$(ANSIBLE_CONFIG)) ansible-pull --url $(ANSIBLE_GIT_REPOSITORY) $(if $(ANSIBLE_GIT_KEY_FILE),--key-file $(ANSIBLE_GIT_KEY_FILE)) $(if $(ANSIBLE_GIT_VERSION),--checkout $(ANSIBLE_GIT_VERSION)) $(if $(ANSIBLE_GIT_DIRECTORY),--directory $(ANSIBLE_GIT_DIRECTORY)) $(if $(ANSIBLE_TAGS),--tags $(ANSIBLE_TAGS)) $(if $(ANSIBLE_EXTRA_VARS),--extra-vars '$(ANSIBLE_EXTRA_VARS)') $(if $(findstring true,$(FORCE)),--force) $(if $(findstring true,$(DRYRUN)),--check) --full $(if $(ANSIBLE_INVENTORY),--inventory $(ANSIBLE_INVENTORY)) $(ANSIBLE_VERBOSE) $(ANSIBLE_PLAYBOOK) + @$(if $(ANSIBLE_CONFIG),ANSIBLE_CONFIG=$(ANSIBLE_GIT_DIRECTORY)/$(ANSIBLE_CONFIG)) ansible-pull --url $(ANSIBLE_GIT_REPOSITORY) $(if $(ANSIBLE_GIT_KEY_FILE),--key-file $(ANSIBLE_GIT_KEY_FILE)) $(if $(ANSIBLE_GIT_VERSION),--checkout $(ANSIBLE_GIT_VERSION)) $(if $(ANSIBLE_GIT_DIRECTORY),--directory $(ANSIBLE_GIT_DIRECTORY)) $(if $(ANSIBLE_TAGS),--tags $(ANSIBLE_TAGS)) $(if $(ANSIBLE_EXTRA_VARS),--extra-vars '$(ANSIBLE_EXTRA_VARS)') $(if $(findstring true,$(FORCE)),--force) $(if $(findstring true,$(DRYRUN)),--check) --full $(if $(ANSIBLE_INVENTORY),--inventory $(ANSIBLE_INVENTORY)) $(ANSIBLE_VERBOSE) $(ANSIBLE_PLAYBOOK) exec: @make -C $(ANSIBLE_GIT_DIRECTORY) exec ARGS='$(ARGS)' DOCKER_NAME=$(COMPOSE_PROJECT_NAME)_$(SERVICE) ENV=$(ENV) DOCKER_RUN_WORKDIR= diff --git a/ansible/roles/hosts/templates/env.j2 b/ansible/roles/hosts/templates/env.j2 index f24b6e0..1f461ff 100644 --- a/ansible/roles/hosts/templates/env.j2 +++ b/ansible/roles/hosts/templates/env.j2 @@ -1,4 +1,3 @@ {% for var in hosts_user_env|default([]) %} {{var}}={{ lookup('env',var) }} {% endfor %} -ENV_USER_VARS={{hosts_user_env |default([]) |join(' ')}} diff --git a/ansible/roles/remotes/README.md b/ansible/roles/remotes/README.md index e5f6337..45f4980 100644 --- a/ansible/roles/remotes/README.md +++ b/ansible/roles/remotes/README.md @@ -66,6 +66,15 @@ aws_secret_access_key: 'YOUR_SECRET_ACCESS_KEY' aws_user: 'root' ``` +### Git variables + +* `git_repositories` - Clone git repositories + +``` yaml +git_repositories: +- { "repo": "https://github.com/aynicos/myos", "dest": "/dns/com/github/aynicos/myos", "key_file": "~/.ssh/id_rsa", "version": "master" } +``` + ## Example playbook ``` yaml diff --git a/ansible/roles/remotes/defaults/main.yml b/ansible/roles/remotes/defaults/main.yml index 27ce62d..3405be5 100644 --- a/ansible/roles/remotes/defaults/main.yml +++ b/ansible/roles/remotes/defaults/main.yml @@ -19,6 +19,9 @@ aws_user: "{{ ansible_user|default('root') }}" # aws_secret_access_key to add in ~/.aws/credentials aws_secret_access_key: 'YOUR_SECRET_ACCESS_KEY' +# git repositories to clone +git_repositories: [] + # packages to install/remove remotes_packages: [] diff --git a/ansible/roles/remotes/tasks/files.yml b/ansible/roles/remotes/tasks/files.yml new file mode 100644 index 0000000..8a54b2b --- /dev/null +++ b/ansible/roles/remotes/tasks/files.yml @@ -0,0 +1,10 @@ +--- +# file: tasks/files.yml + +- name: files - get remote binary files + with_items: + - https://raw.githubusercontent.com/dylanaraps/pfetch/master/pfetch + get_url: url={{item}} dest=/usr/local/bin owner=root group=root mode=0755 + ignore_errors: true + become: yes + diff --git a/ansible/roles/hosts/tasks/git.yml b/ansible/roles/remotes/tasks/git.yml similarity index 83% rename from ansible/roles/hosts/tasks/git.yml rename to ansible/roles/remotes/tasks/git.yml index fa7a78f..ff0975a 100644 --- a/ansible/roles/hosts/tasks/git.yml +++ b/ansible/roles/remotes/tasks/git.yml @@ -2,7 +2,7 @@ # file: tasks/git.yml - name: git - clone repositories - with_items: "{{ hosts_git_repositories|default([]) }}" + with_items: "{{ git_repositories|default([]) }}" git: repo: "{{ item.repo }}" dest: "{{ item.dest|default('/src') }}" diff --git a/ansible/roles/remotes/tasks/main.yml b/ansible/roles/remotes/tasks/main.yml index 0b714b3..a180840 100644 --- a/ansible/roles/remotes/tasks/main.yml +++ b/ansible/roles/remotes/tasks/main.yml @@ -4,9 +4,15 @@ - import_tasks: vars.yml tags: - vars +- import_tasks: files.yml + tags: + - files - import_tasks: packages.yml tags: - packages +- import_tasks: git.yml + tags: + - git - import_tasks: pips.yml tags: - pips