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

conteudo tecnico #1

Open
wants to merge 2 commits into
base: main
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
22 changes: 14 additions & 8 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :
## -*- mode: ruby -*-
## vi: set ft=ruby :

VAGRANT_DISABLE_VBOXSYMLINKCREATE=1

vms = {
'ansible-server' => {'memory' => '2560', 'cpus' => 1, 'ip' => '199', 'box' => 'devopsbox/ubuntu-20.04', 'provision' => 'provision/ansible/ansible-server.yaml'},
'balancer' => {'memory' => '768', 'cpus' => 1, 'ip' => '200', 'box' => 'devopsbox/centos-8.5', 'provision' => 'provision/ansible/balancer.yaml'},
'webserver1' => {'memory' => '768', 'cpus' => 1, 'ip' => '201', 'box' => 'devopsbox/ubuntu-20.04', 'provision' => 'provision/ansible/webserver1.yaml'},
'webserver1' => {'memory' => '1024', 'cpus' => 1, 'ip' => '201', 'box' => 'devopsbox/ubuntu-20.04', 'provision' => 'provision/ansible/webserver1.yaml'},
'webserver2' => {'memory' => '768', 'cpus' => 1, 'ip' => '202', 'box' => 'devopsbox/centos-8.5', 'provision' => 'provision/ansible/webserver2.yaml'},
'dbserver' => {'memory' => '768', 'cpus' => 1, 'ip' => '203', 'box' => 'devopsbox/debian-10.11', 'provision' => 'provision/ansible/dbserver.yaml'}
'dbserver' => {'memory' => '768', 'cpus' => 1, 'ip' => '203', 'box' => 'devopsbox/debian-10.11', 'provision' => 'provision/ansible/dbserver.yaml'},
# 'winclient' => {'memory' => '1024', 'cpus' => 1, 'ip' => '204', 'box' => 'devopsbox/windows-10'}
}

Vagrant.configure('2') do |config|
Expand All @@ -20,14 +21,19 @@ Vagrant.configure('2') do |config|
k.vm.box = "#{conf['box']}"
k.vm.hostname = "#{name}"
k.vm.network 'private_network', ip: "172.16.0.#{conf['ip']}"
# if "#{name}" == 'winclient'
# k.vm.communicator = 'winrm'
# end
k.vm.provider 'virtualbox' do |vb|
vb.memory = conf['memory']
vb.cpus = conf['cpus']
end
k.vm.provision 'ansible_local' do |ansible|
ansible.playbook = "#{conf['provision']}"
ansible.compatibility_mode = '2.0'
end
# if "#{name}" != 'winclient'
k.vm.provision 'ansible_local' do |ansible|
ansible.playbook = "#{conf['provision']}"
ansible.compatibility_mode = '2.0'
end
# end
end
end
end
1 change: 1 addition & 0 deletions provision/ansible/ansible-server.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
- 172.16.0.201 webserver1
- 172.16.0.202 webserver2
- 172.16.0.203 dbserver
- 172.16.0.204 winclient

- name: Ajustando /etc/hosts
lineinfile:
Expand Down
30 changes: 15 additions & 15 deletions provision/ansible/files/modulos/1-docker.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
---
- hosts: local
tasks:
- name: Adiciona chave GPG para o repositório oficial do Docker
ansible.builtin.apt_key:
url: https://download.docker.com/linux/ubuntu/gpg
state: present
register: apt_key_add
- name: Adiciona repositório do Docker
when: apt_key_add is succeeded
ansible.builtin.apt_repository:
repo: deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable
state: present
- name: Instala o Docker
apt:
name: docker-ce
state: present
update_cache: true
- name: Adiciona chave GPG para o repositório oficial do Docker
ansible.builtin.apt_key:
url: https://download.docker.com/linux/ubuntu/gpg
state: present
register: apt_key_add
- name: Adiciona repositório do Docker
when: apt_key_add is succeeded
ansible.builtin.apt_repository:
repo: deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable
state: present
- name: Instala o Docker
apt:
name: docker-ce
state: present
update_cache: true
6 changes: 5 additions & 1 deletion provision/ansible/files/playbooks/1-adduser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@
- hosts: local
tasks:
- name: Adicionar usuario helpdesk
user: name=helpdesk state=present shell=/bin/bash password=$1$i5CwO/2J$JIaH55NqG10CDpYLqLAZf/
user:
name: helpdesk
state: present
shell: /bin/bash
password: $1$i5CwO/2J$JIaH55NqG10CDpYLqLAZf/
6 changes: 5 additions & 1 deletion provision/ansible/files/playbooks/2-install-ntpdate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@
- hosts: local
tasks:
- name: Instala pacote ntpdate
apt: name=ntpdate state=present update_cache=true
apt:
name: ntpdate
state: present
update_cache: true

10 changes: 7 additions & 3 deletions provision/ansible/files/playbooks/3-vars-adduser.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
---
- hosts: local
vars:
- usuario: linus
usuario: linus
tasks:
- name: Adicionar usuario
user: name={{ usuario }} state=present shell=/bin/bash password=$1$i5CwO/2J$JIaH55NqG10CDpYLqLAZf/
- name: Adicionar usuario
user:
name: "{{ usuario }}"
state: present
shell: /bin/bash
password: $1$i5CwO/2J$JIaH55NqG10CDpYLqLAZf/
7 changes: 5 additions & 2 deletions provision/ansible/files/playbooks/4-vars_files-pacotes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@
vars_files:
- /home/suporte/playbooks/vars.yml
tasks:
- name: Instala pacotes atraves de variaveis
apt: name={{ pacotes }} state=present update_cache=true
- name: Instala pacotes atraves de variaveis
apt:
name: "{{ pacotes }}"
state: present
update_cache: true
20 changes: 14 additions & 6 deletions provision/ansible/files/playbooks/5-register-ntp.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
---
- hosts: local
tasks:
- name: Instala pacote NTP
apt: name=ntp state=present update_cache=true
register: ntp_installed
- name: Define o arquivo de configuracao do servidor NTP
when: ntp_installed is succeeded
copy: src=/home/suporte/playbooks/ntp.conf dest=/etc/ntp.conf owner=root group=root mode=0644
- name: Instala pacote NTP
apt:
name: ntp
state: present
update_cache: true
register: ntp_installed
- name: Define o arquivo de configuracao do servidor NTP
when: ntp_installed is succeeded
copy:
src: /home/suporte/playbooks/ntp.conf
dest: /etc/ntp.conf
owner: root
group: root
mode: 0644
10 changes: 8 additions & 2 deletions provision/ansible/files/playbooks/6-create-dir.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
---
- hosts: local
tasks:
- name: Adicionar estrutura de diretórios atraves de variavel
file: dest={{ diretorios }} state=directory recurse=yes owner=root group=root mode=775
- name: Adicionar estrutura de diretórios atraves de variavel
file:
dest: "{{ diretorios }}"
state: directory
recurse: yes
owner: root
group: root
mode: 775
21 changes: 13 additions & 8 deletions provision/ansible/files/playbooks/7-fatos-apache.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
---
- hosts: webservers
tasks:
- name: Instala Apache no Debian/Ubuntu
when: ansible_os_family == "Debian"
apt: name=apache2 state=present update_cache=true
register: apache2_installed
- name: Instala Apache no CentOS
when: ansible_os_family == "RedHat"
yum: name=httpd state=present
register: httpd_installed
- name: Instala Apache no Debian/Ubuntu
when: ansible_os_family == "Debian"
apt:
name: apache2
state: present
update_cache: true
register: apache2_installed
- name: Instala Apache no CentOS
when: ansible_os_family == "RedHat"
yum:
name: httpd
state: present
register: httpd_installed

10 changes: 10 additions & 0 deletions provision/ansible/files/playbooks/lineinfile.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
- hosts: local
tasks:
- name: Garantir permissão de superusuário para o usuário helpdesk
lineinfile:
path: /etc/sudoers
state: present
insertafter: "suporte ALL=(ALL) NOPASSWD: ALL"
line: "helpdesk ALL=(ALL) NOPASSWD: ALL"

20 changes: 20 additions & 0 deletions provision/ansible/files/playbooks/uri.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
- hosts: local
gather_facts: no
tasks:
- name: Verificando status da Aplicação Dexter
uri:
url: "http://balancer"
return_content: yes
register: response
- name: Response
debug:
msg: "Aplicação Dexter: [200] OK"
when:
- response.status == 200
- '"<p>A transportadora Dexter Courier" in response.content'
- name: Response
debug:
msg: "Aplicação Dexter: [ERR] Could not connect to mysql"
when: '"Could not connect to mysql" in response.content'
failed_when: '"Could not connect to mysql" in response.content'
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
$link = mysqli_connect ( '{{ database }}', 'admin', '4linux', 'dexter500') or die ("Cloud not connect to mysql");
$link = mysqli_connect ( '{{ database }}', 'admin', '4linux', 'dexter500') or die ("Could not connect to mysql");

function inserir($tabela, $dados){
foreach( $dados as $campo => $valor ){//Separa o post em campos e valores
Expand All @@ -9,7 +9,7 @@
$campos = implode( ",", $campos );//Converte o array em string separando por virgula (Campos)
$valores = implode( ",", $valores );//Converte o array em string separando por virgula (Valores)
$sql = "insert into $tabela ( $campos ) values ( $valores )";
$link = mysqli_connect ( '{{ database }}', 'admin', '4linux', 'dexter500') or die ("Cloud not connect to mysql");
$link = mysqli_connect ( '{{ database }}', 'admin', '4linux', 'dexter500') or die ("Could not connect to mysql");
return mysqli_query( $link, $sql );//Insere o registro no banco
}
function alterar($tabela, $dados, $onde){
Expand All @@ -19,15 +19,15 @@
$sets = implode( ",", $sets );
$sql = "update $tabela set $sets where $onde ";
//die($sql);
$link = mysqli_connect ( '{{ database }}', 'admin', '4linux', 'dexter500') or die ("Cloud not connect to mysql");
$link = mysqli_connect ( '{{ database }}', 'admin', '4linux', 'dexter500') or die ("Could not connect to mysql");
return mysqli_query( $link, $sql );
}
function excluir($tabela, $onde=null) {
$sql = "delete from $tabela";
if( $onde ){
$sql .= " where $onde";
}
$link = mysqli_connect ( '{{ database }}', 'admin', '4linux', 'dexter500') or die ("Cloud not connect to mysql");
$link = mysqli_connect ( '{{ database }}', 'admin', '4linux', 'dexter500') or die ("Could not connect to mysql");
return mysqli_query( $link, $sql );
}
function listar($tabela, $campos = "*", $onde=null, $filtro=null, $ordem=null, $limite=null){
Expand All @@ -48,7 +48,7 @@
$sql .= " limit $limite";
}
$registros = [];
$link = mysqli_connect ( '{{ database }}', 'admin', '4linux', 'dexter500') or die ("Cloud not connect to mysql");
$link = mysqli_connect ( '{{ database }}', 'admin', '4linux', 'dexter500') or die ("Could not connect to mysql");
$query = mysqli_query( $link, $sql );

while($registro = mysqli_fetch_array($query)){
Expand All @@ -59,7 +59,7 @@
}
function ver($tabela, $onde, $campos = "*"){
$sql = "select $campos from $tabela where $onde";
$link = mysqli_connect ( '{{ database }}', 'admin', '4linux', 'dexter500') or die ("Cloud not connect to mysql");
$link = mysqli_connect ( '{{ database }}', 'admin', '4linux', 'dexter500') or die ("Could not connect to mysql");
$query = mysqli_query( $link, $sql ); //prepara a consulta
return mysqli_fetch_array( $query );//determina o tipo de retorno
}
12 changes: 6 additions & 6 deletions provision/ansible/files/roles/web-server/templates/banco.php.j2
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
$link = mysqli_connect ( '{{ database }}', 'admin', '4linux', 'dexter500') or die ("Cloud not connect to mysql");
$link = mysqli_connect ( '{{ database }}', 'admin', '4linux', 'dexter500') or die ("Could not connect to mysql");

function inserir($tabela, $dados){
foreach( $dados as $campo => $valor ){//Separa o post em campos e valores
Expand All @@ -9,7 +9,7 @@
$campos = implode( ",", $campos );//Converte o array em string separando por virgula (Campos)
$valores = implode( ",", $valores );//Converte o array em string separando por virgula (Valores)
$sql = "insert into $tabela ( $campos ) values ( $valores )";
$link = mysqli_connect ( '{{ database }}', 'admin', '4linux', 'dexter500') or die ("Cloud not connect to mysql");
$link = mysqli_connect ( '{{ database }}', 'admin', '4linux', 'dexter500') or die ("Could not connect to mysql");
return mysqli_query( $link, $sql );//Insere o registro no banco
}
function alterar($tabela, $dados, $onde){
Expand All @@ -19,15 +19,15 @@
$sets = implode( ",", $sets );
$sql = "update $tabela set $sets where $onde ";
//die($sql);
$link = mysqli_connect ( '{{ database }}', 'admin', '4linux', 'dexter500') or die ("Cloud not connect to mysql");
$link = mysqli_connect ( '{{ database }}', 'admin', '4linux', 'dexter500') or die ("Could not connect to mysql");
return mysqli_query( $link, $sql );
}
function excluir($tabela, $onde=null) {
$sql = "delete from $tabela";
if( $onde ){
$sql .= " where $onde";
}
$link = mysqli_connect ( '{{ database }}', 'admin', '4linux', 'dexter500') or die ("Cloud not connect to mysql");
$link = mysqli_connect ( '{{ database }}', 'admin', '4linux', 'dexter500') or die ("Could not connect to mysql");
return mysqli_query( $link, $sql );
}
function listar($tabela, $campos = "*", $onde=null, $filtro=null, $ordem=null, $limite=null){
Expand All @@ -48,7 +48,7 @@
$sql .= " limit $limite";
}
$registros = [];
$link = mysqli_connect ( '{{ database }}', 'admin', '4linux', 'dexter500') or die ("Cloud not connect to mysql");
$link = mysqli_connect ( '{{ database }}', 'admin', '4linux', 'dexter500') or die ("Could not connect to mysql");
$query = mysqli_query( $link, $sql );

while($registro = mysqli_fetch_array($query)){
Expand All @@ -59,7 +59,7 @@
}
function ver($tabela, $onde, $campos = "*"){
$sql = "select $campos from $tabela where $onde";
$link = mysqli_connect ( '{{ database }}', 'admin', '4linux', 'dexter500') or die ("Cloud not connect to mysql");
$link = mysqli_connect ( '{{ database }}', 'admin', '4linux', 'dexter500') or die ("Could not connect to mysql");
$query = mysqli_query( $link, $sql ); //prepara a consulta
return mysqli_fetch_array( $query );//determina o tipo de retorno
}
12 changes: 6 additions & 6 deletions provision/ansible/files/site/include/banco.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
$link = mysqli_connect ( '172.16.0.203', 'admin', '4linux', 'dexter500') or die ("Cloud not connect to mysql");
$link = mysqli_connect ( '172.16.0.203', 'admin', '4linux', 'dexter500') or die ("Could not connect to mysql");

function inserir($tabela, $dados){
foreach( $dados as $campo => $valor ){//Separa o post em campos e valores
Expand All @@ -9,7 +9,7 @@ function inserir($tabela, $dados){
$campos = implode( ",", $campos );//Converte o array em string separando por virgula (Campos)
$valores = implode( ",", $valores );//Converte o array em string separando por virgula (Valores)
$sql = "insert into $tabela ( $campos ) values ( $valores )";
$link = mysqli_connect ( '172.16.0.203', 'admin', '4linux', 'dexter500') or die ("Cloud not connect to mysql");
$link = mysqli_connect ( '172.16.0.203', 'admin', '4linux', 'dexter500') or die ("Could not connect to mysql");
return mysqli_query( $link, $sql );//Insere o registro no banco
}
function alterar($tabela, $dados, $onde){
Expand All @@ -19,15 +19,15 @@ function alterar($tabela, $dados, $onde){
$sets = implode( ",", $sets );
$sql = "update $tabela set $sets where $onde ";
//die($sql);
$link = mysqli_connect ( '172.16.0.203', 'admin', '4linux', 'dexter500') or die ("Cloud not connect to mysql");
$link = mysqli_connect ( '172.16.0.203', 'admin', '4linux', 'dexter500') or die ("Could not connect to mysql");
return mysqli_query( $link, $sql );
}
function excluir($tabela, $onde=null) {
$sql = "delete from $tabela";
if( $onde ){
$sql .= " where $onde";
}
$link = mysqli_connect ( '172.16.0.203', 'admin', '4linux', 'dexter500') or die ("Cloud not connect to mysql");
$link = mysqli_connect ( '172.16.0.203', 'admin', '4linux', 'dexter500') or die ("Could not connect to mysql");
return mysqli_query( $link, $sql );
}
function listar($tabela, $campos = "*", $onde=null, $filtro=null, $ordem=null, $limite=null){
Expand All @@ -48,7 +48,7 @@ function listar($tabela, $campos = "*", $onde=null, $filtro=null, $ordem=null, $
$sql .= " limit $limite";
}
$registros = [];
$link = mysqli_connect ( '172.16.0.203', 'admin', '4linux', 'dexter500') or die ("Cloud not connect to mysql");
$link = mysqli_connect ( '172.16.0.203', 'admin', '4linux', 'dexter500') or die ("Could not connect to mysql");
$query = mysqli_query( $link, $sql );

while($registro = mysqli_fetch_array($query)){
Expand All @@ -59,7 +59,7 @@ function listar($tabela, $campos = "*", $onde=null, $filtro=null, $ordem=null, $
}
function ver($tabela, $onde, $campos = "*"){
$sql = "select $campos from $tabela where $onde";
$link = mysqli_connect ( '172.16.0.203', 'admin', '4linux', 'dexter500') or die ("Cloud not connect to mysql");
$link = mysqli_connect ( '172.16.0.203', 'admin', '4linux', 'dexter500') or die ("Could not connect to mysql");
$query = mysqli_query( $link, $sql ); //prepara a consulta
return mysqli_fetch_array( $query );//determina o tipo de retorno
}