Refactor server roles into one that handles all OS physical or virtual
This commit is contained in:
@@ -1,31 +0,0 @@
|
||||
---
|
||||
# Copy profiles to /etc/profile.d/
|
||||
- include_tasks: ../../../functions/copy_etc-profile.d.yml
|
||||
|
||||
# Copy scripts to /usr/local/bin
|
||||
- include_tasks: ../../../functions/copy_usr-local-bin.yml
|
||||
|
||||
# Rsync /etc/vim
|
||||
- name: Synchronizing /etc/vim
|
||||
synchronize:
|
||||
src: files/vim/vim
|
||||
dest: /etc/
|
||||
delete: yes
|
||||
group: no
|
||||
owner: no
|
||||
rsync_opts:
|
||||
- "--exclude=.git"
|
||||
|
||||
- name: Sed /etc/vim/vimrc
|
||||
replace:
|
||||
path: /etc/vim/vimrc
|
||||
regexp: '~/.vim/plugged'
|
||||
replace: '/etc/vim/plugged'
|
||||
|
||||
- name: Symlink /usr/share/vim/vimfiles
|
||||
file:
|
||||
src: /etc/vim
|
||||
dest: /usr/share/vim/vimfiles
|
||||
owner: root
|
||||
group: root
|
||||
state: link
|
||||
@@ -1,4 +0,0 @@
|
||||
---
|
||||
# Install and Configure Debian
|
||||
- include_tasks: install.yml
|
||||
- include_tasks: configure.yml
|
||||
31
server/files/bin/purgefiles.py
Normal file
31
server/files/bin/purgefiles.py
Normal file
@@ -0,0 +1,31 @@
|
||||
"""Clean old files"""
|
||||
|
||||
__author__ = "Matthew Reschke <mail@mreschke.com>"
|
||||
__license__ = "MIT"
|
||||
|
||||
import os
|
||||
import sys
|
||||
import subprocess
|
||||
|
||||
|
||||
# Usage
|
||||
# Create another file, example /usr/local/bin/clean-system.py
|
||||
# from purgefiles import purge
|
||||
# purge('/store/logs', 540)
|
||||
|
||||
|
||||
def purge(path, older_than_days, file_filter='*', max_depth=999, include_folders=False):
|
||||
del_cmd = 'rm -rfv'
|
||||
typestr = '-type f'
|
||||
if include_folders: typestr = ''
|
||||
#_cmd('find ' + path + ' -maxdepth ' + str(max_depth) + ' -iname "' + file_filter + '" ' + typestr + ' -mtime +' + str(older_than_days) + ' -exec ' + del_cmd + ' {} \; | tee -a ' + log)
|
||||
_cmd('find ' + path + ' -maxdepth ' + str(max_depth) + ' -iname "' + file_filter + '" ' + typestr + ' -mtime +' + str(older_than_days) + ' -exec ' + del_cmd + ' {} \;')
|
||||
|
||||
def _cmd(run, capture_output=False):
|
||||
# Run the cmd
|
||||
if capture_output:
|
||||
proc = subprocess.Popen(run, universal_newlines=True, executable='bash', shell=True, stdout=subprocess.PIPE).stdout
|
||||
return proc.read().strip()
|
||||
else:
|
||||
run = "bash -c '" + run + "'"
|
||||
os.system(run)
|
||||
97
server/files/profile.d/bash_prompt.sh
Normal file
97
server/files/profile.d/bash_prompt.sh
Normal file
@@ -0,0 +1,97 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Custom prompt
|
||||
# mReschke 2019-04-10
|
||||
|
||||
# At first these colors did not contain the \[ and \] which caused bash prompt mess up on long lines as it was miscounting the length of the line. See https://unix.stackexchange.com/questions/389008/bash-messed-up-display-for-long-lines
|
||||
DEFAULT="\[\033[0;0m\]"
|
||||
BLUE="\[\033[0;34m\]"
|
||||
GREEN="\[\033[0;32m\]"
|
||||
CYAN="\[\033[0;36m\]"
|
||||
RED="\[\033[0;31m\]"
|
||||
PURPLE="\[\033[0;35m\]"
|
||||
BROWN="\[\033[0;33m\]"
|
||||
GRAY="\[\033[0;37m\]"
|
||||
|
||||
DARKGRAY="\[\033[1;30m\]"
|
||||
LIGHTBLUE="\[\033[1;34m\]"
|
||||
LIGHTGREEN="\[\033[1;32m\]"
|
||||
LIGHTCYAN="\[\033[1;36m\]"
|
||||
LIGHTRED="\[\033[1;31m\]"
|
||||
LIGHTPURPLE="\[\033[1;35m\]"
|
||||
YELLOW="\[\033[1;33m\]"
|
||||
WHITE="\[\033[1;37m\]"
|
||||
|
||||
GIT_PS1_SHOWDIRTYSTATE=1
|
||||
GIT_PS1_SHOWSTASHSTATE=1
|
||||
GIT_PS1_SHOWUNTRACKEDFILES=1
|
||||
GIT_PS1_SHOWCOLORHINTS=
|
||||
GIT_PS1_DESCRIBE_STYLE="branch"
|
||||
GIT_PS1_SHOWUPSTREAM="auto git"
|
||||
|
||||
date="${CYAN}\D{%Y-%m-%d} ${LIGHTCYAN}\t"
|
||||
user="${LIGHTPURPLE}\u${DARKGRAY}@${PURPLE}\h"
|
||||
path="${DARKGRAY}in ${GREEN}\w"
|
||||
#prompt1="${DARKGRAY}o"
|
||||
#prompt1="${DARKGRAY}ooo"
|
||||
#prompt1="${RED}o${GREEN}o${BLUE}o"
|
||||
#prompt1="${DARKGRAY}o${GREEN}O${DARKGRAY}o"
|
||||
#prompt1="${DARKGRAY}o${GREEN}O${DARKGRAY}o"
|
||||
prompt1="${GREEN}o${DARKGRAY}o${GREEN}o"
|
||||
#prompt1="${RED}o${DARKGRAY}-${GREEN}o${DARKGRAY}-${BLUE}o"
|
||||
#prompt2="${BROWN} \\$ ${GREEN}→ ${DEFAULT}" # Not all terms understand this arrow
|
||||
prompt2="${BROWN} \\$ ${DEFAULT}"
|
||||
git="${LIGHTGREEN}"
|
||||
|
||||
# PS1 vs PROMPT_COMMAND?
|
||||
# PS1 is a string like MyPrompt> While PROMPT_COMMAND is evaulated using bash
|
||||
# In this case __git_ps1 is a bash function and all the stuff inside the "" are its parameters
|
||||
# It places the actual (master) prompt AFTER the "". This is why you see "stuff" "more stuff", the space
|
||||
# in between the quoted strings is where the (master) git prompt goes
|
||||
|
||||
# No, hostname -f requires DNS connection, breaks bash if no internet, slow
|
||||
#PROMPT_COMMAND='__git_ps1 "\n'${TITLEBAR}$DARK_BLUE'\u'$DEFAULT'@'$CYAN'$(hostname -f) '$BROWN'\w\n'$RED'CAUTION: mReschke Production!'$GREEN'" " '$CYAN'"\\\$"'$GREEN' → '$DEFAULT'"'
|
||||
#PROMPT_COMMAND='__git_ps1 "\n'${TITLEBAR}$DARK_BLUE'\u'$DEFAULT'@'$CYAN'$(hostname) '$BROWN'\w\n'$RED'mreschke.net production!'$GREEN'" " '$CYAN'"\\\$"'$GREEN' → '$DEFAULT'"'
|
||||
#PROMPT_COMMAND='__git_ps1 "\n'$date' '$user' in '$path'\n'$prompt'" "'$DEFAULT'"'
|
||||
PROMPT_COMMAND="__git_ps1 '\n$date $user $path\n$prompt1$git' '$prompt2'"
|
||||
|
||||
|
||||
# If you do just PS1 and no prompt_command, toor does not get a prompt
|
||||
# maybe because PS1 is overwritten elsewhere down the chain? Prompt_comman is not, so it works for all
|
||||
#export PS1=$date' '$user' in '$path'\n'$prompt' $(__git_ps1 " (%s)") '
|
||||
#export PS1=$date' '$user' in '$path'\n'$git' '$prompt
|
||||
|
||||
PS1=""
|
||||
PS2='continue-> '
|
||||
PS4='$0.$LINENO+ '
|
||||
|
||||
|
||||
# The full list comes from reading man bash, at the section PROMPTING:
|
||||
# ---------------------------------------------------------------------
|
||||
# \a an ASCII bell character (07)
|
||||
# \d the date in "Weekday Month Date" format (e.g., "Tue May 26")
|
||||
# \D{format} the format is passed to strftime(3) and the result is inserted into the prompt string; an empty format results in a locale-specific time representation. The braces are required
|
||||
# \e an ASCII escape character (033)
|
||||
# \h the hostname up to the first `.'
|
||||
# \H the hostname
|
||||
# \j the number of jobs currently managed by the shell
|
||||
# \l the basename of the shell's terminal device name
|
||||
# \n newline
|
||||
# \r carriage return
|
||||
# \s the name of the shell, the basename of $0 (the portion following the final slash)
|
||||
# \t the current time in 24-hour HH:MM:SS format
|
||||
# \T the current time in 12-hour HH:MM:SS format
|
||||
# \@ the current time in 12-hour am/pm format
|
||||
# \A the current time in 24-hour HH:MM format
|
||||
# \u the username of the current user
|
||||
# \v the version of bash (e.g., 2.00)
|
||||
# \V the release of bash, version + patch level (e.g., 2.00.0)
|
||||
# \w the current working directory, with $HOME abbreviated with a tilde (uses the value of the PROMPT_DIRTRIM variable)
|
||||
# \W the basename of the current working directory, with $HOME abbreviated with a tilde
|
||||
# \! the history number of this command
|
||||
# \# the command number of this command
|
||||
# \$ if the effective UID is 0, a #, otherwise a $
|
||||
# \nnn the character corresponding to the octal number nnn
|
||||
# \\ a backslash
|
||||
# \[ begin a sequence of non-printing characters, which could be used to embed a terminal control sequence into the prompt
|
||||
# \] end a sequence of non-printing characters
|
||||
|
Before Width: | Height: | Size: 86 KiB After Width: | Height: | Size: 86 KiB |
@@ -1,4 +1,39 @@
|
||||
---
|
||||
# ------------------------------------------------------------------------------
|
||||
# These tasks run for ALL servers be it Debian, CentOS, Virtual or Physical
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
# Copy profiles to /etc/profile.d/
|
||||
- include_tasks: ../../../../functions/copy_etc-profile.d.yml
|
||||
|
||||
# Copy scripts to /usr/local/bin
|
||||
- include_tasks: ../../../../functions/copy_usr-local-bin.yml
|
||||
|
||||
# Rsync /etc/vim
|
||||
- name: Synchronizing /etc/vim
|
||||
synchronize:
|
||||
src: vim/vim
|
||||
dest: /etc/
|
||||
delete: yes
|
||||
group: no
|
||||
owner: no
|
||||
rsync_opts:
|
||||
- "--exclude=.git"
|
||||
|
||||
- name: Sed /etc/vim/vimrc
|
||||
replace:
|
||||
path: /etc/vim/vimrc
|
||||
regexp: '~/.vim/plugged'
|
||||
replace: '/etc/vim/plugged'
|
||||
|
||||
- name: Symlink /usr/share/vim/vimfiles
|
||||
file:
|
||||
src: /etc/vim
|
||||
dest: /usr/share/vim/vimfiles
|
||||
owner: root
|
||||
group: root
|
||||
state: link
|
||||
|
||||
# Increase number of TCP connections per port (debian default 128)
|
||||
- name: Increasing number of TCP connections per port /etc/sysctl.conf net.core.somaxconn = 4096
|
||||
sysctl:
|
||||
@@ -1,36 +1,29 @@
|
||||
---
|
||||
# ------------------------------------------------------------------------------
|
||||
# These tasks run for any Debian/Ubuntu server (physical or virtual)
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
# Copy Debian 9 sources.list
|
||||
- name: Copying Debian 9 apt/sources.list
|
||||
copy: src=debian9/sources.list dest=/etc/apt/sources.list
|
||||
copy: src=debian/9/sources.list dest=/etc/apt/sources.list
|
||||
when: ansible_os_family == "Debian" and ansible_distribution_major_version == "9"
|
||||
|
||||
# Copy Debian 10 sources.list
|
||||
- name: Copying Debian 10 apt/sources.list
|
||||
copy: src=debian10/sources.list dest=/etc/apt/sources.list
|
||||
copy: src=debian/10/sources.list dest=/etc/apt/sources.list
|
||||
when: ansible_os_family == "Debian" and ansible_distribution_major_version == "10"
|
||||
|
||||
# Copy Ubuntu 16.04 sources.list
|
||||
- name: Copying Ubuntu 16.04 apt/sources.list
|
||||
copy: src=ubuntu1604/sources.list dest=/etc/apt/sources.list
|
||||
copy: src=ubuntu/16.04/sources.list dest=/etc/apt/sources.list
|
||||
when: ansible_distribution == "Ubuntu" and ansible_distribution_version == "16.04"
|
||||
|
||||
# Ignore apt translations
|
||||
- name: Ignoring apt tranlations
|
||||
copy: src=99translations dest=/etc/apt/apt.conf.d/99translations
|
||||
|
||||
# ??? hum, I don't want dotdeb on my debian 8 controller
|
||||
# may have ZERO debian 8 except for physical, so maybe don't do this generically
|
||||
# Many packages we install for Debian8 require dotdeb, so just install it generically
|
||||
#- name: Adding Debian8 dotdeb sources
|
||||
# apt_repository: repo='deb http://packages.dotdeb.org jessie all' state=present
|
||||
# when: ansible_os_family == "Debian" and ansible_distribution_major_version == "8"
|
||||
|
||||
#- name: Addding Debian8 dotdeb GPG key
|
||||
# apt_key: url='https://www.dotdeb.org/dotdeb.gpg' state=present
|
||||
# when: ansible_os_family == "Debian" and ansible_distribution_major_version == "8"
|
||||
copy: src=debian/99translations dest=/etc/apt/apt.conf.d/99translations
|
||||
|
||||
# Install common apps for all debian machines
|
||||
- name: Installing Debian common applications
|
||||
- name: Installing common Debian/Ubuntu applications
|
||||
apt:
|
||||
update_cache: yes
|
||||
state: present
|
||||
@@ -62,46 +55,3 @@
|
||||
- dos2unix # Convert dos line endings to unix and visa versa
|
||||
- acl # I customize directories often with ACL
|
||||
- dnsutils # Dig command and other dns commands
|
||||
|
||||
# Install PHP by default, unless explicitly ignored with - { role: server/debian, include_php: false }
|
||||
- name: Installing PHP 7 cli
|
||||
apt:
|
||||
update_cache: yes
|
||||
state: present
|
||||
name: php-cli
|
||||
when: include_php|default(true)|bool
|
||||
|
||||
|
||||
|
||||
# - nfs-kernel-server
|
||||
# - samba
|
||||
# - cifs-utils
|
||||
# - libnet-ssleay-perl
|
||||
# - libio-socket-ssl-perl
|
||||
# - libxrender1
|
||||
# - supervisor
|
||||
|
||||
# Were generic here, then commented out, careful
|
||||
# - dos2unix
|
||||
# - nfs-common
|
||||
# - entr
|
||||
|
||||
# libnet and libio are for sendEmail
|
||||
# libxrender1 is for wkhtmltopdf
|
||||
# python git dos2unix
|
||||
|
||||
|
||||
# other:
|
||||
# unattended-upgrades https://wiki.debian.org/UnattendedUpgrades
|
||||
# -- sending emails about updates...
|
||||
# log monitoring, security etc... maybe a new role
|
||||
|
||||
|
||||
#- name: Installing Debian8 applications
|
||||
# apt: name={{ item }} update_cache=yes state=present
|
||||
# with_items:
|
||||
|
||||
#- name: Installing Debian 9 applications
|
||||
# apt: name={{ item }} update_cache=yes state=present
|
||||
# with_items:
|
||||
# when: ansible_os_family == "Debian" and ansible_distribution_major_version == "9"
|
||||
20
server/tasks/debian/main.yml
Normal file
20
server/tasks/debian/main.yml
Normal file
@@ -0,0 +1,20 @@
|
||||
---
|
||||
# Debian Server
|
||||
# ------------------------------------------------------------------------------
|
||||
- name: Configuring debian/ubuntu server
|
||||
include_tasks: all.yml
|
||||
|
||||
# Physical Debian Server
|
||||
# ------------------------------------------------------------------------------
|
||||
- name: Configuring physical debian/ubuntu server
|
||||
include_tasks: physical.yml
|
||||
when: type == 'physical'
|
||||
|
||||
|
||||
# Virtual Debian Server
|
||||
# ------------------------------------------------------------------------------
|
||||
# Currently NO virtual specific debian customizations
|
||||
#- name: Configuring virtual debian/ubuntu server
|
||||
# include_tasks: virtual.yml
|
||||
# when: type == 'virtual'
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
---
|
||||
# Assuming physical servers are Debian
|
||||
- name: Installing physical server applications
|
||||
# ------------------------------------------------------------------------------
|
||||
# These tasks run for physical Debian/Ubuntu servers
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
# Physical Debian/Ubuntu Server
|
||||
- name: Installing physical Debian/Ubuntu server applications
|
||||
apt:
|
||||
update_cache: yes
|
||||
state: present
|
||||
12
server/tasks/main.yml
Normal file
12
server/tasks/main.yml
Normal file
@@ -0,0 +1,12 @@
|
||||
---
|
||||
# Any server (OS agnostic)
|
||||
# ------------------------------------------------------------------------------
|
||||
- name: Configure any server (OS agnostic)
|
||||
include_tasks: agnostic/main.yml
|
||||
|
||||
|
||||
# Debian server
|
||||
# ------------------------------------------------------------------------------
|
||||
- name: Configure debian/ubuntu server
|
||||
include_tasks: debian/main.yml
|
||||
when: ansible_os_family == "Debian"
|
||||
@@ -1 +0,0 @@
|
||||
---
|
||||
Reference in New Issue
Block a user