2024-09-18 12:10:57 +00:00
|
|
|
- name: Install Stack Orchestrator if it isn't present
|
|
|
|
import_playbook: ../stack-orchestrator-setup/setup-laconic-so.yml
|
|
|
|
|
|
|
|
- name: Setup k8s
|
|
|
|
hosts: "{{ target_host }}"
|
|
|
|
|
2024-09-19 13:21:20 +00:00
|
|
|
environment:
|
|
|
|
PATH: "{{ ansible_env.PATH }}:/home/{{ansible_user}}/.local/bin"
|
|
|
|
VAULT_KEY: "{{ vault_passphrase }}"
|
|
|
|
|
2024-09-18 13:35:37 +00:00
|
|
|
vars_files:
|
2024-09-23 09:08:49 +00:00
|
|
|
- vars/k8s-vars.yml
|
|
|
|
- vars/dns-vars.yml
|
2024-09-18 12:10:57 +00:00
|
|
|
|
|
|
|
tasks:
|
|
|
|
- name: Install Python and pip
|
|
|
|
apt:
|
|
|
|
name: "{{ item }}"
|
|
|
|
state: present
|
|
|
|
become: true
|
|
|
|
loop:
|
|
|
|
- python3
|
|
|
|
- python3-pip
|
|
|
|
|
|
|
|
- name: Install Ansible on remote host
|
|
|
|
pip:
|
|
|
|
name: ansible
|
|
|
|
extra_args: --user
|
|
|
|
when: target_host != "localhost"
|
|
|
|
|
|
|
|
- name: Ensure ~/.local/bin is in PATH in .bashrc
|
|
|
|
lineinfile:
|
|
|
|
path: ~/.bashrc
|
|
|
|
line: 'export PATH="$HOME/.local/bin:$PATH"'
|
|
|
|
state: present
|
|
|
|
create: yes
|
2024-09-18 13:35:37 +00:00
|
|
|
|
2024-09-23 13:29:16 +00:00
|
|
|
- name: Ensure ~/.local/bin is in PATH in .zshrc
|
|
|
|
lineinfile:
|
|
|
|
path: ~/.zshrc
|
|
|
|
line: 'export PATH="$HOME/.local/bin:$PATH"'
|
|
|
|
state: present
|
|
|
|
create: yes
|
|
|
|
|
2024-09-18 13:35:37 +00:00
|
|
|
- name: Clone the service provider template repo
|
|
|
|
git:
|
|
|
|
repo: "https://git.vdb.to/cerc-io/service-provider-template.git"
|
|
|
|
dest: "{{ ansible_env.HOME }}/service-provider-template"
|
|
|
|
|
|
|
|
- name: Update .vault/vault-keys file
|
|
|
|
lineinfile:
|
|
|
|
path: "service-provider-template/.vault/vault-keys"
|
|
|
|
regexp: '^.*$'
|
|
|
|
line: "{{ gpg_key_id }}"
|
|
|
|
create: yes
|
|
|
|
|
|
|
|
- name: Start GPG agent
|
|
|
|
command: gpg-agent --daemon
|
|
|
|
ignore_errors: yes
|
|
|
|
|
|
|
|
- name: Set VAULT_KEY environment variable
|
|
|
|
shell: export VAULT_KEY='{{ vault_passphrase }}'
|
|
|
|
|
|
|
|
- name: Run vault-rekey.sh
|
|
|
|
expect:
|
|
|
|
command: bash .vault/vault-rekey.sh
|
|
|
|
responses:
|
|
|
|
"Enter passphrase:": "{{ vault_passphrase }}"
|
2024-09-23 13:29:16 +00:00
|
|
|
environment:
|
|
|
|
VAULT_KEY='{{ vault_passphrase }}'
|
2024-09-18 13:35:37 +00:00
|
|
|
args:
|
|
|
|
chdir: "service-provider-template"
|
2024-09-19 06:59:13 +00:00
|
|
|
|
|
|
|
- name: Ensure the target directory exists
|
|
|
|
file:
|
|
|
|
path: "{{ ansible_env.HOME }}/service-provider-template"
|
|
|
|
state: directory
|
|
|
|
mode: '0755'
|
|
|
|
|
|
|
|
- name: Change directory name in group_vars
|
|
|
|
command: mv lcn_cad {{ org_id }}_{{ location_id }}
|
|
|
|
args:
|
|
|
|
chdir: "{{ ansible_env.HOME }}/service-provider-template/group_vars"
|
|
|
|
|
|
|
|
- name: Change control directory name in host_vars
|
|
|
|
command: mv lcn-cad-cluster-control {{ org_id }}-{{ location_id }}-cluster-control
|
|
|
|
args:
|
|
|
|
chdir: "{{ ansible_env.HOME }}/service-provider-template/host_vars"
|
|
|
|
|
|
|
|
- name: Change daemon directory name in host_vars
|
|
|
|
command: mv lcn-daemon {{ org_id }}-daemon
|
|
|
|
args:
|
|
|
|
chdir: "{{ ansible_env.HOME }}/service-provider-template/host_vars"
|
|
|
|
|
2024-09-20 06:45:14 +00:00
|
|
|
- name: Copy control-firewalld.yml to the remote VM
|
2024-09-19 06:59:13 +00:00
|
|
|
template:
|
|
|
|
src: ./templates/control-firewalld.yml.j2
|
|
|
|
dest: "{{ ansible_env.HOME }}/service-provider-template/host_vars/{{ org_id }}-{{ location_id }}-cluster-control/firewalld.yml"
|
|
|
|
|
2024-09-20 06:45:14 +00:00
|
|
|
- name: Copy daemon-firewalld.yml to the remote VM
|
2024-09-19 06:59:13 +00:00
|
|
|
template:
|
|
|
|
src: ./templates/daemon-firewalld.yml.j2
|
|
|
|
dest: "{{ ansible_env.HOME }}/service-provider-template/host_vars/{{ org_id }}-daemon/firewalld.yml"
|
|
|
|
|
2024-09-20 06:45:14 +00:00
|
|
|
- name: Copy nginx.yml to the remote VM
|
2024-09-19 06:59:13 +00:00
|
|
|
template:
|
|
|
|
src: ./templates/nginx.yml.j2
|
|
|
|
dest: "{{ ansible_env.HOME }}/service-provider-template/host_vars/{{ org_id }}-daemon/nginx.yml"
|
|
|
|
|
2024-09-20 06:45:14 +00:00
|
|
|
- name: Copy hosts file to the remote VM
|
2024-09-19 06:59:13 +00:00
|
|
|
template:
|
|
|
|
src: ./templates/hosts.j2
|
|
|
|
dest: "{{ ansible_env.HOME }}/service-provider-template/hosts"
|
|
|
|
|
2024-09-20 06:45:14 +00:00
|
|
|
- name: Copy k8s.yml to the remote VM
|
2024-09-19 06:59:13 +00:00
|
|
|
template:
|
|
|
|
src: ./templates/k8s.yml.j2
|
|
|
|
dest: "{{ ansible_env.HOME }}/service-provider-template/group_vars/{{ org_id }}_{{ location_id }}/k8s.yml"
|
|
|
|
|
2024-09-20 06:45:14 +00:00
|
|
|
- name: Copy wildcard-pwa-example.yml to the remote VM
|
2024-09-19 06:59:13 +00:00
|
|
|
template:
|
|
|
|
src: ./templates/wildcard-pwa-example.yml.j2
|
2024-09-19 13:21:20 +00:00
|
|
|
dest: "{{ ansible_env.HOME }}/service-provider-template/files/manifests/wildcard-pwa-{{dns_domain}}.yaml"
|
2024-09-19 06:59:13 +00:00
|
|
|
|
|
|
|
- name: Delete old wildcard-pwa file
|
|
|
|
file:
|
|
|
|
path: "{{ ansible_env.HOME }}/service-provider-template/files/manifests/wildcard-pwa-laconic.yaml"
|
|
|
|
state: absent
|
2024-09-19 13:21:20 +00:00
|
|
|
|
|
|
|
- name: Install required ansible roles
|
|
|
|
shell: ansible-galaxy install -f -p roles -r roles/requirements.yml
|
|
|
|
args:
|
|
|
|
chdir: "{{ ansible_env.HOME }}/service-provider-template"
|
|
|
|
|
|
|
|
- name: Install Kubernetes helper tools
|
|
|
|
shell: ./roles/k8s/files/scripts/get-kube-tools.sh
|
|
|
|
args:
|
|
|
|
chdir: "{{ ansible_env.HOME }}/service-provider-template"
|
|
|
|
become: yes
|
|
|
|
|
|
|
|
- name: Update group_vars/all/vault.yml with support email using template
|
|
|
|
template:
|
|
|
|
src: ./templates/vault.yml.j2
|
|
|
|
dest: "{{ ansible_env.HOME }}/service-provider-template/group_vars/all/vault.yml"
|
|
|
|
|
|
|
|
- name: Base64 encode DigitalOcean token
|
|
|
|
set_fact:
|
|
|
|
b64_encoded_token: "{{ do_api_token | b64encode }}"
|
|
|
|
|
|
|
|
- name: Update secret-digitalocean-dns.yaml with encoded token
|
|
|
|
template:
|
|
|
|
src: ./templates/secret-digitalocean-dns.yml.j2
|
|
|
|
dest: "{{ ansible_env.HOME }}/service-provider-template/files/manifests/secret-digitalocean-dns.yaml"
|
|
|
|
vars:
|
|
|
|
b64_encoded_token: "{{ b64_encoded_token }}"
|
|
|
|
|
|
|
|
- name: Remove k8s-vault.yml file
|
|
|
|
file:
|
|
|
|
path: "{{ ansible_env.HOME }}/service-provider-template/group_vars/{{ org_id }}_{{ location_id }}/k8s-vault.yml"
|
|
|
|
state: absent
|
|
|
|
|
|
|
|
- name: Generate token for the cluster
|
|
|
|
command: ./roles/k8s/files/scripts/token-vault.sh ./group_vars/{{ org_id }}_{{ location_id }}/k8s-vault.yml
|
|
|
|
args:
|
|
|
|
chdir: "{{ ansible_env.HOME }}/service-provider-template"
|
|
|
|
|
|
|
|
- name: Configure firewalld and nginx
|
|
|
|
command: ansible-playbook -i hosts site.yml --tags=firewalld,nginx
|
|
|
|
args:
|
|
|
|
chdir: "{{ ansible_env.HOME }}/service-provider-template"
|
|
|
|
|
|
|
|
- name: Install Stack Orchestrator
|
2024-09-23 13:29:16 +00:00
|
|
|
command: ansible-playbook -i hosts site.yml --tags=so --limit=so --user so
|
2024-09-19 13:21:20 +00:00
|
|
|
args:
|
|
|
|
chdir: "{{ ansible_env.HOME }}/service-provider-template"
|
|
|
|
|
|
|
|
- name: Deploy Kubernetes
|
2024-09-23 13:29:16 +00:00
|
|
|
command: ansible-playbook -i hosts site.yml --tags=k8s --limit={{ org_id }}_{{ location_id }} --user so
|
2024-09-19 13:21:20 +00:00
|
|
|
args:
|
|
|
|
chdir: "{{ ansible_env.HOME }}/service-provider-template"
|