Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

k3d #23

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

k3d #23

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions ansible/deploy_k3d.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
- name: create stack user
hosts: all
tags: user
roles:
- ensure_stack_user

- name: deploy docker tools
hosts: k8s
tags: docker
remote_user: stack
become: true
roles:
- geerlingguy.pip
- geerlingguy.docker
post_tasks:
- name: Add user to docker group
become: true
ansible.builtin.command: usermod -aG docker stack
- name: Check we can execute docker commands
ansible.builtin.command: docker info

- name: deploy k8s tools
hosts: k8s
tags: k8s-tools
remote_user: stack
roles:
- ensure_kustomize
- prepare_dev_tools
- ensure_kubectl
- ensure_k3d


- name: finalize
hosts: all
roles:
- print_debug_ip
38 changes: 38 additions & 0 deletions ansible/roles/ensure_k3d/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).
3 changes: 3 additions & 0 deletions ansible/roles/ensure_k3d/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
# defaults file for ensure_kind
ensure_k3d_url_template: "https://raw.githubusercontent.com/k3d-io/k3d/main/install.sh"
2 changes: 2 additions & 0 deletions ansible/roles/ensure_k3d/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
# handlers file for ensure_kind
52 changes: 52 additions & 0 deletions ansible/roles/ensure_k3d/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
galaxy_info:
author: your name
description: your role description
company: your company (optional)

# 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: license (GPL-2.0-or-later, MIT, etc)

min_ansible_version: 2.1

# If this a Container Enabled role, provide the minimum Ansible Container version.
# min_ansible_container_version:

#
# Provide a list of supported platforms, and for each platform a list of versions.
# If you don't wish to enumerate all versions for a particular platform, use 'all'.
# To view available platforms and versions (or releases), visit:
# https://galaxy.ansible.com/api/v1/platforms/
#
# platforms:
# - name: Fedora
# versions:
# - all
# - 25
# - name: SomePlatform
# versions:
# - all
# - 1.0
# - 7
# - 99.99

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.
44 changes: 44 additions & 0 deletions ansible/roles/ensure_k3d/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
# tasks file for ensure_k3d
- name: install k3d
become: true
ansible.builtin.shell: |
set -e pipefail
curl -s https://raw.githubusercontent.com/k3d-io/k3d/main/install.sh | bash
k3d --version
environment:
K3D_INSTALL_DIR: /bin

- name: create k3d cluster
ansible.builtin.shell: |
set -e pipefail
k3d cluster list | grep -q dev-cluster || \
k3d cluster create dev-cluster --api-port 6550 --servers 1 --agents 2 --port 8080:80@loadbalancer --port 8443:443@loadbalancer --wait
k3d cluster list
register: k3d_cluster_create
changed_when: k3d_cluster_create.stdout.find('dev-cluster') == -1

- name: gather k3d cluster info
ansible.builtin.shell: |
set -e pipefail
k3d cluster list
kubectl cluster-info
kubectl get nodes
kubectl get pods --all-namespaces
register: k3d_cluster_info

- name: print k3d cluster info
ansible.builtin.debug:
msg: "{{k3d_cluster_info.stdout}}"


- name: install olm operator
ansible.builtin.shell: |
set -e pipefail
kubectl get namespace | grep -q "^olm"
if [ $? -ne 0 ]; then
curl -L https://github.com/operator-framework/operator-lifecycle-manager/releases/download/v0.26.0/install.sh -o install.sh
chmod +x install.sh
./install.sh v0.26.0
rm install.sh
fi
2 changes: 2 additions & 0 deletions ansible/roles/ensure_k3d/tests/inventory
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
localhost

5 changes: 5 additions & 0 deletions ansible/roles/ensure_k3d/tests/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
- hosts: localhost
remote_user: root
roles:
- ensure_kind
2 changes: 2 additions & 0 deletions ansible/roles/ensure_k3d/vars/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
# vars file for ensure_kind
38 changes: 38 additions & 0 deletions ansible/roles/ensure_kubectl/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 ansible/roles/ensure_kubectl/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
# defaults file for ensure_kubectl
ensure_kubectl_version: "v1.29.1"
ensure_kubectl_url_template: "https://dl.k8s.io/release/{{ensure_kubectl_version}}/bin/linux/amd64/kubectl"
2 changes: 2 additions & 0 deletions ansible/roles/ensure_kubectl/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
# handlers file for ensure_kubectl
52 changes: 52 additions & 0 deletions ansible/roles/ensure_kubectl/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
galaxy_info:
author: your name
description: your role description
company: your company (optional)

# 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: license (GPL-2.0-or-later, MIT, etc)

min_ansible_version: 2.1

# If this a Container Enabled role, provide the minimum Ansible Container version.
# min_ansible_container_version:

#
# Provide a list of supported platforms, and for each platform a list of versions.
# If you don't wish to enumerate all versions for a particular platform, use 'all'.
# To view available platforms and versions (or releases), visit:
# https://galaxy.ansible.com/api/v1/platforms/
#
# platforms:
# - name: Fedora
# versions:
# - all
# - 25
# - name: SomePlatform
# versions:
# - all
# - 1.0
# - 7
# - 99.99

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.
8 changes: 8 additions & 0 deletions ansible/roles/ensure_kubectl/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
# tasks file for ensure_kubectl
- name: download kubectl
become: true
get_url:
url: "{{ensure_kubectl_url_template}}"
dest: /bin/kubectl
mode: 777
2 changes: 2 additions & 0 deletions ansible/roles/ensure_kubectl/tests/inventory
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
localhost

5 changes: 5 additions & 0 deletions ansible/roles/ensure_kubectl/tests/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
- hosts: localhost
remote_user: root
roles:
- ensure_kubectl
2 changes: 2 additions & 0 deletions ansible/roles/ensure_kubectl/vars/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
# vars file for ensure_kubectl
3 changes: 1 addition & 2 deletions bootstrap-repo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ which dpkg && bindep -b | xargs sudo apt -y install
# to install manually later on.
which rpm && bindep -b | xargs sudo dnf -y --setopt=install_weak_deps=False install
#pip install ansible=2.9
pip install ansible\<5 ansible-core\<2.12.0 \
molecule!=3.6.1,!=3.6.0 molecule-vagrant python-vagrant netaddr molecule-openstack openstacksdk
pip install -r molecule-requirements.txt
which vagrant && vagrant plugin install vagrant-libvirt
git submodule update --init --recursive
groups | grep -E "libvirt" > /dev/null || \
Expand Down
12 changes: 12 additions & 0 deletions molecule-requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
ansible-core==2.14.6
molecule>=5.1.0,<6.0.0
molecule-plugins[podman,vagrant]>=23.5.0
pytest-testinfra
# this is required for the molecule jobs
ansi2html
dogpile.cache>=0.9.2
openstacksdk
pytest
pytest-cov
pytest-html
jinja2
2 changes: 1 addition & 1 deletion molecule/okd/INSTALL.rst → molecule/k3d/INSTALL.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ widely recommended `'--user' flag`_ when invoking ``pip``.

.. code-block:: bash

$ pip install 'molecule_vagrant'
$ pip install 'molecule-plugins[vagrant]'
23 changes: 23 additions & 0 deletions molecule/k3d/collections.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
# Copyright Red Hat, Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

collections:
- name: https://github.com/ansible-collections/ansible.posix
type: git
- name: https://github.com/ansible-collections/community.general
type: git
- name: https://github.com/ansible-collections/community.crypto
type: git
3 changes: 3 additions & 0 deletions molecule/k3d/converge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
- name: "execute deploy multi-node devstack"
import_playbook: ../../ansible/deploy_k3d.yaml
Loading