Skip to content

Commit

Permalink
new file: crc/README.md
Browse files Browse the repository at this point in the history
	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
  • Loading branch information
djdanielsson committed Nov 19, 2024
1 parent da8f572 commit 53d0fbb
Show file tree
Hide file tree
Showing 10 changed files with 224 additions and 0 deletions.
38 changes: 38 additions & 0 deletions roles/crc/README.md
Original file line number Diff line number Diff line change
@@ -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).
4 changes: 4 additions & 0 deletions roles/crc/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
# defaults file for crc
crc_version: 2.43.0
...
Empty file added roles/crc/files/.keep
Empty file.
3 changes: 3 additions & 0 deletions roles/crc/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
# handlers file for crc
...
36 changes: 36 additions & 0 deletions roles/crc/meta/main.yml
Original file line number Diff line number Diff line change
@@ -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.
...
107 changes: 107 additions & 0 deletions roles/crc/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -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
...
23 changes: 23 additions & 0 deletions roles/crc/templates/haproxy.cfg.j2
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions roles/crc/tests/inventory
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#SPDX-License-Identifier: MIT-0
localhost

7 changes: 7 additions & 0 deletions roles/crc/tests/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
- name: Tests
hosts: localhost
remote_user: root
roles:
- crc
...
3 changes: 3 additions & 0 deletions roles/crc/vars/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
# vars file for crc
...

0 comments on commit 53d0fbb

Please sign in to comment.