|
| 1 | +--- |
| 2 | +- name: Prepare and create container to start crc-cloud playbook |
| 3 | + hosts: crc-cloud.dev |
| 4 | + tasks: |
| 5 | + # FIXME: change to main repository |
| 6 | + - name: Clone crc-cloud repository |
| 7 | + ansible.builtin.git: |
| 8 | + repo: https://github.com/danpawlik/crc-cloud |
| 9 | + dest: crc-cloud |
| 10 | + version: add-ansible-role |
| 11 | + |
| 12 | + - name: Check if boostrap ssh key exists |
| 13 | + ansible.builtin.stat: |
| 14 | + path: .ssh/crc-cloud-bootstrap.pub |
| 15 | + register: _boostrap_ssh_key |
| 16 | + |
| 17 | + - name: Generate ssh keypair |
| 18 | + when: not _boostrap_ssh_key.stat.exists |
| 19 | + community.crypto.openssh_keypair: |
| 20 | + path: .ssh/crc-cloud-bootstrap |
| 21 | + type: ed25519 |
| 22 | + state: present |
| 23 | + owner: core |
| 24 | + group: core |
| 25 | + |
| 26 | + - name: Add generated key to authorized keys |
| 27 | + ansible.builtin.shell: | |
| 28 | + cat .ssh/crc-cloud-bootstrap.pub >> .ssh/authorized_keys.d/ignition |
| 29 | +
|
| 30 | + # FIXME: move it to dedicated files |
| 31 | + - name: Create entrypoint file |
| 32 | + ansible.builtin.copy: |
| 33 | + content: | |
| 34 | + #!/bin/bash |
| 35 | +
|
| 36 | + echo "Check if inventory.yaml exists..." |
| 37 | + if [ -f "inventory.yaml" ]; then |
| 38 | + echo "Starting Ansible..." |
| 39 | + export ANSIBLE_HOST_KEY_CHECKING=False |
| 40 | + export ANSIBLE_LOG_PATH=/home/user/ansible-logs/ansible.log |
| 41 | + ansible-playbook -i inventory.yaml crc-cloud/ansible/playbooks/start.yaml |
| 42 | + else |
| 43 | + echo "Could not find inventory file. Exit" |
| 44 | + exit 1 |
| 45 | + fi |
| 46 | + dest: entrypoint.sh |
| 47 | + |
| 48 | + - name: Prepare Dockerfile |
| 49 | + ansible.builtin.copy: |
| 50 | + content: | |
| 51 | + FROM quay.io/centos/centos:stream9 |
| 52 | +
|
| 53 | + RUN dnf install -y ansible-core sudo && \ |
| 54 | + ansible-galaxy collection install community.general \ |
| 55 | + community.crypto ansible.posix \ |
| 56 | + kubernetes.core |
| 57 | +
|
| 58 | +
|
| 59 | + RUN groupadd --gid 1000 user && \ |
| 60 | + useradd --uid 1000 --gid 1000 -d /home/user user |
| 61 | + COPY entrypoint.sh /home/user/entrypoint.sh |
| 62 | + RUN chown -R user:user /home/user && chmod +x /home/user/entrypoint.sh |
| 63 | +
|
| 64 | + # FIXME - change root to user |
| 65 | + USER root |
| 66 | +
|
| 67 | + WORKDIR /home/user |
| 68 | + ENTRYPOINT ["/home/user/entrypoint.sh"] |
| 69 | +
|
| 70 | + dest: Dockerfile |
| 71 | + |
| 72 | + - name: Build bootstrap container |
| 73 | + ansible.builtin.shell: | |
| 74 | + podman build -t crc-cloud-bootstrap -f Dockerfile |
| 75 | +
|
| 76 | + - name: Create inventory file |
| 77 | + ansible.builtin.copy: |
| 78 | + content: | |
| 79 | + --- |
| 80 | + all: |
| 81 | + hosts: |
| 82 | + crc: |
| 83 | + ansible_port: 22 |
| 84 | + ansible_host: {{ ansible_default_ipv4.address }} |
| 85 | + ansible_user: core |
| 86 | + ansible_ssh_private_key_file: /home/user/.ssh/id_ed25519 |
| 87 | + vars: |
| 88 | + openshift_pull_secret: | |
| 89 | + {{ openshift_pull_secret }} |
| 90 | + dest: inventory.yaml |
| 91 | + |
| 92 | + - name: Create Ansible log directory |
| 93 | + ansible.builtin.file: |
| 94 | + path: "{{ item }}" |
| 95 | + state: directory |
| 96 | + owner: core |
| 97 | + group: core |
| 98 | + loop: |
| 99 | + - ansible-logs |
| 100 | + - .kube |
| 101 | + |
| 102 | + - name: Create container to boostrap |
| 103 | + ansible.builtin.shell: > |
| 104 | + podman create --name crc-cloud-boostrap |
| 105 | + --network host |
| 106 | + -v "/var/home/core/.ssh/crc-cloud-bootstrap:/home/user/.ssh/id_ed25519:z" |
| 107 | + -v "/var/home/core/inventory.yaml:/home/user/inventory.yaml:z" |
| 108 | + -v "/var/home/core/crc-cloud:/home/user/crc-cloud:z" |
| 109 | + -v "/var/home/core/ansible-logs:/home/user/ansible-logs:z" |
| 110 | + -v "/var/home/core/.kube:/home/user/.kube:z" |
| 111 | + crc-cloud-bootstrap |
| 112 | +
|
| 113 | + - name: Start the container |
| 114 | + ansible.builtin.shell: | |
| 115 | + podman start crc-cloud-boostrap |
0 commit comments