This commit is contained in:
aynic.os
2021-07-14 23:58:24 +01:00
parent b6f1b8d798
commit da2f3ed44a
40 changed files with 166 additions and 108 deletions
+14 -1
View File
@@ -23,6 +23,13 @@ hosts_cloudinit_config:
hosts_cloudinit_enable: false
```
* `hosts_git_repositories` - Clone git repositories
``` yaml
hosts_git_repositories:
- { "repo": "https://github.com/aynicos/myos", "dest": "/dns/com/github/aynicos/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
@@ -99,7 +106,13 @@ hosts_ssh_public_hosts:
hosts_ssh_username: root
```
* `hosts_user_env` - List of environment variables added in ~/.env
* `hosts_update` - Update hosts every day
``` yaml
hosts_update: false
```
* `hosts_user_env` - List of environment variables to add in file ~/.myos
``` yaml
hosts_user_env:
+7 -1
View File
@@ -78,6 +78,9 @@ hosts_cloudinit_config:
# enable cloud-init
hosts_cloudinit_enable: false
# git repositories to clone
hosts_git_repositories: []
# packages to install/remove
hosts_packages: []
@@ -125,7 +128,10 @@ hosts_ssh_public_hosts: "{{ lookup('env','ANSIBLE_SSH_PUBLIC_HOSTS').split(' ')
# remote ssh user
hosts_ssh_username: "{{ lookup('env','ANSIBLE_SSH_USERNAME') or ansible_user }}"
# list of environment variables to write to user ~/.env
# update hosts every day
hosts_update: false
# list of environment variables to add in ~/.myos
hosts_user_env: []
# run specific functions on user login
-1
View File
@@ -1,6 +1,5 @@
# ~/.profile: executed by the command interpreter for login shells.
# set -x
umask 027
# source ~/.*aliases and ~/.*functions files
for source in aliases functions; do
-8
View File
@@ -1,8 +0,0 @@
alias DELETE='resty-delete'
alias GET='resty-get'
alias HEAD='resty-head'
alias OPTIONS='resty-options'
alias PATCH='resty-patch'
alias POST='resty-post'
alias PUT='resty-put'
alias TRACE='resty-trace'
-2
View File
@@ -1,2 +0,0 @@
gam () { "~/.gam/gam" "$@" ; }
gyb () { "~/.gyb/gyb" "$@" ; }
@@ -0,0 +1,2 @@
PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin
0 0 * * * root /etc/init.d/myos ansible-pull
+7 -8
View File
@@ -1,24 +1,23 @@
#!/bin/sh
#!/bin/bash
### 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
# Description: MYOS system call
### 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
[ -r /etc/default/myos ] && . /etc/default/myos || exit 1
type make >/dev/null 2>&1 && [ -d "${MYOS}" ] || exit 2
# load user config
[ -r ~/.myos ] && . ~/.myos
case "$1" in
*)
IFS=$'\n'; exec env $(cat ~/.env 2>/dev/null) make -C "${MYOS}" $@
IFS=$'\n'; exec sh -c "cd ${MYOS} && exec make $@ $(cat /etc/default/myos ~/.myos 2>/dev/null)"
esac
@@ -9,10 +9,10 @@ start() {
/etc/init.d/myos start
}
status() {
/etc/init.d/myos ps
}
stop() {
/etc/init.d/myos stop
}
status() {
/etc/init.d/myos status
}
@@ -1,8 +1,8 @@
# shellcheck shell=sh
# file rc.sh: Call user defined functions
## author: Yann "aya" Autissier
## license: MIT
## version: 20210620
## license: GPL
## version: 20210714
case $- in
# if this is an interactive shell
@@ -1,8 +1,8 @@
# shellcheck shell=sh
# file rc_functions.sh: Define shell functions
## author: Yann "aya" Autissier
## license: MIT
## version: 20210711
## license: GPL
## version: 20210714
# function force: Run a command sine die
force() {
@@ -0,0 +1,9 @@
[Unit]
Description=Call myos ansible-pull
[Service]
Type=oneshot
ExecStart=/etc/init.d/myos ansible-pull
[Install]
WantedBy=multi-user.target
@@ -0,0 +1,9 @@
[Unit]
Description=Call ansible
[Timer]
OnCalendar=*-*-* 00:00:00
Unit=ansible.service
[Install]
WantedBy=timers.target
+14
View File
@@ -0,0 +1,14 @@
---
# file: tasks/config.yml
- name: config - arch != x86 - do not run docker-compose in docker
when: ansible_machine|lower != "x86_64"
lineinfile: dest="/etc/default/myos" state="present" line="DOCKER=false"
become: yes
- name: config - set MYOS config in /etc/default/myos
with_items:
- MYOS={{ lookup('env','ANSIBLE_MYOS') }}
lineinfile: dest="/etc/default/myos" create="yes" line="{{ item }}" mode="0644"
become: yes
+9
View File
@@ -9,6 +9,13 @@
copy: src=../files/{{item}} dest={{item}} owner=root group=root mode=0644
become: yes
- name: files - copy myos cron file
when: hosts_update
with_items:
- /etc/cron.d/myos
copy: src=../files/{{item}} dest={{item}} owner=root group=root mode=0644
become: yes
- name: files - copy binary files
with_items:
- /etc/init.d/myos
@@ -19,6 +26,8 @@
- name: files - systemd - copy files
when: ansible_service_mgr|lower == "systemd"
with_items:
- /etc/systemd/system/ansible.service
- /etc/systemd/system/ansible.timer
- /etc/systemd/system/myos.service
- /etc/systemd/system/zram.service
copy: src=../files/{{item}} dest={{item}} owner=root group=root mode=0644
+14
View File
@@ -0,0 +1,14 @@
---
# file: tasks/git.yml
- name: git - clone repositories
with_items: "{{ hosts_git_repositories|default([]) }}"
git:
repo: "{{ item.repo }}"
dest: "{{ item.dest|default('/dns') }}"
umask: "022"
key_file: "{{ item.key_file|default('~/.ssh/id_rsa') }}"
version: "{{ item.version|default('HEAD') }}"
ignore_errors: true
become: yes
+6
View File
@@ -10,6 +10,9 @@
- import_tasks: cloudinit.yml
tags:
- cloudinit
- import_tasks: config.yml
tags:
- cloudinit
- import_tasks: dir.yml
tags:
- dir
@@ -25,6 +28,9 @@
- import_tasks: services.yml
tags:
- services
- import_tasks: git.yml
tags:
- git
- import_tasks: ssh.yml
tags:
- ssh
+2 -2
View File
@@ -2,7 +2,7 @@
# file: tasks/services.yml
- name: services - enable/disable hosts services
when: ansible_service_mgr|lower != "openrc"
when: hosts_services is defined and ansible_service_mgr|lower != "openrc"
with_items: "{{ hosts_services|default([]) }}"
service:
name: "{{item.name}}"
@@ -11,7 +11,7 @@
become: yes
- name: services - openrc - enable/disable hosts services
when: ansible_service_mgr|lower == "openrc"
when: hosts_services is defined and ansible_service_mgr|lower == "openrc"
with_items: "{{ hosts_services|default([]) }}"
service:
name: "{{item.name}}"
+4 -6
View File
@@ -11,10 +11,10 @@
copy: src="{{ item }}" dest=~/.ssh/ mode=0400
ignore_errors: true
- name: user - create ~/.env
- name: user - create ~/.myos
template:
src: env.j2
dest: ~/.env
src: myos.j2
dest: ~/.myos
force: no
mode: 0400
@@ -32,13 +32,11 @@
with_items: "{{ hosts_user_rc_functions|default([]) }}"
file: path="~/.rc.d/{{item.path}}" state="{{item.state}}"
- name: user - copy ~/.*aliases ~/.*functions ~/.*profile ~/.shrc
- name: user - copy ~/.*aliases ~/.*profile ~/.shrc
with_items:
- ".dircolors_aliases"
- ".docker_aliases"
- ".resty_aliases"
- ".vim_aliases"
- ".sh_functions"
- ".bash_profile"
- ".profile"
- ".shrc"
+1 -1
View File
@@ -1,6 +1,6 @@
CMDS := exec
SERVICE ?= cli
-include .env
-include .myos
ansible:
@make -C $(ANSIBLE_GIT_DIRECTORY) ansible-run-localhost
@@ -1,3 +1,4 @@
MYOS={{ lookup('env','ANSIBLE_MYOS') }}
{% for var in hosts_user_env|default([]) %}
{{var}}={{ lookup('env',var) }}
{% endfor %}