Skip to content
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
27 changes: 25 additions & 2 deletions Ansible/01_exploring_ansible/Vagrantfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@


# -*- mode: ruby -*-
# vi: set ft=ruby :

Expand All @@ -7,6 +9,24 @@
# you're doing.
Vagrant.configure("2") do |config|

config.vm.define "lb" do |lb|
lb.vm.box = "centos/7"
lb.vm.hostname = "lb"
lb.vm.network "private_network", ip: "192.168.33.200"
lb.vm.provider "virtualbox" do |vb|
vb.customize ["modifyvm", :id, "--memory", "512", "--cpus", "1", "--name", "lb"]
end
lb.vm.provision "ansible" do |ansible|
ansible.playbook = "playbooks/haproxy/loadbalancer.yml"
ansible.extra_vars = {
"web_servers" => [
{"name": "web-1","ip":"192.168.33.11"},
{"name": "web-2","ip":"192.168.33.12"}
]
}
end
end

config.ssh.insert_key = false
(1..2).each do |i|
config.vm.define "web-#{i}" do |web|
Expand All @@ -16,7 +36,11 @@ Vagrant.configure("2") do |config|
web.vm.provider "virtualbox" do |vb|
vb.customize ["modifyvm", :id, "--memory", "512", "--cpus", "1", "--name", "web-#{i}"]
end
web.vm.provision "shell", inline: "echo iam ready"
web.vm.provision "ansible" do |ansible|
ansible.playbook = "playbooks/httpd/webserver.yml"
ansible.groups = {
"webservers" => ["web-#{i}"]
}
end
end

Expand All @@ -27,4 +51,3 @@ Vagrant.configure("2") do |config|
db.vm.provision "shell", inline: "echo Iam DB server"
end
end

8 changes: 8 additions & 0 deletions Ansible/01_exploring_ansible/ansible.cfg.save
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[defaults]
inventory=./ansible_hosts
remote_user=vagrant
private_key_file=$HOME/.vagrant.d/insecure_private_key

[servers]
192.168.33.11
192.168.33.12
4 changes: 4 additions & 0 deletions Ansible/01_exploring_ansible/ansible_hosts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@ web-2 ansible_ssh_host=192.168.33.12

[dbservers]
db ansible_ssh_host=192.168.33.100

[first]
servers
dbservers
8 changes: 6 additions & 2 deletions Ansible/01_exploring_ansible/playbooks/01-ping.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
---
- hosts: all
tasks:
- name: Ping all servers
action: ping
- name: Ping All Servers
action: ping
- debug: msg="Hello"
- hosts: servers
tasks:
- debug: msg="Hello Servers"
20 changes: 20 additions & 0 deletions Ansible/01_exploring_ansible/playbooks/loadbalancer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
- hosts: lb
become: true
tasks:
- name: "install haproxy"
yum:
name:
- haproxy
- name: "configure haproxy"
template:
src: templates/haproxy.j2
dest: /etc/haproxy/haproxy.cfg
owner: root
group: wheel
mode: '0644'
- name: "Restar and enabled haproxy"
service:
name: haproxy
state: restarted
enabled: yes
54 changes: 54 additions & 0 deletions Ansible/04_load_balancer/Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@


# -*- mode: ruby -*-
# vi: set ft=ruby :

# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure("2") do |config|

config.vm.define "lb" do |lb|
lb.vm.box = "centos/7"
lb.vm.hostname = "lb"
lb.vm.network "private_network", ip: "192.168.33.200"
lb.vm.provider "virtualbox" do |vb|
vb.customize ["modifyvm", :id, "--memory", "512", "--cpus", "1", "--name", "lb"]
end
lb.vm.provision "ansible" do |ansible|
ansible.playbook = "playbooks/haproxy/loadbalancer.yml"
ansible.extra_vars = {
"web_servers" => [
{"name": "web-1","ip":"192.168.33.11"},
{"name": "web-2","ip":"192.168.33.12"}
]
}
end
end

config.ssh.insert_key = false
(1..2).each do |i|
config.vm.define "web-#{i}" do |web|
web.vm.box = "centos/7"
web.vm.hostname = "web-#{i}"
web.vm.network "private_network", ip: "192.168.33.1#{i}"
web.vm.provider "virtualbox" do |vb|
vb.customize ["modifyvm", :id, "--memory", "512", "--cpus", "1", "--name", "web-#{i}"]
end
web.vm.provision "ansible" do |ansible|
ansible.playbook = "playbooks/httpd/webserver.yml"
ansible.groups = {
"webservers" => ["web-#{i}"]
}
end
end

config.vm.define "db" do |db|
db.vm.box = "centos/7"
db.vm.hostname = "db"
db.vm.network "private_network", ip: "192.168.33.100"
db.vm.provision "shell", inline: "echo Iam DB server"
end
end
end
9 changes: 9 additions & 0 deletions Ansible/04_load_balancer/playbooks/01-ping.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
- hosts: all
tasks:
- name: Ping All Servers
action: ping
- debug: msg="Hello"
- hosts: servers
tasks:
- debug: msg="Hello Servers"
7 changes: 7 additions & 0 deletions Ansible/04_load_balancer/playbooks/02-shell.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
- hosts: servers
tasks:
- name: Execute Shell Commands
shell: uname
register: uname_result
- debug: msg="{{ uname_result.stdout }}"
9 changes: 9 additions & 0 deletions Ansible/04_load_balancer/playbooks/03-variables.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
- hosts: servers
vars_files:
- variables.yml
vars:
variable1: "PlayBookValue"
tasks:
- name: Variable Value
debug: msg="Value is {{ variable1 }}"
14 changes: 14 additions & 0 deletions Ansible/04_load_balancer/playbooks/04-ansible-facts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
- hosts: servers
tasks:
- name: Kernel
debug: msg="{{ ansible_kernel }}"
- name: Hostname
debug: msg="{{ ansible_hostname }}"
- name: Distribution
debug: msg="{{ ansible_distribution }}"
- debug: var=ansible_architecture
- debug: var=inventory_hostname
- debug: var=groups
- debug: var=group_names
- debug: var=hostvars
10 changes: 10 additions & 0 deletions Ansible/04_load_balancer/playbooks/05-install-httpd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
- hosts: servers
become: true
tasks:
- yum:
name:
- httpd
state: present
- service: name=httpd state=started enabled=yes
- raw: "echo Welcome to Sistemas Distribuidos | sudo tee /var/www/html/index.html"
24 changes: 24 additions & 0 deletions Ansible/04_load_balancer/playbooks/06-conditionals-loops.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
- hosts: servers
vars:
system: "Windows"
color: "Red"
tasks:
# - debug: var=hostvars
- debug: var=ansible_system
- debug: var=color
when: system == 'Linux'
- debug: var=item
with_items:
- item1
- item2
- item3
- item4
- debug: var=item.name
with_items:
- name: Sebastian
country: India
- name: Garcia
country: US
- name: Delgado
country: Netherlands
20 changes: 20 additions & 0 deletions Ansible/04_load_balancer/playbooks/haproxy/loadbalancer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
- hosts: lb
become: true
tasks:
- name: "install haproxy"
yum:
name:
- haproxy
- name: "configure haproxy"
template:
src: templates/haproxy.j2
dest: /etc/haproxy/haproxy.cfg
owner: root
group: wheel
mode: '0644'
- name: "Restar and enabled haproxy"
service:
name: haproxy
state: restarted
enabled: yes
83 changes: 83 additions & 0 deletions Ansible/04_load_balancer/playbooks/haproxy/templates/haproxy.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# example configuration for a possible web application. See the
# full configuration options online.
#
# http://haproxy.1wt.eu/download/1.4/doc/configuration.txt
#
#---------------------------------------------------------------------

#---------------------------------------------------------------------
# Global settings
#---------------------------------------------------------------------
global
# to have these messages end up in /var/log/haproxy.log you will
# need to:
#
# 1) configure syslog to accept network log events. This is done
# by adding the '-r' option to the SYSLOGD_OPTIONS in
# /etc/sysconfig/syslog
#
# 2) configure local2 events to go to the /var/log/haproxy.log
# file. A line like the following can be added to
# /etc/sysconfig/syslog
#
# local2.* /var/log/haproxy.log
#
log 127.0.0.1 local2

chroot /var/lib/haproxy
pidfile /var/run/haproxy.pid
maxconn 4000
user haproxy
group haproxy
daemon

# turn on stats unix socket
stats socket /var/lib/haproxy/stats

#---------------------------------------------------------------------
# common defaults that all the 'listen' and 'backend' sections will
# use if not designated in their block
#---------------------------------------------------------------------
defaults
mode http
log global
option httplog
option dontlognull
option http-server-close
option forwardfor except 127.0.0.0/8
option redispatch
retries 3
timeout http-request 10s
timeout queue 1m
timeout connect 10s
timeout client 1m
timeout server 1m
timeout http-keep-alive 10s
timeout check 10s
maxconn 3000

#---------------------------------------------------------------------
# main frontend which proxys to the backends
#---------------------------------------------------------------------
frontend main *:80
acl url_static path_beg -i /static /images /javascript /stylesheets
acl url_static path_end -i .jpg .gif .png .css .js

use_backend static if url_static
default_backend nodes

#---------------------------------------------------------------------
# static backend for serving up images, stylesheets and such
#---------------------------------------------------------------------
backend static
balance roundrobin
server static 127.0.0.1:4331 check

#---------------------------------------------------------------------
# round robin balancing between the various backends
#---------------------------------------------------------------------
backend nodes
balance roundrobin
{% for server in web_servers %}
server web-{{server.name}} {{server.ip}}:80 check
{% endfor %}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions Ansible/04_load_balancer/playbooks/httpd/templates/index.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Universidad Icesi - Mateo Matta </title>
</head>
<body>
<h1>Hello from {{print_hostname.stdout}}!</h1>
<a href="https://ibb.co/XpCHLh0"><img src="https://i.ibb.co/vmj9q7y/imagen-Html.png" alt="imagen-Html" border="0"></a>
</body>
</html>
22 changes: 22 additions & 0 deletions Ansible/04_load_balancer/playbooks/httpd/webserver.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
- hosts: webservers
become: true
tasks:
- name: "Install httpd"
yum:
name: httpd
- name: "know hostname"
shell: "echo $HOSTNAME"
register: print_hostname
- name: "Configure httpd"
template:
src: templates/index.j2
dest: /var/www/html/index.html
owner: root
group: wheel
mode: '0644'
- name: "start httpd"
service:
name: httpd
state: restarted
enabled: yes
1 change: 1 addition & 0 deletions Ansible/04_load_balancer/playbooks/variables.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
variable1: "Variables YAML Value"