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

Bugfix/provision stack #5

Open
wants to merge 6 commits into
base: master
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
.vagrant/
.vscode
*.log
**.log**
kubectl
63 changes: 39 additions & 24 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -1,40 +1,55 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :

# Definição das VMs e suas configurações
vms = {
"cicd" => {"memory"=>"1536", "cpus"=>"1", "ip" => "10" , "disk" => "40GB" , 'box' => 'ubuntu/focal64', 'provision' => 'provision/ansible/cicd.yaml'},
"cicd-tools" => {"memory"=>"3072", "cpus"=>"1", "ip" => "20" , "disk" => "40GB" , 'box' => 'ubuntu/focal64', 'provision' => 'provision/ansible/cicd-tools.yaml'},
"k3s" => {"memory"=>"2048" , "cpus"=>"2", "ip" => "30" , "disk" => "60GB" , 'box' => 'ubuntu/focal64', 'provision' => 'provision/ansible/k3s.yaml' },
"gitlab-ci" => {"memory"=>"3072" , "cpus"=>"2", "ip" => "40" , "disk" => "80GB" , 'box' => 'ubuntu/focal64', 'provision' => 'provision/ansible/gitlab-ci.yaml' }

"cicd" => { "memory" => "2048", "cpus" => "1", "ip" => "10", "disk" => "40GB", "box" => "generic/ubuntu2204", "provision" => "provision/ansible/cicd.yaml" },
"cicd-tools" => { "memory" => "4096", "cpus" => "1", "ip" => "20", "disk" => "40GB", "box" => "generic/ubuntu2204", "provision" => "provision/ansible/cicd-tools.yaml" },
"k3s" => { "memory" => "2048", "cpus" => "2", "ip" => "30", "disk" => "60GB", "box" => "generic/ubuntu2204", "provision" => "provision/ansible/k3s.yaml" },
"gitlab-ci" => { "memory" => "3072", "cpus" => "2", "ip" => "40", "disk" => "80GB", "box" => "generic/ubuntu2204", "provision" => "provision/ansible/gitlab-ci.yaml" }
}

Vagrant.configure("2") do |config|
required_plugins = %w( vagrant-vbguest vagrant-disksize )
_retry = false
required_plugins.each do |plugin|
unless Vagrant.has_plugin? plugin
system "vagrant plugin install #{plugin}"
_retry=true
end
# Configuração de plugins obrigatórios
required_plugins = %w(vagrant-vbguest vagrant-disksize)

# Verificação e instalação de plugins obrigatórios
required_plugins.each do |plugin|
unless Vagrant.has_plugin?(plugin)
system("vagrant plugin install #{plugin}")
end

end

# Configuração principal do Vagrant
Vagrant.configure("2") do |config|

# Compartilhamento da pasta "provision" com a VM, usando o caminho absoluto do host
# Substitua 'D:/Devops-Projects/CI_CD/provision' pelo caminho correto do seu sistema
config.vm.synced_folder "D:/Devops-Projects/CI_CD/provision", "/vagrant/provision"

# Configurações específicas para cada VM
vms.each do |name, conf|
config.vbguest.iso_path = "https://download.virtualbox.org/virtualbox/7.0.8/VBoxGuestAdditions_7.0.8.iso"
#config.disksize.size = "50GB"
config.vm.define "#{name}" do |k|
k.vm.box = "#{conf['box']}"
k.vm.hostname = "#{name}"
k.vm.disk :disk, size: conf['disk'], primary: true
k.vm.network 'private_network', ip: "192.168.88.#{conf['ip']}"
k.vm.provider 'virtualbox' do |vb|
config.vm.define name do |vm_config|

# Definindo a box e hostname
vm_config.vm.box = conf['box']
vm_config.vm.hostname = name

# Configurando disco e rede
vm_config.vm.disk :disk, size: conf['disk'], primary: true
vm_config.vm.network 'private_network', ip: "192.168.88.#{conf['ip']}"

# Configurando o provedor (VirtualBox)
vm_config.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']}"

# Configuração do Ansible Local provisioner
vm_config.vm.provision 'ansible_local' do |ansible|
ansible.playbook = "/vagrant/#{conf['provision']}"
ansible.compatibility_mode = '2.0'
end

end
end
end
50 changes: 31 additions & 19 deletions provision/ansible/cicd-tools.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
become: yes
become_user: root
become_method: sudo
vars:
ssh_public_key: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDbC7fGQkGTjXERSAwLq7co5QXvahoXdG93m/Zx/+W1v+eme1ZohTCyi41MkcAJDr2KHSibwo6PE7WWjgYFAsZg/PNE6igI0D5VzC63T48tsK6ffxGFYy3rl0B/VyvHdfqe/vcw44zn6HRjF2q01DXV2NeSBZuJL+diclAcB+2jhrjha9iHWxxkJuxwFl76bAfhVdtNE6yC0It+aUtJLPT1ppcviGKpIyN1w6pGvWxk1pV+Pf6CdqU1FK05FeSPK+f34bSgIOin/DCNN6oBFgX2V5H/+Gf290bmlT9YGVSNZ0Y/HCK3Cetl3A+1j4YtbyANA3ju5mWeKeG8svzfphVRuOlKtwL+pVSrcnJuLIJqf4Nsq3PBAaPt9xzHk5vkmVfaMftQU0OXrgYhP2455SuuhpJe4LG3uyncRAXCK1AX7OoDI5jY6C4pZM00Vv+FOu5BYZLn28vr73B/rHBMzjnOCiouLbrYiCSL9VGtLcPTx4haoTWbm7fZSakyUhITI6M= alissonoliveira@ALISSON"

tasks:
- name: Garantindo /etc/hosts
lineinfile:
Expand All @@ -20,6 +23,26 @@
shell: /bin/bash
password : $1$QbUARykG$p2nthVG8AkDvabKPHwboa1

- name: Criar usuário Devops
user:
name: "devops"
shell: /bin/bash
home: "/home/devops"
state: present
createhome: yes

- name: Garantir que o usuário devops pode usar sudo sem senha
lineinfile:
path: /etc/sudoers
line: 'devops ALL=(ALL) NOPASSWD:ALL'
validate: '/usr/sbin/visudo -cf %s'

- name: Adicionar chave pública ao arquivo authorized_keys
authorized_key:
user: devops
state: present
key: "{{ ssh_public_key }}"

- name: Instala pacotes que permitem que o apt seja usado sobre HTTPS
apt:
name: "{{ packages }}"
Expand All @@ -37,26 +60,15 @@
- vim
- python3-docker

- name: Adiciona uma chave de assinatura apt para o Docker
apt_key:
url: https://download.docker.com/linux/ubuntu/gpg
state: present

- name: Adiciona repositorio apt para versao estavel
apt_repository:
repo: deb [arch=amd64] https://download.docker.com/linux/ubuntu xenial stable
state: present
- name: Faz o download do script para instalação do Docker
get_url:
url: https://get.docker.com/
dest: /tmp/get_docker.sh
mode: '0755'

- name: Instala o Docker e suas dependencias
apt:
name: "{{ packages }}"
state: present
update_cache: yes
vars:
packages:
- docker-ce
- docker-ce-cli
- containerd.io
- name: Executa o script para instalação do Docker
shell: "sh /tmp/get_docker.sh"


- name: create .bash.rc
copy:
Expand Down
87 changes: 49 additions & 38 deletions provision/ansible/cicd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
become: yes
become_user: root
become_method: sudo
vars:
ssh_public_key: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDbC7fGQkGTjXERSAwLq7co5QXvahoXdG93m/Zx/+W1v+eme1ZohTCyi41MkcAJDr2KHSibwo6PE7WWjgYFAsZg/PNE6igI0D5VzC63T48tsK6ffxGFYy3rl0B/VyvHdfqe/vcw44zn6HRjF2q01DXV2NeSBZuJL+diclAcB+2jhrjha9iHWxxkJuxwFl76bAfhVdtNE6yC0It+aUtJLPT1ppcviGKpIyN1w6pGvWxk1pV+Pf6CdqU1FK05FeSPK+f34bSgIOin/DCNN6oBFgX2V5H/+Gf290bmlT9YGVSNZ0Y/HCK3Cetl3A+1j4YtbyANA3ju5mWeKeG8svzfphVRuOlKtwL+pVSrcnJuLIJqf4Nsq3PBAaPt9xzHk5vkmVfaMftQU0OXrgYhP2455SuuhpJe4LG3uyncRAXCK1AX7OoDI5jY6C4pZM00Vv+FOu5BYZLn28vr73B/rHBMzjnOCiouLbrYiCSL9VGtLcPTx4haoTWbm7fZSakyUhITI6M= alissonoliveira@ALISSON"

tasks:
- name: Garantindo /etc/hosts
lineinfile:
Expand All @@ -20,6 +23,26 @@
shell: /bin/bash
password : $1$QbUARykG$p2nthVG8AkDvabKPHwboa1

- name: Criar usuário Devops
user:
name: "devops"
shell: /bin/bash
home: "/home/devops"
state: present
createhome: yes

- name: Garantir que o usuário devops pode usar sudo sem senha
lineinfile:
path: /etc/sudoers
line: 'devops ALL=(ALL) NOPASSWD:ALL'
validate: '/usr/sbin/visudo -cf %s'

- name: Adicionar chave pública ao arquivo authorized_keys
authorized_key:
user: devops
state: present
key: "{{ ssh_public_key }}"

- name: Adiciona usuario jenkins
user:
name: jenkins
Expand All @@ -42,27 +65,15 @@
- vim
- python3-docker

- name: Adiciona uma chave de assinatura apt para o Docker
apt_key:
url: https://download.docker.com/linux/ubuntu/gpg
state: present
- name: Faz o download do script para instalação do Docker
get_url:
url: https://get.docker.com/
dest: /tmp/get_docker.sh
mode: '0755'

- name: Adiciona repositorio apt para versao estavel
apt_repository:
repo: deb [arch=amd64] https://download.docker.com/linux/ubuntu xenial stable
state: present

- name: Instala o Docker e suas dependencias
apt:
name: "{{ packages }}"
state: present
update_cache: yes
vars:
packages:
- docker-ce
- docker-ce-cli
- containerd.io
- docker-compose
- name: Executa o script para instalação do Docker
shell: "sh /tmp/get_docker.sh"


- name: Criando o arquivo daemon.json
copy:
Expand All @@ -78,25 +89,26 @@
daemon_reload: yes
state: restarted

- name: Adiciona uma chave de assinatura apt para o Kubernetes
apt_key:
url: https://packages.cloud.google.com/apt/doc/apt-key.gpg
state: present
- name: Baixar e instalar kubectl
shell: |
echo "Baixando o kubectl"
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
echo "Tornando kubectl executável"
chmod +x kubectl
echo "Movendo kubectl para /usr/local/bin"
mv kubectl /usr/local/bin/
args:
chdir: /tmp # Define o diretório de trabalho para evitar problemas de caminho

- name: Adiciona repositorio apt para Kubernetes
apt_repository:
repo: deb https://apt.kubernetes.io/ kubernetes-xenial main
state: present
filename: kubernetes.list
- name: Verificar se kubectl está instalado
command: kubectl version --client
register: kubectl_version
failed_when: kubectl_version.rc != 0
changed_when: False

- name: Instala os pacotes do Kubernetes
apt:
name: "{{ packages }}"
state: present
update_cache: yes
vars:
packages:
- kubectl=1.25.4-00
- name: Exibir versão do kubectl
debug:
msg: "kubectl version: {{ kubectl_version.stdout }}"

- name: /var/lib/jenkins/.kube
file:
Expand All @@ -105,4 +117,3 @@
owner: jenkins
group: jenkins


50 changes: 31 additions & 19 deletions provision/ansible/gitlab-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
become: yes
become_user: root
become_method: sudo
vars:
ssh_public_key: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDbC7fGQkGTjXERSAwLq7co5QXvahoXdG93m/Zx/+W1v+eme1ZohTCyi41MkcAJDr2KHSibwo6PE7WWjgYFAsZg/PNE6igI0D5VzC63T48tsK6ffxGFYy3rl0B/VyvHdfqe/vcw44zn6HRjF2q01DXV2NeSBZuJL+diclAcB+2jhrjha9iHWxxkJuxwFl76bAfhVdtNE6yC0It+aUtJLPT1ppcviGKpIyN1w6pGvWxk1pV+Pf6CdqU1FK05FeSPK+f34bSgIOin/DCNN6oBFgX2V5H/+Gf290bmlT9YGVSNZ0Y/HCK3Cetl3A+1j4YtbyANA3ju5mWeKeG8svzfphVRuOlKtwL+pVSrcnJuLIJqf4Nsq3PBAaPt9xzHk5vkmVfaMftQU0OXrgYhP2455SuuhpJe4LG3uyncRAXCK1AX7OoDI5jY6C4pZM00Vv+FOu5BYZLn28vr73B/rHBMzjnOCiouLbrYiCSL9VGtLcPTx4haoTWbm7fZSakyUhITI6M= alissonoliveira@ALISSON"

tasks:
- name: Garantindo /etc/hosts
lineinfile:
Expand All @@ -19,6 +22,26 @@
name: suporte
shell: /bin/bash
password : $1$QbUARykG$p2nthVG8AkDvabKPHwboa1
- name: Criar usuário Devops
user:
name: "devops"
shell: /bin/bash
home: "/home/devops"
state: present
createhome: yes

- name: Garantir que o usuário devops pode usar sudo sem senha
lineinfile:
path: /etc/sudoers
line: 'devops ALL=(ALL) NOPASSWD:ALL'
validate: '/usr/sbin/visudo -cf %s'

- name: Adicionar chave pública ao arquivo authorized_keys
authorized_key:
user: devops
state: present
key: "{{ ssh_public_key }}"


- name: Instala pacotes que permitem que o apt seja usado sobre HTTPS
apt:
Expand All @@ -37,26 +60,15 @@
- vim
- python3-docker

- name: Adiciona uma chave de assinatura apt para o Docker
apt_key:
url: https://download.docker.com/linux/ubuntu/gpg
state: present

- name: Adiciona repositorio apt para versao estavel
apt_repository:
repo: deb [arch=amd64] https://download.docker.com/linux/ubuntu xenial stable
state: present
- name: Faz o download do script para instalação do Docker
get_url:
url: https://get.docker.com/
dest: /tmp/get_docker.sh
mode: '0755'

- name: Instala o Docker e suas dependencias
apt:
name: "{{ packages }}"
state: present
update_cache: yes
vars:
packages:
- docker-ce
- docker-ce-cli
- containerd.io
- name: Executa o script para instalação do Docker
shell: "sh /tmp/get_docker.sh"


- name: Criando o arquivo daemon.json
copy:
Expand Down
Loading