Adding files for common setup on app. Finishing up dynamic inventory.

This commit is contained in:
Samuel Clay 2021-01-28 19:06:30 -05:00
parent d3ce8ab87c
commit dccb87bd26
16 changed files with 191 additions and 87 deletions

View file

@ -1,8 +1,10 @@
[defaults]
# host_key_checking = False
remote_user = nb
retry_files_enabled = False
inventory = /srv/newsblur/ansible/inventories/digital_ocean.ini, /srv/newsblur/ansible/inventories/digital_ocean.yml
private_key_file = /srv/secrets-newsblur/keys/docker.pem
private_key_file = /srv/secrets-newsblur/keys/docker.key
# private_key_file = /srv/secrets-newsblur/keys/newsblur.key
[inventory]
enable_plugins = ini, constructed

View file

@ -3,8 +3,8 @@
import os
import subprocess
# TOKEN_FILE = "/srv/secrets-newsblur/keys/digital_ocean.token"
TOKEN_FILE = "/srv/secrets-newsblur/keys/digital_ocean.readprod.token"
TOKEN_FILE = "/srv/secrets-newsblur/keys/digital_ocean.token"
# TOKEN_FILE = "/srv/secrets-newsblur/keys/digital_ocean.readprod.token"
with open(TOKEN_FILE) as f:
token = f.read().strip()

View file

@ -3,10 +3,10 @@ strict: False
groups:
web: inventory_hostname.startswith('app') or inventory_hostname.startswith('node') or inventory_hostname.startswith('work') or inventory_hostname.startswith('push')
app: inventory_hostname.startswith('app') or inventory_hostname.startswith('push')
app: (inventory_hostname.startswith('app') or inventory_hostname.startswith('push')) and inventory_hostname != 'app'
# work: inventory_hostname.startswith('work')
node: inventory_hostname.startswith('node')
node: inventory_hostname.startswith('node') and inventory_hostname != 'node'
# debug: inventory_hostname.startswith('debug')
db: inventory_hostname.startswith('db')
task: inventory_hostname.startswith('task')
task: inventory_hostname.startswith('task') and inventory_hostname != 'task'
search: inventory_hostname.startswith('search')

View file

@ -0,0 +1,37 @@
#!/bin/sh
bold=`echo "\033[1m"`
regular=`echo "\033[0m"`
black=`echo "\033[30;40m"`
red=`echo "\033[31;40m"`
green=`echo "\033[32;40m"`
yellow=`echo "\033[33;40m"`
blue=`echo "\033[34;40m"`
magenta=`echo "\033[35;40m"`
cyan=`echo "\033[36;40m"`
white=`echo "\033[37;40m"`
cat <<EOMOTD
$bold
$cyan^^ $yellow@@@@@@@@@
$cyan^^ ^^ $yellow@@@@@@@@@@@@@@@
$yellow@@@@@@@@@@@@@@@@@@ $cyan^^
$yellow@@@@@@@@@@@@@@@@@@@@
$bold$blue~~~~ ~~ ~~~~~ ~~~~~~~~ ~~ $regular$yellow&&&&&&&&&&&&&&&&&&&&$bold$blue ~~~~~~~ ~~~~~~~~~~~ ~~~
$bold$blue~ ~~ ~ ~ $regular$yellow~~~~~~~~~~~~~~~~~~~~$bold$blue ~ ~~ ~~ ~
$bold$blue ~ ~~ ~~ ~~ ~~ $regular$yellow~~~~~~~~~~~~~ ~~~~$bold$blue ~ ~~~ ~ ~~~ ~ $bold$blue~~
$bold$blue ~ ~~ ~ ~ $regular$yellow~~~~~~ ~~ ~~~$bold$blue ~~ ~ ~~ ~~ ~
$bold$blue~ ~ ~ ~ ~ $regular$yellow~~ ~~~~~~$bold$blue ~ ~~ ~ $bold$blue~~
$bold$blue ~ ~ ~ ~ ~~ ~ ~
$green
888b | 888~~\ 888
|Y88b | e88~~8e Y88b e / d88~\ 888 | 888 888 888 888-~\
| Y88b | d888 88b Y88b d8b / C888 888 _/ 888 888 888 888
| Y88b | 8888__888 Y888/Y88b/ Y88b 888 \ 888 888 888 888
| Y88b| Y888 , Y8/ Y8/ 888D 888 | 888 888 888 888
| Y888 "88___/ Y Y \_88P 888__/ 888 "88_-888 888
$red App Server
$regular$white
EOMOTD

View file

@ -0,0 +1,39 @@
#!/bin/sh
bold=`echo "\033[1m"`
regular=`echo "\033[0m"`
black=`echo "\033[30;40m"`
red=`echo "\033[31;40m"`
green=`echo "\033[32;40m"`
yellow=`echo "\033[33;40m"`
blue=`echo "\033[34;40m"`
magenta=`echo "\033[35;40m"`
cyan=`echo "\033[36;40m"`
white=`echo "\033[37;40m"`
cat <<EOMOTD
$bold
$cyan^^ $yellow@@@@@@@@@
$cyan^^ ^^ $yellow@@@@@@@@@@@@@@@
$yellow@@@@@@@@@@@@@@@@@@ $cyan^^
$yellow@@@@@@@@@@@@@@@@@@@@
$bold$blue~~~~ ~~ ~~~~~ ~~~~~~~~ ~~ $regular$yellow&&&&&&&&&&&&&&&&&&&&$bold$blue ~~~~~~~ ~~~~~~~~~~~ ~~~
$bold$blue~ ~~ ~ ~ $regular$yellow~~~~~~~~~~~~~~~~~~~~$bold$blue ~ ~~ ~~ ~
$bold$blue ~ ~~ ~~ ~~ ~~ $regular$yellow~~~~~~~~~~~~~ ~~~~$bold$blue ~ ~~~ ~ ~~~ ~ $bold$blue~~
$bold$blue ~ ~~ ~ ~ $regular$yellow~~~~~~ ~~ ~~~$bold$blue ~~ ~ ~~ ~~ ~
$bold$blue~ ~ ~ ~ ~ $regular$yellow~~ ~~~~~~$bold$blue ~ ~~ ~ $bold$blue~~
$bold$blue ~ ~ ~ ~ ~~ ~ ~
$green
888b | 888~~\ 888
|Y88b | e88~~8e Y88b e / d88~\ 888 | 888 888 888 888-~\
| Y88b | d888 88b Y88b d8b / C888 888 _/ 888 888 888 888
| Y88b | 8888__888 Y888/Y88b/ Y88b 888 \ 888 888 888 888
| Y88b| Y888 , Y8/ Y8/ 888D 888 | 888 888 888 888
| Y888 "88___/ Y Y \_88P 888__/ 888 "88_-888 888
$red DB Server
$regular$white
EOMOTD

View file

@ -0,0 +1,39 @@
#!/bin/sh
bold=`echo "\033[1m"`
regular=`echo "\033[0m"`
black=`echo "\033[30;40m"`
red=`echo "\033[31;40m"`
green=`echo "\033[32;40m"`
yellow=`echo "\033[33;40m"`
blue=`echo "\033[34;40m"`
magenta=`echo "\033[35;40m"`
cyan=`echo "\033[36;40m"`
white=`echo "\033[37;40m"`
cat <<EOMOTD
$bold
$cyan^^ $yellow@@@@@@@@@
$cyan^^ ^^ $yellow@@@@@@@@@@@@@@@
$yellow@@@@@@@@@@@@@@@@@@ $cyan^^
$yellow@@@@@@@@@@@@@@@@@@@@
$bold$blue~~~~ ~~ ~~~~~ ~~~~~~~~ ~~ $regular$yellow&&&&&&&&&&&&&&&&&&&&$bold$blue ~~~~~~~ ~~~~~~~~~~~ ~~~
$bold$blue~ ~~ ~ ~ $regular$yellow~~~~~~~~~~~~~~~~~~~~$bold$blue ~ ~~ ~~ ~
$bold$blue ~ ~~ ~~ ~~ ~~ $regular$yellow~~~~~~~~~~~~~ ~~~~$bold$blue ~ ~~~ ~ ~~~ ~ $bold$blue~~
$bold$blue ~ ~~ ~ ~ $regular$yellow~~~~~~ ~~ ~~~$bold$blue ~~ ~ ~~ ~~ ~
$bold$blue~ ~ ~ ~ ~ $regular$yellow~~ ~~~~~~$bold$blue ~ ~~ ~ $bold$blue~~
$bold$blue ~ ~ ~ ~ ~~ ~ ~
$green
888b | 888~~\ 888
|Y88b | e88~~8e Y88b e / d88~\ 888 | 888 888 888 888-~\
| Y88b | d888 88b Y88b d8b / C888 888 _/ 888 888 888 888
| Y88b | 8888__888 Y888/Y88b/ Y88b 888 \ 888 888 888 888
| Y88b| Y888 , Y8/ Y8/ 888D 888 | 888 888 888 888
| Y888 "88___/ Y Y \_88P 888__/ 888 "88_-888 888
$red Task Server
$regular$white
EOMOTD

View file

@ -1,49 +0,0 @@
#!/bin/sh
bold=`echo "\033[1m"`
regular=`echo "\033[0m"`
black=`echo "\033[30;40m"`
red=`echo "\033[31;40m"`
green=`echo "\033[32;40m"`
yellow=`echo "\033[33;40m"`
blue=`echo "\033[34;40m"`
magenta=`echo "\033[35;40m"`
cyan=`echo "\033[36;40m"`
white=`echo "\033[37;40m"`
cat <<EOMOTD
$bold
$yellow^^
^^ $red.. ..
[] []
.:[]:_ $yellow^^$red ,:[]:.
.: :[]: :-. ,-: :[]: :.
.: : :[]: : :'._ ,.': : :[]: : :.
.: : : :[]: : : : :-._ _,-: : : : :[]: : : :.
_..: : : : :[]: : : : : : :-._________.-: : : : : : :[]: : : : :-._
_:_:_:_:_:_:[]:_:_:_:_:_:_:_:_:_:_:_:_:_:_:_:_:_:_:_:[]:_:_:_:_:_:_
!!!!!!!!!!!![]!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!![]!!!!!!!!!!!!!
^^^^^^^^^^^^[]^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^[]^^^^^^^^^^^^^
[] []
[] []
[] []
$blue ~~^-~^_~^~$red/ \\$blue~^-~^~_~^-~_^~-^~_^~~-^~_~^~-~_~-^~_^$red/ \\$blue~^-~_~^-~~-
$blue ~ _~~- ~^-^~-^~~- ^~_^-^~~_ -~^_ -~_-~~^- _~~_~-^_ ~^-^~~-_^-~ ~^
$blue ~ ^- _~~_- ~~ _ ~ ^~ - ~~^ _ - ^~- ~ _ ~~^ - ~_ - ~^_~
$blue ~- ^_ ~^ - ^~ _ - ~^~ _ _~^~- _ ~~^ - _ ~ - _ ~~^ -
$blue ~^ -_ ~^^ -_ ~ _ - _ ~^~- _~ -_ ~- _ ~^ _ - ~ ^-
$blue ~^~ - _ ^ - ~~~ _ - _ ~-^ ~ __- ~_ - ~ ~^_-
$blue ~ ~- ^~ - ~^ - ~ ^~ - ~~ ^~ - ~
$green ████████╗██╗ ██╗██████╗ ███╗ ██╗ ████████╗ ██████╗ ██╗ ██╗ ██████╗██╗ ██╗
$green ╚══██╔══╝██║ ██║██╔══██╗████╗ ██║ ╚══██╔══╝██╔═══██╗██║ ██║██╔════╝██║ ██║
$green ██║ ██║ ██║██████╔╝██╔██╗ ██║ ██║ ██║ ██║██║ ██║██║ ███████║
$green ██║ ██║ ██║██╔══██╗██║╚██╗██║ ██║ ██║ ██║██║ ██║██║ ██╔══██║
$green ██║ ╚██████╔╝██║ ██║██║ ╚████║ ██║ ╚██████╔╝╚██████╔╝╚██████╗██║ ██║
$green ╚═╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═══╝ ╚═╝ ╚═════╝ ╚═════╝ ╚═════╝╚═╝ ╚═╝
$cyan App Server
$regular$white
EOMOTD

View file

@ -1,25 +1,19 @@
. /etc/profile
# Path to your oh-my-zsh configuration.
plugins=(git osx ruby gem github pip rails)
export ZSH=$HOME/.oh-my-zsh
# Set to the name theme to load.
# Look in ~/.oh-my-zsh/themes/
export CLICOLOR='1'
export ZSH_THEME="risto"
export DISABLE_AUTO_UPDATE=true
export DISABLE_AUTO_UPDATE="true"
export WORKON_HOME=/srv/newsblur/venv
export PROJECT_HOME=/srv/newsblur
# source /usr/local/bin/virtualenvwrapper.sh
# Set to this to use case-sensitive completion
export CASE_SENSITIVE="true"
export LC_COLLATE='C'
plugins=(git github pip)
source $ZSH/oh-my-zsh.sh
export DISABLE_AUTO_UPDATE="true"
export PYTHONSTARTUP=$HOME/.pystartup
export LSCOLORS='gxgxcxdxBxegedabagacad'
export GOROOT=/srv/code/go
export GOPATH=/srv/code/go
zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}'
zstyle ':completion:*' list-colors "=(#b) #([0-9]#)*=36=31"
setopt COMPLETE_IN_WORD
@ -48,8 +42,11 @@ alias ls='ls -pFa --color'
alias cd..='cd ..'
alias smtp='python -m smtpd -n -c DebuggingServer 127.0.0.1:1025'
alias tltt='echo "----------------\n"; tail -f /var/log/turntouch-web/turntouch-web.log'
alias sshtt=/srv/turntouch-web/scripts/ssh.sh
alias cdtw=/srv/turntouch-web
alias tlnb='echo "----------------\n"; tail -f logs/newsblur.log'
alias sshnb='ssh sclay@app10.newsblur.com'
alias sp='~/newsblur/manage.py shell_plus --use-pythonrc'
alias cdsg='cd ~/staging'
alias cdnb='cd ~/newsblur'
alias sshdo=/srv/newsblur/utils/ssh.sh
cd /srv/turntouch-web
cd /srv/newsblur

View file

@ -25,9 +25,9 @@
- name: Copy toprc
copy: src=toprc.txt dest=~/.toprc
- name: Copy motd
- name: "Copy motd for {{ motd_role }}"
become: yes
copy: src=motd.txt dest=/etc/update-motd.d/52-nb-motd mode=0755
copy: "src=motd.{{ motd_role }}.txt dest=/etc/update-motd.d/52-nb-motd mode=0755"
- include: ufw.yml
become: yes

View file

@ -0,0 +1,6 @@
---
- name: "Build hosts file"
lineinfile: dest=/etc/hosts regexp='.*{{ item }}$' line="{{ hostvars[item].ansible_default_ipv4.address }} {{item}}" state=present
become: yes
when: hostvars[item].ansible_default_ipv4.address is defined
with_items: groups['all']

View file

@ -3,11 +3,13 @@
remote_user: nb
vars:
- update_apt_cache: yes
- motd_role: app
vars_files:
- env_vars/base.yml
roles:
# - base
# - docker
- nginx
- base
- docker
- web
- nginx
- {role: etchosts, tags: 'etchosts'}

View file

@ -9,16 +9,47 @@
- env_vars/droplet.yml
tasks:
- name: Defined role or name
fail:
msg: Please define a role for your new droplet
when: role is not defined and name is not defined
- name: Setting name from role using inventory
set_fact:
name: "{{ role }}"
when: role is defined
- name: Setting role from name
set_fact:
role: "{{ name | regex_replace('\\d+', '') }}"
when: role is not defined
- fail:
msg: Please define a name for your new droplet
when: name is not defined
- name: Create a new droplet
vars:
token: "{{ lookup('file', '/srv/secrets-newsblur/keys/digital_ocean.token') | trim }}"
community.digitalocean.digital_ocean_droplet:
state: present
name: app01
name: "{{ name }}"
size: "{{ droplet_size }}"
region: "{{ droplet_region }}"
image: "{{ droplet_image }}"
wait_timeout: 500
ssh_keys: [ "{{ droplet_ssh_key_id }}" ]
register: new_box
unique_name: true
oauth_token: "{{ token }}"
register: created_droplet
- debug:
msg: "ID is {{ new_box.data.droplet.id }}, IP is {{ new_box.data.ip_address }}"
msg: "ID is {{ created_droplet.data.droplet.id }}, IP is {{ created_droplet.data.ip_address }}"
- name: "Add to dyanmic inventory under {{ role }}"
add_host:
name: '{{ created_droplet.data.ip_address }}'
group: '{{ role }}'
- name: Setup user on new machine
include_playbook: setup_root.yml

View file

@ -5,9 +5,9 @@ export DISABLE_AUTO_UPDATE=true
export WORKON_HOME=/srv/newsblur/venv
export PROJECT_HOME=/srv/newsblur
source /usr/local/bin/virtualenvwrapper.sh
# source /usr/local/bin/virtualenvwrapper.sh
plugins=(git github pip virtualenvwrapper)
plugins=(git github pip)
source $ZSH/oh-my-zsh.sh
export PYTHONSTARTUP=$HOME/.pystartup

View file

@ -8,7 +8,7 @@ sys.path.append('/srv/newsblur')
os.environ['DJANGO_SETTINGS_MODULE'] = 'newsblur_web.settings'
if __name__ == '__main__':
doapi = digitalocean.Manager(token=settings.DO_TOKEN_LOG)
doapi = digitalocean.Manager(token=settings.DO_TOKEN_SSH)
droplets = doapi.get_all_droplets()
for droplet in droplets:
if sys.argv[1] == droplet.name:

View file

@ -20,4 +20,4 @@ WHITE='\033[01;37m'
ipaddr=`python /srv/newsblur/utils/hostname_ssh.py $1`
printf "\n ${BLUE}---> ${LBLUE}Connecting to ${LGREEN}$1${BLUE} / ${LRED}$ipaddr${BLUE} <--- ${RESTORE}\n\n"
ssh -l sclay -i /srv/secrets-newsblur/keys/newsblur.key $ipaddr
ssh -l nb -i /srv/secrets-newsblur/keys/docker.key $ipaddr