Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
108 commits
Select commit Hold shift + click to select a range
5cf883c
added ansible boilerplate
yoav-katz Nov 13, 2024
81a9803
feat(haproxy): added haproxy role
yoav-katz Nov 13, 2024
f89d381
bla
yoav-katz Nov 13, 2024
713637b
feat(keepalived): added keepalived functionality
yoav-katz Nov 13, 2024
13fb643
fixes
yoav-katz Nov 13, 2024
9eb9b4b
fix
yoav-katz Nov 13, 2024
634c62c
bla
yoav-katz Nov 13, 2024
9cf9aa5
bla
yoav-katz Nov 13, 2024
9b0b878
bla
yoav-katz Nov 13, 2024
7151433
fixed
yoav-katz Nov 13, 2024
21c3df5
added boilerplate
yoav-katz Nov 13, 2024
df4b400
fixed
yoav-katz Nov 13, 2024
609bfc5
fixe
yoav-katz Nov 13, 2024
4814336
fix
yoav-katz Nov 13, 2024
063dea8
bl
yoav-katz Nov 13, 2024
36bbdd1
bl
yoav-katz Nov 13, 2024
1ede2e9
bla
yoav-katz Nov 13, 2024
3f277f0
b
yoav-katz Nov 13, 2024
8d5d7c6
b
yoav-katz Nov 13, 2024
84a57e8
bl
yoav-katz Nov 13, 2024
efd8fae
bla
yoav-katz Nov 13, 2024
92f3c25
br
yoav-katz Nov 13, 2024
9b7f066
bla
yoav-katz Nov 13, 2024
8c3eaac
bl
yoav-katz Nov 13, 2024
77bce73
s
yoav-katz Nov 13, 2024
d7fc486
bla
yoav-katz Nov 13, 2024
a5dfd3e
b
yoav-katz Nov 13, 2024
332fa11
bl
yoav-katz Nov 13, 2024
bd83943
bls
yoav-katz Nov 13, 2024
3bba01f
b
yoav-katz Nov 13, 2024
100cf3e
d
yoav-katz Nov 13, 2024
8ce39c8
b
yoav-katz Nov 13, 2024
be79ce5
adsadf
yoav-katz Nov 14, 2024
2f80391
fix
yoav-katz Nov 14, 2024
5ad0ff8
bfaads
yoav-katz Nov 14, 2024
c0e2f08
asdfasddfsadf
yoav-katz Nov 14, 2024
3238ff9
dfgdfg
yoav-katz Nov 14, 2024
00f93be
sfdasddf
yoav-katz Nov 14, 2024
6af5ced
adfasdf
yoav-katz Nov 14, 2024
e2d0fbb
asgdsadg
yoav-katz Nov 14, 2024
7d43e15
blasfasdsdfg
yoav-katz Nov 14, 2024
f64c515
asdfasdf
yoav-katz Nov 14, 2024
8dd6b91
sadfasdfdasg
yoav-katz Nov 14, 2024
097f6d7
afdasdf
yoav-katz Nov 14, 2024
3662794
sdgasfd
yoav-katz Nov 14, 2024
f9a344d
adsfasdfa
yoav-katz Nov 14, 2024
68871ac
adfasdfasf
yoav-katz Nov 14, 2024
b66b7a5
ASDFasdf
yoav-katz Nov 14, 2024
b197d98
sadfasdffsddfs
yoav-katz Nov 14, 2024
350cc9e
asdfdass
yoav-katz Nov 18, 2024
00ae3f3
asdfda
yoav-katz Nov 18, 2024
45eae36
asdfasdf
yoav-katz Nov 18, 2024
7a379a7
asdfda
yoav-katz Nov 18, 2024
a1d3ae1
asdfsaf
yoav-katz Nov 18, 2024
9124694
safafasdf
yoav-katz Nov 18, 2024
715f5ec
asdfasfd
yoav-katz Nov 18, 2024
e804c8c
asdfdsaf
yoav-katz Nov 18, 2024
57b35ae
asdf
yoav-katz Nov 18, 2024
9291d2b
asdffasfd
yoav-katz Nov 18, 2024
e3fe16d
asdf
yoav-katz Nov 18, 2024
a52bd62
adfasdf
yoav-katz Nov 18, 2024
cbb896f
asfdsa
yoav-katz Nov 18, 2024
cf5d507
asdfd
yoav-katz Nov 18, 2024
782f5f8
adfsa
yoav-katz Nov 18, 2024
7602e8e
asdfsadf
yoav-katz Nov 18, 2024
684ade6
sadffafdsa
yoav-katz Nov 18, 2024
c28e25c
asdfsadF
yoav-katz Nov 18, 2024
3aa49ef
asdfsafd
yoav-katz Nov 18, 2024
f7bb652
a
yoav-katz Nov 18, 2024
6105c24
asdf
yoav-katz Nov 18, 2024
70207df
asdfasdf
yoav-katz Nov 18, 2024
b28dd71
asdfsaf
yoav-katz Nov 18, 2024
5e7c989
d
yoav-katz Nov 18, 2024
9480169
adgadsf
yoav-katz Nov 18, 2024
007ce92
asdfsdf
yoav-katz Nov 18, 2024
44d188d
AFDsdf
yoav-katz Nov 18, 2024
a8849ab
adf
yoav-katz Nov 18, 2024
9637e1a
adgadffsf
yoav-katz Nov 18, 2024
b996ee3
adsadf
yoav-katz Nov 18, 2024
b5d7f77
Asfd
yoav-katz Nov 18, 2024
0d6e5b7
asdfsf
yoav-katz Nov 18, 2024
e493053
adsasdf
yoav-katz Nov 18, 2024
8a92679
asdfsF
yoav-katz Nov 18, 2024
e591ee5
asdfs
yoav-katz Nov 18, 2024
91a4971
asdfsaf
yoav-katz Nov 18, 2024
cd2a057
ASdfasf
yoav-katz Nov 18, 2024
00bb347
sadfasdfsFD
yoav-katz Nov 18, 2024
5645e80
Asdfsaf
yoav-katz Nov 18, 2024
6b916d0
Asdfasfd
yoav-katz Nov 18, 2024
de4bfbc
Adfsaf
yoav-katz Nov 18, 2024
97184ff
asdfsfd
yoav-katz Nov 18, 2024
abd94e0
asdfasfd
yoav-katz Nov 18, 2024
346653b
asdfsadf
yoav-katz Nov 18, 2024
3794860
adsfsfd
yoav-katz Nov 18, 2024
1014e82
asdfsafd
yoav-katz Nov 19, 2024
abe0f36
SAdfsaf
yoav-katz Nov 19, 2024
3e382d3
ASdfsadf
yoav-katz Nov 19, 2024
258d14b
sdfsf
yoav-katz Nov 19, 2024
a5e7d9e
afdsdf
yoav-katz Nov 19, 2024
19c4aff
asdfsAF
yoav-katz Nov 19, 2024
f22dc91
SADFasf
yoav-katz Nov 19, 2024
4c060c2
AfdasDF
yoav-katz Nov 19, 2024
59b6bfc
SadfasF
yoav-katz Nov 19, 2024
76eb18e
ASDFasDF
yoav-katz Nov 19, 2024
e2c1e81
ASdfasFD
yoav-katz Nov 19, 2024
62c62d4
sadfasdf
yoav-katz Nov 19, 2024
64578e8
sadfasF
yoav-katz Nov 19, 2024
555f47b
The Choosen One
yoav-katz Nov 19, 2024
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.vscode/*
7 changes: 7 additions & 0 deletions ansible.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[defaults]
roles_path = $HOME/ITtoolsTask/roles
inventory = $HOME/ITtoolsTask/inventory.ini
forks = 10
remote_user = vagrant
become = False
ansible_python_interpreter = /usr/bin/python3.8
7 changes: 7 additions & 0 deletions inventory.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[haproxy]
192.168.0.2 keepalived_state=MASTER keepalived_priority=101
192.168.0.3 keepalived_state=BACKUP keepalived_priority=99

[webserver]
192.168.0.4
192.168.0.5
23 changes: 23 additions & 0 deletions playbook.yml

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

call it main.yml, or something else, but not this

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
- name: Configure Task
hosts: all
become: true

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try using the become only when necessary, and not all the time.

gather_facts: true
vars_files:
- vault.yml
vars:
keepalived_ip: 192.168.0.6
tasks:
- name: Set subject_alt_names
set_fact:
subject_alt_names: "{{ groups['webserver'] | map('extract', hostvars, 'ansible_fqdn') | map('regex_replace', '^(.*)$', 'DNS:\\1') | join(',') }},DNS:keepalived.com,IP:{{ keepalived_ip }}"
when: "'haproxy' in group_names"

- name: Import apache Role
import_role:
name: "apache"
when: "'webserver' in group_names"

- name: Import haproxy Role
import_role:
name: "haproxy"
when: "'haproxy' in group_names"
6 changes: 6 additions & 0 deletions roles/apache/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
# handlers file for apache
- name: Restart Httpd
service:
name: httpd
state: restarted
14 changes: 14 additions & 0 deletions roles/apache/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
galaxy_info:
role_name: apache
author: Yoav Katz

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hhhhhhh

description: Creating httpd configuration with default index.html inside it
platforms:
- name: Centos8
versions:
- all

license: MIT

min_ansible_version: 2.1

dependencies: ['certificates']
33 changes: 33 additions & 0 deletions roles/apache/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
- name: Ensure httpd and his required packages ares installed.
dnf:
name:
- httpd
- mod_ssl
- openssh
state: present

- name: Generate httpd configuration
template:
src: httpd.conf.j2
dest: /etc/httpd/conf/httpd.conf
validate: httpd -t -f %s
mode: 0644
owner: apache
group: apache
notify:
- Restart Httpd

- name: Generate apache html
template:
src: index.html.j2
dest: /var/www/html/index.html
mode: 0644
owner: apache
group: apache

- name: Ensure httpd service is enabled
service:
name: httpd
state: started
enabled: true
78 changes: 78 additions & 0 deletions roles/apache/templates/httpd.conf.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
ServerRoot "/etc/httpd"
ServerName {{ ansible_fqdn }}

Include conf.modules.d/*.conf

User apache
Group apache

<Directory />
AllowOverride none
Require all denied
</Directory>

DocumentRoot "/var/www/html"

#Further relax access to the default document root:
<Directory "/var/www/html">
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>

<VirtualHost *:443>
SSLEngine on
SSLCertificateKeyFile /etc/ssl/private/server.pem
SSLCertificateFile /etc/ssl/private/server.pem
SSLProtocol all -SSLv2 -SSLv3
</VirtualHost>

<IfModule dir_module>
DirectoryIndex index.html
</IfModule>

<Files ".ht*">
Require all denied
</Files>

ErrorLog "logs/error_log"

LogLevel warn

<IfModule log_config_module>
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common

<IfModule logio_module>
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
</IfModule>

CustomLog "logs/access_log" combined
</IfModule>

<IfModule alias_module>
ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
</IfModule>

<Directory "/var/www/cgi-bin">
AllowOverride None
Options None
Require all granted
</Directory>

<IfModule mime_module>
TypesConfig /etc/mime.types
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType text/html .shtml
AddOutputFilter INCLUDES .shtml
</IfModule>

AddDefaultCharset UTF-8

<IfModule mime_magic_module>
MIMEMagicFile conf/magic
</IfModule>

EnableSendfile on
IncludeOptional conf.d/*.conf
7 changes: 7 additions & 0 deletions roles/apache/templates/index.html.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<html>
<head>
</head>
<body>
<h1>{{ ansible_nodename }}</h1>
</body>
</html>
1 change: 1 addition & 0 deletions roles/apache/vars/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
handler_to_notify: 'Restart Httpd'
5 changes: 5 additions & 0 deletions roles/certificates/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
organization_details:
name: "Katz"
locality: "Tel Aviv"
country: "IL"
14 changes: 14 additions & 0 deletions roles/certificates/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
galaxy_info:
role_name: certificates
author: Yoav Katz
description: Creating certificates to using a CA given as a variable
platforms:
- name: Centos8
versions:
- all

license: MIT

min_ansible_version: 2.1

dependencies: []
50 changes: 50 additions & 0 deletions roles/certificates/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---
- name: Ensure cryptography Package Installed
pip:
name: cryptography>=1.6
state: present
extra_args: "--only-binary :all:"

- name: Generate private key
community.crypto.openssl_privatekey_pipe:
size: 2048
register: host_private_key

- name: Create certificate signing request (CSR) for new certificate
community.crypto.openssl_csr_pipe:
privatekey_content: "{{ host_private_key.privatekey }}"
common_name: "{{ ansible_fqdn }}"
subject_alt_name: >
{{
[ 'DNS:localhost', 'IP:' + inventory_hostname, 'DNS:' + ansible_fqdn ] +
( subject_alt_names | default('') | split(',') | select('match', '.+') )
}}
subject_alt_name_critical: true
organization_name: "{{ organization_details.name }}"
locality_name: "{{ organization_details.locality }}"
country_name: "{{ organization_details.country }}"
register: host_csr

- name: Sign the CSR using the CA
community.crypto.x509_certificate_pipe:
csr_content: "{{ host_csr.csr }}"
provider: ownca
ownca_path: /etc/ca/ca.crt
ownca_privatekey_path: /etc/ca/private/ca.key
ownca_not_before: "-1d"
ownca_not_after: +365d
register: host_crt
delegate_to: localhost

- name: Ensure /etc/ssl/private directory exists
file:
path: /etc/ssl/private/
state: directory
mode: 0744

- name: Assemble private key and certificate into PEM file
copy:
content: "{{ host_private_key.privatekey }}{{ host_crt.certificate }}"
dest: /etc/ssl/private/server.pem
mode: 0644
notify: "{{ handler_to_notify }}"
5 changes: 5 additions & 0 deletions roles/haproxy/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
# defaults file for haproxy
keepalived_ip: 192.168.0.6
keepalived_subnet: 28
keepalived_auth_pass: "1111"
10 changes: 10 additions & 0 deletions roles/haproxy/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
- name: Restart HAProxy
service:
name: haproxy
state: restarted

- name: Restart Keepalived
service:
name: keepalived
state: restarted
14 changes: 14 additions & 0 deletions roles/haproxy/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
galaxy_info:
role_name: haproxy
author: Yoav Katz
description: Creating haproxy with keepalived configuration that passes requests to webserver host group
platforms:
- name: Centos8
versions:
- all

license: MIT

min_ansible_version: 2.1

dependencies: ['certificates']
27 changes: 27 additions & 0 deletions roles/haproxy/tasks/keepalived.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
- name: Validate all keepalived host vars exists
assert:
that:
- keepalived_state in ['MASTER', 'BACKUP']
- keepalived_priority is number
fail_msg: "to configure Keepalived all hosts hosting it needs: keepalived_state and keepalived_priority"

- name: Ensure Keepalived is installed.
dnf:
name: keepalived
state: present

- name: Generate Keepalived configuration
template:
src: keepalived.conf.j2
dest: /etc/keepalived/keepalived.conf
validate: keepalived -t -f %s
mode: 0644
owner: haproxy
group: haproxy
notify: Restart Keepalived

- name: Ensure Keepalive service is enabled
service:
name: keepalived
state: started
enabled: true
25 changes: 25 additions & 0 deletions roles/haproxy/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
- name: Ensure HAProxy is installed.
dnf:
name: haproxy
state: present

- name: Generate HAProxy configuration
template:
src: haproxy.cfg.j2
dest: /etc/haproxy/haproxy.cfg
validate: haproxy -c -f %s
mode: 0644
owner: haproxy
group: haproxy
notify: Restart HAProxy

- name: Ensure HAProxy service is enabled
service:
name: haproxy
state: started
enabled: true

- name: Generate keepalived
import_tasks:
file: keepalived.yml
32 changes: 32 additions & 0 deletions roles/haproxy/templates/haproxy.cfg.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
global
log /dev/log local0 info
user haproxy
group haproxy
daemon
maxconn 4000
tune.ssl.default-dh-param 2048

defaults
log global
option dontlognull
mode http
timeout connect 5000
timeout client 50000
timeout server 50000

frontend ha-front-ssl
bind *:443 ssl crt /etc/ssl/private/server.pem
mode tcp
option tcplog
http-request set-header X-Forwarded-For %[src]
http-request add-header X-Forwarded-Proto https
option http-server-close
{% for server in groups['webserver'] %}
acl url_{{ hostvars[server].ansible_nodename }} hdr(host) -i {{ hostvars[server].ansible_fqdn }}
use_backend be_{{ hostvars[server].ansible_nodename }} if url_{{ hostvars[server].ansible_nodename }}
{% endfor %}

{% for server in groups['webserver'] %}
backend be_{{ hostvars[server].ansible_nodename }}
server {{ hostvars[server].ansible_nodename }} {{ hostvars[server].inventory_hostname }}:443 ssl verify required ca-file /etc/pki/ca-trust/source/anchors/root-CA.crt check
{% endfor %}
Loading