test123123

This commit is contained in:
faten 2025-06-02 16:09:06 +00:00
parent 9082135485
commit 18c950d126

View File

@ -1,34 +1,31 @@
- name: Clone SSH repos, inject private key, build and run container - name: Ensure SSH key is present on remote host
hosts: docker_host
gather_facts: false
tasks:
- name: Write SSH private key to /tmp/deploy_key on remote host
ansible.builtin.copy:
content: "{{ lookup('env', 'SSH_PRIVATE_KEY') }}"
dest: "/tmp/deploy_key"
mode: '0600'
- name: Clone repos and run container
hosts: docker_host hosts: docker_host
remote_user: ubuntu remote_user: ubuntu
gather_facts: true
become: yes become: yes
become_method: sudo become_method: sudo
become_user: root become_user: root
vars: vars:
ansible_remote_tmp: /tmp/.ansible-ubuntu
main_br: "{{ lookup('env', 'MAIN_BR') | default('main', true) }}" main_br: "{{ lookup('env', 'MAIN_BR') | default('main', true) }}"
env_br: "{{ lookup('env', 'ENV_BR') | default('main', true) }}" env_br: "{{ lookup('env', 'ENV_BR') | default('main', true) }}"
playbook_file: "{{ lookup('env', 'PLAYBOOK_FILE') | default('base.yaml') }}" playbook_file: "{{ lookup('env', 'PLAYBOOK_FILE') | default('base.yaml') }}"
ssh_private_key: "{{ lookup('env', 'SSH_PRIVATE_KEY') }}"
base_dir: "/home/ubuntu" base_dir: "/home/ubuntu"
deploy_key_path: "/tmp/deploy_key" deploy_key_path: "/tmp/deploy_key"
repo_core_url: "git@git.felcloud.io:felcloud/ansible_core_init_ansible.git" 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_env_url: "git@git.felcloud.io:felcloud/ansible_env_staging.git"
repo_core_dir: "{{ base_dir }}/ansible_core_init_ansible" repo_core_dir: "{{ base_dir }}/ansible_core_init_ansible"
repo_env_dir: "{{ base_dir }}/ansible_env_staging" repo_env_dir: "{{ base_dir }}/ansible_env_staging"
tasks: tasks:
- name: Write SSH private key to file
ansible.builtin.copy:
content: "{{ ssh_private_key }}"
dest: "{{ deploy_key_path }}"
mode: '0600'
- name: Remove existing core repo - name: Remove existing core repo
ansible.builtin.file: ansible.builtin.file:
path: "{{ repo_core_dir }}" path: "{{ repo_core_dir }}"
@ -39,7 +36,7 @@
path: "{{ repo_env_dir }}" path: "{{ repo_env_dir }}"
state: absent state: absent
- name: Clone core repo via SSH using GIT_SSH_COMMAND - name: Clone core repo via SSH
ansible.builtin.git: ansible.builtin.git:
repo: "{{ repo_core_url }}" repo: "{{ repo_core_url }}"
dest: "{{ repo_core_dir }}" dest: "{{ repo_core_dir }}"
@ -48,7 +45,7 @@
environment: environment:
GIT_SSH_COMMAND: "ssh -i {{ deploy_key_path }} -o StrictHostKeyChecking=no -o BatchMode=yes" GIT_SSH_COMMAND: "ssh -i {{ deploy_key_path }} -o StrictHostKeyChecking=no -o BatchMode=yes"
- name: Clone env repo via SSH using GIT_SSH_COMMAND - name: Clone env repo via SSH
ansible.builtin.git: ansible.builtin.git:
repo: "{{ repo_env_url }}" repo: "{{ repo_env_url }}"
dest: "{{ repo_env_dir }}" dest: "{{ repo_env_dir }}"
@ -57,14 +54,14 @@
environment: environment:
GIT_SSH_COMMAND: "ssh -i {{ deploy_key_path }} -o StrictHostKeyChecking=no -o BatchMode=yes" GIT_SSH_COMMAND: "ssh -i {{ deploy_key_path }} -o StrictHostKeyChecking=no -o BatchMode=yes"
- name: Inject SSH private key into custom_files/id_rsa - name: Inject SSH private key into core repo for container use
ansible.builtin.copy: ansible.builtin.copy:
src: "{{ deploy_key_path }}" src: "{{ deploy_key_path }}"
dest: "{{ repo_core_dir }}/custom_files/id_rsa" dest: "{{ repo_core_dir }}/custom_files/id_rsa"
remote_src: yes remote_src: yes
mode: '0600' mode: '0600'
- name: Build the Docker image from core repo - name: Build the Docker image
community.docker.docker_image: community.docker.docker_image:
name: ansible-pulumi name: ansible-pulumi
tag: local tag: local