diff --git a/Vagrantfile b/Vagrantfile index 0dfcdbd..319d45a 100755 --- a/Vagrantfile +++ b/Vagrantfile @@ -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| @@ -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 diff --git a/provision/ansible/ansible-server.yaml b/provision/ansible/ansible-server.yaml index 208b383..6ff688f 100755 --- a/provision/ansible/ansible-server.yaml +++ b/provision/ansible/ansible-server.yaml @@ -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: diff --git a/provision/ansible/files/modulos/1-docker.yaml b/provision/ansible/files/modulos/1-docker.yaml index 836a556..9412b69 100644 --- a/provision/ansible/files/modulos/1-docker.yaml +++ b/provision/ansible/files/modulos/1-docker.yaml @@ -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 diff --git a/provision/ansible/files/playbooks/1-adduser.yaml b/provision/ansible/files/playbooks/1-adduser.yaml index 97e490d..7294de4 100644 --- a/provision/ansible/files/playbooks/1-adduser.yaml +++ b/provision/ansible/files/playbooks/1-adduser.yaml @@ -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/ diff --git a/provision/ansible/files/playbooks/2-install-ntpdate.yaml b/provision/ansible/files/playbooks/2-install-ntpdate.yaml index 74b0a98..6b197a9 100644 --- a/provision/ansible/files/playbooks/2-install-ntpdate.yaml +++ b/provision/ansible/files/playbooks/2-install-ntpdate.yaml @@ -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 + diff --git a/provision/ansible/files/playbooks/3-vars-adduser.yaml b/provision/ansible/files/playbooks/3-vars-adduser.yaml index aea36b5..f417bf4 100644 --- a/provision/ansible/files/playbooks/3-vars-adduser.yaml +++ b/provision/ansible/files/playbooks/3-vars-adduser.yaml @@ -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/ diff --git a/provision/ansible/files/playbooks/4-vars_files-pacotes.yaml b/provision/ansible/files/playbooks/4-vars_files-pacotes.yaml index ffaee3d..84afd44 100644 --- a/provision/ansible/files/playbooks/4-vars_files-pacotes.yaml +++ b/provision/ansible/files/playbooks/4-vars_files-pacotes.yaml @@ -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 diff --git a/provision/ansible/files/playbooks/5-register-ntp.yaml b/provision/ansible/files/playbooks/5-register-ntp.yaml index f712e15..84c84cc 100644 --- a/provision/ansible/files/playbooks/5-register-ntp.yaml +++ b/provision/ansible/files/playbooks/5-register-ntp.yaml @@ -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 diff --git a/provision/ansible/files/playbooks/6-create-dir.yaml b/provision/ansible/files/playbooks/6-create-dir.yaml index 63ca3d7..ea4dadb 100644 --- a/provision/ansible/files/playbooks/6-create-dir.yaml +++ b/provision/ansible/files/playbooks/6-create-dir.yaml @@ -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 diff --git a/provision/ansible/files/playbooks/7-fatos-apache.yaml b/provision/ansible/files/playbooks/7-fatos-apache.yaml index 3f17005..811d819 100644 --- a/provision/ansible/files/playbooks/7-fatos-apache.yaml +++ b/provision/ansible/files/playbooks/7-fatos-apache.yaml @@ -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 diff --git a/provision/ansible/files/playbooks/lineinfile.yaml b/provision/ansible/files/playbooks/lineinfile.yaml new file mode 100644 index 0000000..23a73cf --- /dev/null +++ b/provision/ansible/files/playbooks/lineinfile.yaml @@ -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" + diff --git a/provision/ansible/files/playbooks/uri.yaml b/provision/ansible/files/playbooks/uri.yaml new file mode 100644 index 0000000..4a81623 --- /dev/null +++ b/provision/ansible/files/playbooks/uri.yaml @@ -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 + - '"

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' diff --git a/provision/ansible/files/roles/mysql-server/templates/banco.php.j2 b/provision/ansible/files/roles/mysql-server/templates/banco.php.j2 index aca1197..9b31a72 100644 --- a/provision/ansible/files/roles/mysql-server/templates/banco.php.j2 +++ b/provision/ansible/files/roles/mysql-server/templates/banco.php.j2 @@ -1,5 +1,5 @@ $valor ){//Separa o post em campos e valores @@ -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){ @@ -19,7 +19,7 @@ $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) { @@ -27,7 +27,7 @@ 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){ @@ -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)){ @@ -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 } diff --git a/provision/ansible/files/roles/web-server/templates/banco.php.j2 b/provision/ansible/files/roles/web-server/templates/banco.php.j2 index aca1197..9b31a72 100644 --- a/provision/ansible/files/roles/web-server/templates/banco.php.j2 +++ b/provision/ansible/files/roles/web-server/templates/banco.php.j2 @@ -1,5 +1,5 @@ $valor ){//Separa o post em campos e valores @@ -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){ @@ -19,7 +19,7 @@ $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) { @@ -27,7 +27,7 @@ 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){ @@ -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)){ @@ -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 } diff --git a/provision/ansible/files/site/include/banco.php b/provision/ansible/files/site/include/banco.php index 03af3cb..2cff89c 100644 --- a/provision/ansible/files/site/include/banco.php +++ b/provision/ansible/files/site/include/banco.php @@ -1,5 +1,5 @@ $valor ){//Separa o post em campos e valores @@ -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){ @@ -19,7 +19,7 @@ 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) { @@ -27,7 +27,7 @@ function excluir($tabela, $onde=null) { 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){ @@ -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)){ @@ -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 }