From 53d0fbb4682aa1254f872d7ed0b32c25a2eac8ca Mon Sep 17 00:00:00 2001 From: David Danielsson Date: Tue, 19 Nov 2024 12:56:00 -0600 Subject: [PATCH] new file: crc/README.md new file: crc/defaults/main.yml new file: crc/files/.keep new file: crc/handlers/main.yml new file: crc/meta/main.yml new file: crc/tasks/main.yml new file: crc/templates/haproxy.cfg.j2 new file: crc/tests/inventory new file: crc/tests/test.yml new file: crc/vars/main.yml --- roles/crc/README.md | 38 ++++++++++ roles/crc/defaults/main.yml | 4 ++ roles/crc/files/.keep | 0 roles/crc/handlers/main.yml | 3 + roles/crc/meta/main.yml | 36 ++++++++++ roles/crc/tasks/main.yml | 107 +++++++++++++++++++++++++++++ roles/crc/templates/haproxy.cfg.j2 | 23 +++++++ roles/crc/tests/inventory | 3 + roles/crc/tests/test.yml | 7 ++ roles/crc/vars/main.yml | 3 + 10 files changed, 224 insertions(+) create mode 100644 roles/crc/README.md create mode 100644 roles/crc/defaults/main.yml create mode 100644 roles/crc/files/.keep create mode 100644 roles/crc/handlers/main.yml create mode 100644 roles/crc/meta/main.yml create mode 100644 roles/crc/tasks/main.yml create mode 100644 roles/crc/templates/haproxy.cfg.j2 create mode 100644 roles/crc/tests/inventory create mode 100644 roles/crc/tests/test.yml create mode 100644 roles/crc/vars/main.yml diff --git a/roles/crc/README.md b/roles/crc/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/roles/crc/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/roles/crc/defaults/main.yml b/roles/crc/defaults/main.yml new file mode 100644 index 0000000..bbb24b0 --- /dev/null +++ b/roles/crc/defaults/main.yml @@ -0,0 +1,4 @@ +--- +# defaults file for crc +crc_version: 2.43.0 +... diff --git a/roles/crc/files/.keep b/roles/crc/files/.keep new file mode 100644 index 0000000..e69de29 diff --git a/roles/crc/handlers/main.yml b/roles/crc/handlers/main.yml new file mode 100644 index 0000000..6f36c0a --- /dev/null +++ b/roles/crc/handlers/main.yml @@ -0,0 +1,3 @@ +--- +# handlers file for crc +... diff --git a/roles/crc/meta/main.yml b/roles/crc/meta/main.yml new file mode 100644 index 0000000..3cdf764 --- /dev/null +++ b/roles/crc/meta/main.yml @@ -0,0 +1,36 @@ +--- +galaxy_info: + author: David Danielsson + description: Install or remove CRC + company: Red Hat + + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + + # Choose a valid license ID from https://spdx.org - some suggested licenses: + # - BSD-3-Clause (default) + # - MIT + # - GPL-2.0-or-later + # - GPL-3.0-only + # - Apache-2.0 + # - CC-BY-4.0 + license: MIT + + min_ansible_version: 2.17.0 + + # If this a Container Enabled role, provide the minimum Ansible Container version. + # min_ansible_container_version: + + galaxy_tags: [] + # List tags for your role here, one per line. A tag is a keyword that describes + # and categorizes the role. Users find roles by searching for tags. Be sure to + # remove the '[]' above, if you add tags to this list. + # + # NOTE: A tag is limited to a single word comprised of alphanumeric characters. + # Maximum 20 tags per role. + +dependencies: [] + # List your role dependencies here, one per line. Be sure to remove the '[]' above, + # if you add dependencies to this list. +... diff --git a/roles/crc/tasks/main.yml b/roles/crc/tasks/main.yml new file mode 100644 index 0000000..e5d28cb --- /dev/null +++ b/roles/crc/tasks/main.yml @@ -0,0 +1,107 @@ +--- +# tasks file for crc +- name: Enable all repositories starting with rhel-6-server + community.general.rhsm_repository: + name: rhocp-4.17-for-rhel-9-x86_64-rpms + state: enabled + +- name: Install required packages + ansible.builtin.package: + name: + - jq + - wget + - tar + - haproxy + - openshfit-clients + state: present + +- name: Disable and mask firewalld + ansible.builtin.service: + name: firewalld + state: stopped + enabled: false + +- name: Download and install CRC + ansible.builtin.get_url: + url: https://developers.redhat.com/content-gateway/rest/mirror/pub/openshift-v4/clients/crc/{{ crc_version }}/crc-linux-amd64.tar.xz + dest: /tmp/crc.tar.xz + mode: "0755" + register: crc_tarball + +- name: Extract CRC + ansible.builtin.unarchive: + src: "{{ crc_tarball.dest }}" + dest: "/tmp" + owner: root + group: root + mode: "0755" + when: crc_tarball is defined and crc_tarball.status == "success" + +- name: Configure CRC + ansible.builtin.command: + cmd: crc config set memory 16336 + changed_when: true + when: crc_tarball is defined and crc_tarball.status == "success" + register: crc_config_result + +- name: Copy pull-secret + ansible.builtin.copy: + content: "{{ pull_secret }}" + dest: /home/{{ ansible_user }}/pull-secret.json + mode: "0644" + +- name: Start and configure CRC + ansible.builtin.command: + cmd: crc setup --log-level debug && crc start --log-level debug --pull-secret-file /home/{{ ansible_user }}/pull-secret.json + changed_when: true + when: crc_tarball is defined and crc_tarball.status == "success" + register: crc_start_result + +- name: Configure haproxy + ansible.builtin.template: + src: templates/haproxy.cfg.j2 + dest: /etc/haproxy/haproxy.cfg + mode: "0644" + owner: root + group: root + vars: + crc_ip: "{{ crc_start_result.stdout | regex_replace('CRC IP: ([0-9.]+)') }}" + +- name: Enable and start haproxy service + ansible.builtin.service: + name: haproxy + state: started + enabled: true + +- name: Set up base domain for cluster + ansible.builtin.set_fact: + base_domain: "{{ inventory_hostname | ipaddr }}.crc.danielsson.us.com" + +- name: Create TLS certificate and secret + community.crypto.x509_certificate: + path: /home/{{ ansible_user }}/nip.crt + key_path: /home/{{ ansible_user }}/nip.key + common_name: "{{ base_domain }}" + days_until_expiration: 3650 + +- name: Wait for cluster operators to be ready + ansible.builtin.uri: + url: "http://localhost:8443/api/v1/clusteroperators" + status_code: 200 + until: "'Ready' in {{ lookup('url', uri).status.phase | join(', ') }}" + retries: 10 + +- name: Patch route + ansible.builtin.command: + cmd: "oc patch route/{{ base_domain }} --type json -p '[{\"op\": \"add\", \"path\": \"/spec/hostnames\", \"value\": [\"{{ base_domain }}\"]}]'" + changed_when: true + register: route_result + +# - name: Log in to OpenShift cluster (optional) +# kubernetes.core.k8s_api_login: +# state: present +# username: "{{ crc_start_result.stdout | regex_replace('CRC Username: (.+)') }}" +# password: "{{ crc_start_result.stdout | regex_replace('CRC Password: (.+)') }}" +# server: "https://api.{{ base_domain }}:6443" +# when: ansible_os_family == "RedHat" and not ansible_local +... diff --git a/roles/crc/templates/haproxy.cfg.j2 b/roles/crc/templates/haproxy.cfg.j2 new file mode 100644 index 0000000..69426ed --- /dev/null +++ b/roles/crc/templates/haproxy.cfg.j2 @@ -0,0 +1,23 @@ +global + log /dev/log local0 + +defaults + balance roundrobin + log global + maxconn 100 + mode tcp + timeout connect 5s + timeout client 500s + timeout server 500s + +listen apps + bind 0.0.0.0:80 + server crcvm {{ crc_ip }}:80 check + +listen apps_ssl + bind 0.0.0.0:443 + server crcvm {{ crc_ip }}:443 check + +listen api + bind 0.0.0.0:6443 + server crcvm {{ crc_ip }}:6443 check diff --git a/roles/crc/tests/inventory b/roles/crc/tests/inventory new file mode 100644 index 0000000..03ca42f --- /dev/null +++ b/roles/crc/tests/inventory @@ -0,0 +1,3 @@ +#SPDX-License-Identifier: MIT-0 +localhost + diff --git a/roles/crc/tests/test.yml b/roles/crc/tests/test.yml new file mode 100644 index 0000000..4510297 --- /dev/null +++ b/roles/crc/tests/test.yml @@ -0,0 +1,7 @@ +--- +- name: Tests + hosts: localhost + remote_user: root + roles: + - crc +... diff --git a/roles/crc/vars/main.yml b/roles/crc/vars/main.yml new file mode 100644 index 0000000..9b82278 --- /dev/null +++ b/roles/crc/vars/main.yml @@ -0,0 +1,3 @@ +--- +# vars file for crc +...