Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add basic ansible automation #9

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ansible/ansible.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[defaults]
hostfile = hosts
stdout_callback=debug
stderr_callback=debug
2 changes: 2 additions & 0 deletions ansible/hosts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[madlambda]
127.0.0.1
120 changes: 120 additions & 0 deletions ansible/madlambda.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
---
- hosts: all
connection: local
tasks:
- name: create madlambda group
group:
name: madlambda

- name: create i4k user
user:
name: i4k
uid: 1337
groups: madlambda
append: yes

- name: prepare src dir
file:
path: /root/src
state: directory
mode: '0755'

- name: clean unit source
file:
path: /root/src/unit
state: absent

- name: install basic dependencies
apt:
update_cache: yes
state: latest
pkg:
- mercurial
- git
- build-essential
- libssl-dev
- python-dev
- php-dev
- libphp-embed
- golang-go
- jq
- certbot
- wget

- name: configure mercurial
copy:
dest: /root/.hgrc
content: |
[ui]
username = root <[email protected]>

color =

[extensions]
mq =
purge =

[diff]
showfunc = True

- name: clone unit
shell: hg clone http://hg.nginx.org/unit/
args:
chdir: /root/src

- name: apply unit TLS patch
shell: |
wget -O tls-config.patch https://gist.githubusercontent.com/tiago4orion/a3a993c96813f691b9a417193a3ad54e/raw/280459007c2ee21b4b2895812cd9cb2652455530/tls-config.patch
hg qimport -n tls-config tls-config.patch
hg qpush
args:
chdir: /root/src/unit

- name: build unit (php, python and go)
shell: |
make clean || true
./configure --cc-opt="-O3" --prefix=/usr/local/unit --tests --openssl
./configure php
./configure python
GOPATH=/root/src/unit/build/go ./configure go
make tests
./build/tests
make
python3 ./test/run.py
make install
args:
chdir: /root/src/unit

- name: init i4k dir
become_user: i4k
file:
path: /home/i4k/src
state: directory
mode: '0755'

- name: remove i4k sources
become_user: i4k
file:
path: /home/i4k/src/i4k.madlambda.io
state: absent

- name: install i4k stuff
become_user: i4k
shell: git clone https://github.com/tiago4orion/i4k.madlambda.io.git
args:
chdir: /home/i4k/src

- name: install madlambda.io
shell: ./install.sh
args:
chdir: /root/src/madlambda.io

- name: stop && start unit
shell: |
systemctl stop unit || true
systemctl start unit

- name: configure madlambda.io
shell: ./unit/apply.sh
args:
chdir: /root/src/madlambda.io
12 changes: 11 additions & 1 deletion unit/apply.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,23 @@ if ! $CURL -XGET 127.0/certificates/madlambda.io | jq -e ".chain" >/dev/null; th
fi
fi

cat > tls.json << EOF
{
"certificate": "madlambda.io",
"protocols": ["SSLv2", "SSLv3", "TLSv1.2", "TLSv1.3"],
"ciphers": "HIGH:!aNULL:!MD5"
}
EOF

if ! $CURL -XPUT '127.0/config/listeners/*:443/tls' \
--data-binary '{"certificate": "madlambda.io"}' | jq -e ".success"; then
--data-binary @tls.json | jq -e ".success"; then

echo "failed to apply certificate to listener *:443"
exit 1
fi

rm -f tls.json

cd unit/apps

for name in $(ls); do
Expand Down
24 changes: 0 additions & 24 deletions unit/apps/container-example/config.json

This file was deleted.

2 changes: 1 addition & 1 deletion unit/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"user": "root",
"group": "root",
"module": "wsgi",
"path": "/root/madlambda.io/apps/redirect-to-https"
"path": "/root/src/madlambda.io/apps/redirect-to-https"
}
},
"settings": {
Expand Down
9 changes: 0 additions & 9 deletions unit/routes.d/container.json

This file was deleted.

2 changes: 1 addition & 1 deletion unit/routes.d/i4k.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"host": "i4k.madlambda.io"
},
"action": {
"share": "/home/i4k/i4k.madlambda.io/www"
"share": "/home/i4k/src/i4k.madlambda.io/www"
}
}