Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
94 commits
Select commit Hold shift + click to select a range
eca534e
chore: add ansible host file
Apr 17, 2020
2106a4b
chore: arch
Apr 18, 2020
23ae356
chore: add production folder
Apr 19, 2020
39cbde3
chore: add comment host production file
Apr 20, 2020
7f5bff7
chore: add seedbox comm
artentica Apr 22, 2020
664e348
add some conf for user
Apr 24, 2020
13d2088
change target of task
Apr 25, 2020
885a057
add creation user task
artentica Apr 28, 2020
69c632a
add example found online
artentica Apr 29, 2020
8c721d4
complete example
artentica May 2, 2020
e69d420
rm unecessary option
artentica May 2, 2020
d0e3e3f
change target
artentica May 2, 2020
a10eca0
put it in english
artentica May 2, 2020
817fa66
add a loop
artentica May 3, 2020
71f9543
take latest version
artentica May 5, 2020
21b4463
update cache
artentica May 5, 2020
3d2645a
add htop
artentica May 5, 2020
137c5e3
add zsh
artentica May 5, 2020
1cf126b
change for pacman
artentica May 8, 2020
b8601e8
update cache
artentica May 9, 2020
b82701d
upgrade pkg
artentica May 11, 2020
432d92f
chore: rename file
artentica May 12, 2020
e08d0e6
chore: add group vars
artentica May 11, 2020
2f5c9be
chore: add host vars
artentica May 14, 2020
947660d
chore: change seedbox to web
artentica May 15, 2020
bf93616
chore: put all in production folder
artentica May 16, 2020
d0241ce
chore: rename server
artentica May 17, 2020
5da8383
chore: add information on server
artentica May 18, 2020
00f601e
chore: add vars
artentica May 18, 2020
fddd68b
chore: add defaults pkg
artentica May 18, 2020
5c4064a
chore: change host name
artentica May 18, 2020
e17ac21
chore: put values on 2 lines
artentica May 18, 2020
4b56140
chore: add user tasks
artentica May 20, 2020
e2af4b0
chore: pkg
artentica May 25, 2020
81adf3c
chore: playbook
artentica May 27, 2020
0b453f2
chore: rmv debug pkg
artentica May 30, 2020
765c98c
chore: add disallow password login
artentica Jun 3, 2020
85db522
chore: yml formatting
artentica Jun 4, 2020
54adf72
chore: add post install script
artentica Jun 5, 2020
fae45b9
chore: add python and reboot
artentica Aug 10, 2020
635cae7
rename
artentica Jun 6, 2020
b7376f7
chore: rm trailing nb of char
artentica Jun 7, 2020
0025eaa
remove python from install
artentica Jun 8, 2020
c0f2378
update and install new python on same line
artentica Jun 9, 2020
bca67f7
chore: add ssh config
artentica Jun 10, 2020
e9ad656
rm package useless after install
artentica Jun 11, 2020
8441b77
chore: delay reboot
artentica Jun 14, 2020
95f3c34
chore: try force reboot
artentica Jun 15, 2020
890f969
chore: add swarm task main file
artentica Jun 16, 2020
31f472a
chore: add yaml
artentica Aug 26, 2020
c1c2f8a
chore: add first task
artentica Jun 16, 2020
73d45ce
chore: add docker repo
artentica Jun 16, 2020
700b00d
chore: add docker dependencied
artentica Jun 16, 2020
0c89d8a
chore: add user to docker
artentica Jun 16, 2020
264dc15
chore: create service directory
artentica Jun 17, 2020
e1605b1
chore: check if docker is running
artentica Jun 17, 2020
9df224c
chore: correct name task
artentica Jun 17, 2020
5078788
chore: add handler folder
artentica Jun 17, 2020
74f878e
chore: format yml
artentica Jun 17, 2020
31391d6
chore: add handler
artentica Jun 18, 2020
dbbf1d2
chore: correct handler
artentica Jun 19, 2020
8e5b59a
chore: defaults
artentica Jun 20, 2020
4c7f39c
chore: pkg to install
artentica Jun 21, 2020
530f868
chore: variable by default
artentica Jun 22, 2020
3e995ee
chore: correct install docker pkg
artentica Jun 23, 2020
adc0cc8
chore: correct folder name
artentica Jun 24, 2020
e920c55
chore: change default ssh port on mainserver
artentica Jun 28, 2020
d18cbe1
chore: reformat in LF
artentica Jun 28, 2020
303190b
chore: check if default port is used
artentica Jun 28, 2020
2a0a641
chore: show ssh_port_used
artentica Jun 29, 2020
2074f05
chore: just check ssh
artentica Jun 30, 2020
edd896b
chore: correct file ssh task/main
artentica Jul 1, 2020
8c164d6
chore: change ssh conf
artentica Jul 2, 2020
827c199
chore: change ssh
artentica Jul 3, 2020
273250d
chore: change ssh conf
artentica Jul 4, 2020
eba893e
chore: change ssh conf
artentica Jul 5, 2020
849c62c
chore: add default var
artentica Jul 6, 2020
c073863
chore: loop on sshd file config
artentica Jul 7, 2020
592a618
chore: uncomment all steps
artentica Jul 8, 2020
83edbd6
chore: flush handlers
artentica Jul 10, 2020
f09a240
chore: delete old file
artentica Jul 12, 2020
bc05baf
chore: rm add gpg
artentica Jul 13, 2020
b32abf5
change default param
artentica Jul 15, 2020
33e5c37
comment unused line
artentica Jul 17, 2020
3fc7be9
init swarm
artentica Jul 18, 2020
1851837
add docker on init
artentica Jul 18, 2020
208f307
chore: add group vars in for users
artentica Jul 19, 2020
2cbcf69
chore: add sudo in pkg to install to edit sudoers file
artentica Jul 20, 2020
beb0afa
chore: stop loggin by mdp
artentica Jul 22, 2020
8394e19
xhore: swarm default values
artentica Jul 23, 2020
7aefcc7
chore: swarm tasks
artentica Jul 24, 2020
960d74b
chore: add public key files
artentica Jul 25, 2020
acf4499
chore: add public key in conf sys
artentica Jul 25, 2020
8f9bcce
example conf with traefik in swarm
artentica Jul 25, 2020
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
5 changes: 5 additions & 0 deletions ansible/inventory/production/group_vars/web.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
users:
- username: 'artentica'
# groups: "admin,www-data"
- username: 'doctor'
# groups: "admin,www-data"
8 changes: 8 additions & 0 deletions ansible/inventory/production/host_vars/mainServer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
ansible_host: 91.121.85.107
ansible_port: 137
data_center: RBX1
rack: 07A01
id: 172791
reverse: ns352698.ip-91-121-85.eu
...
4 changes: 4 additions & 0 deletions ansible/inventory/production/hosts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# file: production

[web]
mainServer
Empty file.
17 changes: 17 additions & 0 deletions ansible/roles/packages/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
# - debug:
# msg: "{{ hostvars[inventory_hostname] }}"

- name: Dependencies installation
pacman:
name:
- git
- vim
- htop
- zsh
- sudo

update_cache: yes
# upgrade: yes
state: latest
...
4 changes: 4 additions & 0 deletions ansible/roles/ssh/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
# Default path of the ssh config file
sshd_config_path: "/etc/ssh/sshd_config"
...
4 changes: 4 additions & 0 deletions ansible/roles/ssh/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- name: restart sshd
service:
name: sshd
state: restarted
76 changes: 76 additions & 0 deletions ansible/roles/ssh/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
---
# ansible_port can change throughout this role, keep a copy around
- name: Set configured port fact
set_fact:
configured_port: "{{ ansible_port }}"

- name: "Check port {{ ansible_port }}"
wait_for:
port: "{{ ansible_port }}"
state: "started"
host: "{{ ansible_host }}"
connect_timeout: "5"
timeout: "5"
delegate_to: "localhost"
ignore_errors: "yes"
register: ssh_port

- debug:
msg: "{{ ansible_host }}"

- name: "Check port 22"
wait_for:
port: "22"
state: "started"
host: "{{ ansible_host }}"
connect_timeout: "5"
timeout: "5"
delegate_to: "localhost"
ignore_errors: "yes"
register: ssh_port_default
when:
- ssh_port is defined
- ssh_port.state is undefined

- name: Set SSH port to 22
set_fact:
ansible_port: 22
when: ssh_port_default.state is defined

# - name: Security | Disallow password authentication
# lineinfile:
# dest: /etc/ssh/sshd_config
# regexp: "^[#]*PasswordAuthentication"
# line: "PasswordAuthentication no"
# state: present
# notify: restart ssh
# tags: ["ssh"]

- name: Change sshd config
lineinfile:
dest: "{{ sshd_config_path }}"
regexp: "{{ item.regexp }}"
line: "{{ item.line }}"
with_items:
- { regexp: '^Port', line: 'Port "{{configured_port}}"' }
- { regexp: '^[#]*PasswordAuthentication=', line: 'PasswordAuthentication no' }
- { regexp: '^PermitRootLogin', line: 'PermitRootLogin no' }
notify: "restart sshd"

# We notified "Restart sshd" if we modified the sshd config.
# By calling flush_handlers, we make sure the handler is run *right now*
- name: Ensure SSH is reloaded if need be
meta: flush_handlers


- name: "Set SSH port to {{ configured_port }}"
set_fact:
ansible_port: "{{ configured_port }}"
when: ssh_port_default.state is defined

# Gather facts should be set to false when running this role since it will
# fail if the Ansible SSH port is not set correctly.
# We run setup to gather facts here once the SSH port is set up.
- name: Run deferred setup to gather facts
setup:
...
8 changes: 8 additions & 0 deletions ansible/roles/swarm/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
packages:
- docker
- docker-compose
- python-pip

docker_group: docker
...
6 changes: 6 additions & 0 deletions ansible/roles/swarm/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
- name: restart docker
service:
name: docker
state: restarted
...
29 changes: 29 additions & 0 deletions ansible/roles/swarm/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---

- name: install Docker and dependencies
pacman:
name: "{{ packages }}"
state: latest
update_cache: yes
with_items: "{{ packages }}"

- name: "Ensure group {{ docker_group }} exists"
group:
name: "{{ docker_group }}"

- name: Add user to docker group
user:
name: "{{ item.username }}"
group: "{{ docker_group }}"
with_items: "{{ users }}"

- name: Ensure Docker is running
service:
name: docker
state: started
enabled: yes

- name: Init a new swarm with default parameters
docker_swarm:
state: present
...
1 change: 1 addition & 0 deletions ansible/roles/users/files/artentica.key.pub
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIKSuo82KyqCWnmAPNTWbZq+vFaIH2YFJkLNvkANV65mc
1 change: 1 addition & 0 deletions ansible/roles/users/files/doctor.key.pub
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIKSuo82KyqCWnmAPNTWbZq+vFaIH2YFJkLNvkANV65mc
20 changes: 20 additions & 0 deletions ansible/roles/users/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
- name: "Create user: {{item.username}}"
user:
name: "{{ item.username }}"
groups: "admin"
with_items: "{{ users }}"

- name: "Add authorized keys"
authorized_key:
user: "{{ item.username }}"
key: "{{ lookup('file', 'files/'+ item.username + '.key.pub') }}"
with_items: "{{ users }}"

- name: "Allow admin users to sudo without a password"
lineinfile:
dest: "/etc/sudoers" # path: in version 2.3
state: "present"
regexp: "^%admin"
line: "%admin ALL=(ALL) NOPASSWD: ALL"
...
34 changes: 34 additions & 0 deletions ansible/site.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
- name: Server ssh only
hosts: web
remote_user: root
gather_facts: no
roles:
- role: ssh
tags:
- ssh

- name: Server installation
hosts: web
remote_user: root
roles:
- role: packages
tags:
- packages

- name: User configuration
hosts: web
remote_user: root
roles:
- role: users
tags:
- users

- name: Swarm installation & configuration
hosts: web
remote_user: root
roles:
- role: swarm
tags:
- swarm
...
7 changes: 7 additions & 0 deletions postInstall.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

wget https://pkgbuild.com/~eschwartz/repo/x86_64-extracted/pacman-static
chmod +x pacman-static
./pacman-static --noconfirm -Syyu python
rm ./pacman-static
reboot -f
75 changes: 75 additions & 0 deletions swarm/example.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
version: "3.8"


networks:
traefik:
name: "dmz"
driver: overlay
attachable: true

services:

traefik:
image: "traefik:v2.2"
command:
- "--global.sendanonymoususage=false" # désactivation de l'envoi de donnée
- "--global.checknewversion=false" # puisque dockerisé, on désactive le check de mise à jour
- "--accesslog=true" # Pour avoir les logs d'accès
- "--api=true" # Pour activer l'api
# Swarm
#traefik.http.services.myservice.loadbalancer.server.port=8080
- "--providers.docker.swarmMode=true"
- "--providers.docker.watch=true"
- "--providers.docker.endpoint=unix:///var/run/docker.sock"
- "--api.insecure=true" # Activer pour exposer l'api sur 8080
- "--api.dashboard=true" # Pour activer le dashboard
- "--log.level=DEBUG"
#- "--providers.file.directory=/etc/traefik/conf.d/" # Permets de charger les configurations dans le répertoire (tout les yaml et toml)
#- "--providers.file.watch=true" # Permets de surveiller le répertoire précédent pour charger dynamiquement les configurations
- "--entrypoints.http.address=:80" # Création de l'entrypoint nommé web sur le port 80
- "--entrypoints.https.address=:443" # Création de l'entrypoint nommé websecure sur le port 443
#- "--entrypoints.web.http.redirections.entrypoint.scheme=https" # Pour créer une redirection vers https
#- "--entrypoints.web.http.redirections.entrypoint.to=websecure" # Pour rediriger vers l'entrypoint websecure (port 443)
- "--certificatesresolvers.letsencrypt-rsa2048.acme.email=server@vincentriouallon.ovh"
- "--certificatesresolvers.letsencrypt-rsa2048.acme.caserver=https://acme-staging-v02.api.letsencrypt.org/directory"
- "--certificatesresolvers.letsencrypt-rsa2048.acme.storage=/acme.json"
- "--certificatesresolvers.letsencrypt-rsa2048.acme.keytype=RSA2048"
- "--certificatesresolvers.letsencrypt-rsa2048.acme.httpchallenge.entrypoint=web"
- "--certificatesresolvers.letsencrypt-rsa2048.acme.tlschallenge=true"
networks:
- traefik
ports:
- "8080:8080"
- "443:443"
- "80:80"
deploy:
labels:
- "traefik.http.services.traefik.loadbalancer.server.port=8080"
- "traefik.docker.lbswarm=true"
- "traefik.enable=true"
- "traefik.docker.network=dmz"
- "traefik.http.routers.traefik.entrypoints=https"
- "traefik.http.middlewares.http-redirect.redirectscheme.scheme=https"
volumes:
- "/var/run/docker.sock:/var/run/docker.sock:ro"

whoami:
image: "containous/whoami"
networks:
- traefik
deploy:
labels:
- "traefik.enable=true"
- "traefik.docker.network=dmz"
- "traefik.docker.lbswarm=true"
- "traefik.http.routers.reverse_proxy_plex_insecure.rule=Host(`whoami.vincentriouallon.ovh`)"
- "traefik.http.routers.reverse_proxy_plex_insecure.middlewares=http-redirect@docker"
- "traefik.http.routers.reverse_proxy_plex.entrypoints=https"
- "traefik.http.routers.reverse_proxy_plex.tls=true"
- "traefik.http.routers.reverse_proxy_plex.tls.certresolver=letsencrypt-rsa2048"
- "traefik.http.routers.reverse_proxy_plex.rule=Host(`whoami.vincentriouallon.ovh`)"
- "traefik.http.services.reverse_proxy_plex.loadbalancer.passhostheader=true"
- "traefik.http.services.reverse_proxy_plex.loadbalancer.server.port=80"
- "traefik.http.services.reverse_proxy_plex.loadbalancer.server.scheme=http"