mirror of
https://gitea.fenix-dev.com/fenix-gitea-admin/iac-ansible-private.git
synced 2025-10-27 08:43:05 +00:00
134 lines
2.9 KiB
YAML
134 lines
2.9 KiB
YAML
- name: Instalar pip3 no host remoto
|
|
ansible.builtin.apt:
|
|
name: python3-pip
|
|
state: present
|
|
update_cache: true
|
|
|
|
- name: Instalar ruamel.yaml no host remoto
|
|
ansible.builtin.pip:
|
|
name: ruamel.yaml
|
|
executable: pip3
|
|
|
|
- name: Fazer download do manifest oficial do Flannel
|
|
get_url:
|
|
url: https://raw.githubusercontent.com/flannel-io/flannel/master/Documentation/kube-flannel.yml
|
|
dest: /tmp/kube-flannel.yml
|
|
|
|
- name: Substituir o CIDR da rede no manifest
|
|
replace:
|
|
path: /tmp/kube-flannel.yml
|
|
regexp: '10\.244\.0\.0/16'
|
|
replace: '192.168.3.0/16'
|
|
|
|
- name: Corrigir net-conf.json no manifest do Flannel
|
|
ansible.builtin.script:
|
|
cmd: patch_netconf.py
|
|
|
|
- name: cat flannel
|
|
shell: |
|
|
cat /tmp/kube-flannel.yml
|
|
register: flannel_manifest
|
|
|
|
- name: Mostrar conteúdo do manifest
|
|
debug:
|
|
var: flannel_manifest.stdout
|
|
|
|
- name: Forçar uso da interface correta
|
|
replace:
|
|
path: /tmp/kube-flannel.yml
|
|
regexp: 'command:
|
|
\[.*?flanneld.*?\]
|
|
'
|
|
replace: |
|
|
command:
|
|
- /opt/bin/flanneld
|
|
- --ip-masq
|
|
- --kube-subnet-mgr
|
|
- --iface=eth1
|
|
|
|
|
|
|
|
- name: Inicializar o cluster com kubeadm
|
|
command:
|
|
argv:
|
|
- kubeadm
|
|
- init
|
|
- --pod-network-cidr=192.168.3.0/16
|
|
- --apiserver-advertise-address=192.168.1.150
|
|
- --cri-socket=unix:///run/containerd/containerd.sock
|
|
creates: /etc/kubernetes/admin.conf
|
|
|
|
|
|
|
|
|
|
- name: Verificar se o diretório .kube já existe
|
|
stat:
|
|
path: /home/fenix/.kube
|
|
register: kube_dir
|
|
|
|
|
|
- name: Criar diretório .kube para o usuário ubuntu
|
|
ansible.builtin.file:
|
|
path: /home/fenix/.kube
|
|
state: directory
|
|
owner: fenix
|
|
group: ubuntu
|
|
mode: 0755
|
|
when: not kube_dir.stat.exists
|
|
|
|
- name: Set up kubeconfig for user
|
|
copy:
|
|
src: /etc/kubernetes/admin.conf
|
|
dest: /home/fenix/.kube/config
|
|
remote_src: yes
|
|
owner: fenix
|
|
group: ubuntu
|
|
mode: 0644
|
|
when: not kube_dir.stat.exists
|
|
|
|
- name: 33 Wait for Kubernetes API to be ready
|
|
shell: |
|
|
kubectl get --raw='/healthz'
|
|
environment:
|
|
KUBECONFIG: /home/fenix/.kube/config
|
|
register: api_health
|
|
until: api_health.rc == 0
|
|
retries: 10
|
|
delay: 6
|
|
become: yes
|
|
|
|
- name: cat flannel
|
|
shell: |
|
|
cat /tmp/kube-flannel.yml
|
|
register: flannel_manifest2
|
|
|
|
- name: Mostrar conteúdo do manifest
|
|
debug:
|
|
var: flannel_manifest2.stdout
|
|
|
|
- name: Aplicar o manifest do Flannel
|
|
become: yes
|
|
become_user: fenix
|
|
shell: |
|
|
kubectl apply -f /tmp/kube-flannel.yml
|
|
environment:
|
|
KUBECONFIG: /home/fenix/.kube/config
|
|
|
|
- name: 34 Wait for Kubernetes API to be ready
|
|
shell: |
|
|
kubectl get --raw='/healthz'
|
|
environment:
|
|
KUBECONFIG: /home/fenix/.kube/config
|
|
register: api_health
|
|
until: api_health.rc == 0
|
|
retries: 10
|
|
delay: 6
|
|
become: yes
|
|
|
|
- name: Get kubeadm join command
|
|
shell: kubeadm token create --print-join-command
|
|
register: join_cmd
|
|
|
|
- name: Set join command as fact
|
|
set_fact:
|
|
kubeadm_join_command: "{{ join_cmd.stdout }}" |