103 lines
3.0 KiB
YAML
103 lines
3.0 KiB
YAML
- name: Clone SSH repos, inject private key, build and run container
|
|
hosts: docker_host
|
|
remote_user: ubuntu
|
|
gather_facts: true
|
|
become: yes
|
|
become_method: sudo
|
|
become_user: root
|
|
|
|
vars:
|
|
ansible_remote_tmp: /tmp/.ansible-ubuntu
|
|
main_br: "{{ lookup('env', 'MAIN_BR') | default('main', true) }}"
|
|
env_br: "{{ lookup('env', 'ENV_BR') | default('main', true) }}"
|
|
playbook_file: "{{ lookup('env', 'PLAYBOOK_FILE') | default('base.yaml') }}"
|
|
ssh_private_key: "{{ lookup('env', 'SSH_PRIVATE_KEY') }}"
|
|
|
|
base_dir: "/home/ubuntu"
|
|
repo_core_url: "git@git.felcloud.io:felcloud/ansible_core_init_ansible.git"
|
|
repo_env_url: "git@git.felcloud.io:felcloud/ansible_env_staging.git"
|
|
|
|
repo_core_dir: "{{ base_dir }}/ansible_core_init_ansible"
|
|
repo_env_dir: "{{ base_dir }}/ansible_env_staging"
|
|
|
|
tasks:
|
|
|
|
- name: Write SSH private key to /tmp/deploy_key
|
|
ansible.builtin.copy:
|
|
content: "{{ ssh_private_key }}"
|
|
dest: /tmp/deploy_key
|
|
mode: '0600'
|
|
|
|
- name: Create SSH wrapper script
|
|
ansible.builtin.copy:
|
|
dest: /tmp/ssh_wrapper.sh
|
|
mode: '0755'
|
|
content: |
|
|
#!/bin/sh
|
|
exec ssh -i /tmp/deploy_key -o StrictHostKeyChecking=no -o BatchMode=yes "$@"
|
|
|
|
- name: Remove existing core repo
|
|
ansible.builtin.file:
|
|
path: "{{ repo_core_dir }}"
|
|
state: absent
|
|
|
|
- name: Remove existing env repo
|
|
ansible.builtin.file:
|
|
path: "{{ repo_env_dir }}"
|
|
state: absent
|
|
|
|
- name: Clone core repo via SSH using wrapper
|
|
ansible.builtin.git:
|
|
repo: "{{ repo_core_url }}"
|
|
dest: "{{ repo_core_dir }}"
|
|
version: "{{ main_br }}"
|
|
force: yes
|
|
environment:
|
|
GIT_SSH: /tmp/ssh_wrapper.sh
|
|
|
|
- name: Clone env repo via SSH using wrapper
|
|
ansible.builtin.git:
|
|
repo: "{{ repo_env_url }}"
|
|
dest: "{{ repo_env_dir }}"
|
|
version: "{{ env_br }}"
|
|
force: yes
|
|
environment:
|
|
GIT_SSH: /tmp/ssh_wrapper.sh
|
|
|
|
- name: Inject SSH private key into custom_files/id_rsa (for Docker build)
|
|
ansible.builtin.copy:
|
|
content: "{{ ssh_private_key }}"
|
|
dest: "{{ repo_core_dir }}/custom_files/id_rsa"
|
|
mode: '0600'
|
|
|
|
- name: Build the Docker image from core repo
|
|
community.docker.docker_image:
|
|
name: ansible-pulumi
|
|
tag: local
|
|
source: build
|
|
build:
|
|
path: "{{ repo_core_dir }}"
|
|
args:
|
|
branch: "{{ main_br }}"
|
|
nocache: true
|
|
|
|
- name: Run the admin container
|
|
community.docker.docker_container:
|
|
name: admin-ansible-run
|
|
image: ansible-pulumi:local
|
|
command: bash
|
|
tty: true
|
|
interactive: true
|
|
auto_remove: true
|
|
volumes:
|
|
- "{{ repo_env_dir }}:/home/cloud/ansible_env_staging"
|
|
|
|
- name: Clean up SSH key and wrapper
|
|
ansible.builtin.file:
|
|
path: "{{ item }}"
|
|
state: absent
|
|
loop:
|
|
- /tmp/deploy_key
|
|
- /tmp/ssh_wrapper.sh
|
|
|