Skip to content
Merged
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
15 changes: 15 additions & 0 deletions .ansible-lint
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
profile: production

exclude_paths:
- tests/

skip_list:
- var-naming[no-role-prefix]
- galaxy[no-changelog]
- ignore-errors
- jinja[spacing]

mock_modules:
- agnosticd.core.agnosticd_user_info
- agnosticd.core.ec2_tags_to_dict
34 changes: 0 additions & 34 deletions .github/workflows/static-checks-pr.yml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,34 +1,35 @@
---
name: Static Checks Push
name: Static Checks

on:
"on":
push:
branches:
- main
tags:
- v*
pull_request:
branches:
- main

jobs:
static-checks:
name: Run static tests using tox
name: Run yamllint and ansible-lint
runs-on: ubuntu-latest
strategy:
matrix:
python-version:
- '3.12'

steps:
- name: Get Repository Code
id: get_repo_code
uses: actions/checkout@v2
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Run static checks
run: |
pip install tox
tox -c tests/static
...
29 changes: 29 additions & 0 deletions .yamllint
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
extends: default

ignore:
- .tox/
- .git/

rules:
braces:
min-spaces-inside: 0
max-spaces-inside: 1
brackets:
min-spaces-inside: 0
max-spaces-inside: 1
comments:
require-starting-space: false
min-spaces-from-content: 1
comments-indentation: disable
document-start: false
indentation:
spaces: 2
indent-sequences: consistent
line-length:
max: 150
allow-non-breakable-inline-mappings: false
new-line-at-end-of-file: false
octal-values:
forbid-implicit-octal: true
forbid-explicit-octal: true
4 changes: 2 additions & 2 deletions galaxy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ license_file: ''

# A list of tags you want to associate with the collection for indexing/searching. A tag name has the same character
# requirements as 'namespace' and 'name'
tags: []
tags:
- cloud

# Collections that this collection requires to be installed for it to be usable. The key of the dict is the
# collection label 'namespace.name'. The value is a version range
Expand Down Expand Up @@ -66,4 +67,3 @@ build_ignore: []
# 'omit_default_directives' is a boolean that controls whether the default directives are used. Mutually exclusive
# with 'build_ignore'
# manifest: null

53 changes: 1 addition & 52 deletions meta/runtime.yml
Original file line number Diff line number Diff line change
@@ -1,53 +1,2 @@
#SPDX-License-Identifier: MIT-0
---
# Collections must specify a minimum required ansible version to upload
# to galaxy
# requires_ansible: '>=2.9.10'

# Content that Ansible needs to load from another location or that has
# been deprecated/removed
# plugin_routing:
# action:
# redirected_plugin_name:
# redirect: ns.col.new_location
# deprecated_plugin_name:
# deprecation:
# removal_version: "4.0.0"
# warning_text: |
# See the porting guide on how to update your playbook to
# use ns.col.another_plugin instead.
# removed_plugin_name:
# tombstone:
# removal_version: "2.0.0"
# warning_text: |
# See the porting guide on how to update your playbook to
# use ns.col.another_plugin instead.
# become:
# cache:
# callback:
# cliconf:
# connection:
# doc_fragments:
# filter:
# httpapi:
# inventory:
# lookup:
# module_utils:
# modules:
# netconf:
# shell:
# strategy:
# terminal:
# test:
# vars:

# Python import statements that Ansible needs to load from another location
# import_redirection:
# ansible_collections.ns.col.plugins.module_utils.old_location:
# redirect: ansible_collections.ns.col.plugins.module_utils.new_location

# Groups of actions/modules that take a common set of options
# action_groups:
# group_name:
# - module1
# - module2
requires_ansible: '>=2.16.0'
2 changes: 1 addition & 1 deletion roles/create_inventory/tasks/create_inventory.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
kind: VirtualMachine
namespace: "{{ openshift_cnv_namespace }}"
register: r_openshift_cnv_instances

- name: Debug OpenShift CNV Instances fact
ansible.builtin.debug:
var: r_openshift_cnv_instances
Expand Down
22 changes: 13 additions & 9 deletions roles/resources/tasks/create_instance.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@
_cloud_config: |-
#cloud-config
ssh_authorized_keys:
- {{ lookup('file', ssh_provision_pubkey_path ) }}
{{_instance.userdata | default('') | replace('#cloud-config','') | default('')}}
- {{ lookup('file', ssh_provision_pubkey_path) }}
{{ _instance.userdata | default('') | replace('#cloud-config', '') | default('') }}

- name: Set cloud init disk if needed
when: _instance.disable_cloud_init | default(false) == false
when: _instance.disable_cloud_init | default(false) is not true
ansible.builtin.set_fact:
_instance_volumes: "{{ (_instance_volumes if _instance_volumes is not string else _instance_volumes | from_yaml) + [
{
Expand Down Expand Up @@ -127,7 +127,7 @@

- name: Create instance(s) "{{ _instance.name }}"
vars:
_instance_name: "{{ _instance.name }}{{ _index+1 if _instance.count | default(1) | int > 1 }}"
_instance_name: "{{ _instance.name }}{{ _index + 1 if _instance.count | default(1) | int > 1 }}"
_datavolume: |
- metadata:
name: "{{ _instance_name }}-{{ guid }}"
Expand Down Expand Up @@ -185,17 +185,21 @@
namespace: "{{ openshift_cnv_namespace }}"
annotations: >-
{{ cloud_tags_final
| combine(_instance.metadata|default({})) | combine(_instance.tags|default({}) | agnosticd.core.ec2_tags_to_dict) }}
| combine(_instance.metadata | default({})) | combine(_instance.tags | default({}) | agnosticd.core.ec2_tags_to_dict) }}
spec:
dataVolumeTemplates: >-
{{ _datavolume | from_yaml + (_instance.disks | default([]) | to_json | replace('INSTANCENAME',_instance_name) | from_json) + (_instance.cdroms | default([]) | to_json | replace('INSTANCENAME',_instance_name) | from_json) }}
{{ _datavolume | from_yaml
+ (_instance.disks | default([]) | to_json
| replace('INSTANCENAME', _instance_name) | from_json)
+ (_instance.cdroms | default([]) | to_json
| replace('INSTANCENAME', _instance_name) | from_json) }}
running: true
template:
metadata:
labels:
vm.cnv.io/name: "{{ _instance_name }}"
spec: "{{ _spec | from_yaml }}"
loop: "{{ range(1, _instance.count | default(1) | int+1) | list }}"
loop: "{{ range(1, _instance.count | default(1) | int + 1) | list }}"
loop_control:
index_var: _index
register: r_openshift_cnv_instance
Expand All @@ -205,7 +209,7 @@

- name: Wait until the VM is running
vars:
_instance_name: "{{ _instance.name }}{{ _index+1 if _instance.count | default(1) | int > 1 }}"
_instance_name: "{{ _instance.name }}{{ _index + 1 if _instance.count | default(1) | int > 1 }}"
kubernetes.core.k8s_info:
api_version: kubevirt.io/v1
kind: VirtualMachine
Expand All @@ -215,7 +219,7 @@
until: r_vm_status.resources[0].status.printableStatus | default('') == "Running"
retries: 30
delay: 10
loop: "{{ range(1, _instance.count | default(1) | int+1) | list }}"
loop: "{{ range(1, _instance.count | default(1) | int + 1) | list }}"
loop_control:
index_var: _index

Expand Down
6 changes: 5 additions & 1 deletion roles/resources/tasks/create_network.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
---
- name: Create network {{ _network.name }}
vars:
_config: "{'cniVersion':'0.3.1','type':'ovn-k8s-cni-overlay','topology':'layer2','name': '{{ _network.name }}{{ guid }}', 'netAttachDefName': '{{ openshift_cnv_namespace }}/{{ _network.name }}{{ guid }}', 'mtu': {{ _network.mtu | default(1500) }}}"
_config: >-
{'cniVersion':'0.3.1','type':'ovn-k8s-cni-overlay','topology':'layer2',
'name': '{{ _network.name }}{{ guid }}',
'netAttachDefName': '{{ openshift_cnv_namespace }}/{{ _network.name }}{{ guid }}',
'mtu': {{ _network.mtu | default(1500) }}}
kubernetes.core.k8s:
definition:
apiVersion: k8s.cni.cncf.io/v1
Expand Down
11 changes: 9 additions & 2 deletions roles/resources/tasks/create_routes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@
to:
kind: Service
name: "{{ route.service }}"
httpHeaders: "{{ (openshift_cnv_route_remove_x_frame_options_header and route.tls_termination | default('passthrough') != 'passthrough') | ternary({'actions': {'response': [{'name': 'X-Frame-Options', 'action': {'type': 'Delete'}}]}}, omit) }}"
httpHeaders: >-
{{ (openshift_cnv_route_remove_x_frame_options_header
and route.tls_termination | default('passthrough') != 'passthrough')
| ternary({'actions': {'response': [{'name': 'X-Frame-Options',
'action': {'type': 'Delete'}}]}}, omit) }}
loop: "{{ _instance.routes | default([]) }}"
loop_control:
loop_var: route
Expand Down Expand Up @@ -57,7 +61,10 @@
to:
kind: Service
name: "{{ route.service }}"
httpHeaders: "{{ (openshift_cnv_route_remove_x_frame_options_header) | ternary({'actions': {'response': [{'name': 'X-Frame-Options', 'action': {'type': 'Delete'}}]}}, omit) }}"
httpHeaders: >-
{{ (openshift_cnv_route_remove_x_frame_options_header)
| ternary({'actions': {'response': [{'name': 'X-Frame-Options',
'action': {'type': 'Delete'}}]}}, omit) }}
loop: "{{ _instance.routes | default([]) }}"
loop_control:
loop_var: route
Expand Down
20 changes: 10 additions & 10 deletions roles/resources/tasks/create_service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
namespace: "{{ openshift_cnv_namespace }}"
spec: "{{ spec | from_yaml }}"
vars:
_instance_name: "{{ _instance.name }}{{ _index+1 if _instance.count|d(1)|int > 1 }}"
_instance_name: "{{ _instance.name }}{{ _index + 1 if _instance.count | d(1) | int > 1 }}"
spec: |
ports:
{{ service.ports }}
selector:
vm.cnv.io/name: "{{ _instance_name }}"
type: {{ service.type | default('ClusterIP') }}
loop: "{{ range(1, _instance.count | default(1)|int+1) | list }}"
loop: "{{ range(1, _instance.count | default(1) | int + 1) | list }}"
loop_control:
index_var: _index
register: r_create_service
Expand Down Expand Up @@ -50,7 +50,7 @@
ansible.builtin.set_fact:
_instance_node_ports: "{{ svc_np.resources[0].spec.ports | map(attribute='nodePort') | join(',') }}"

- name: Add NodePort annotation for service {{ service.name }} to the instance
- name: Add NodePort annotation to the instance for service {{ service.name }}
when: service.type | default("ClusterIP") == "NodePort"
kubernetes.core.k8s:
state: patched
Expand All @@ -66,8 +66,8 @@
annotations:
NodePort-{{ service.name }}: "{{ _instance_node_ports }}"
vars:
_instance_name: "{{ _instance.name }}{{ _index+1 if _instance.count|d(1)|int > 1 }}"
loop: "{{ range(1, _instance.count | default(1)|int+1) | list }}"
_instance_name: "{{ _instance.name }}{{ _index + 1 if _instance.count | d(1) | int > 1 }}"
loop: "{{ range(1, _instance.count | default(1) | int + 1) | list }}"
loop_control:
index_var: _index
register: r_nodeport_annotation
Expand Down Expand Up @@ -98,16 +98,16 @@
external_ip: "{{ _instance_external_ip }}"
external_ports: "{{ _instance_external_ports }}"
vars:
_instance_name: "{{ _instance.name }}{{ _index+1 if _instance.count|d(1)|int > 1 }}"
loop: "{{ range(1, _instance.count | default(1)|int+1) | list }}"
_instance_name: "{{ _instance.name }}{{ _index + 1 if _instance.count | d(1) | int > 1 }}"
loop: "{{ range(1, _instance.count | default(1) | int + 1) | list }}"
loop_control:
index_var: _index
register: r_lb_patch
until: r_lb_patch is success
retries: "{{ openshift_cnv_retries }}"
delay: "{{ openshift_cnv_delay }}"

- name: Add LoadBalancer annotation for service {{ service.name }} to the instance
- name: Add LoadBalancer annotation to the instance for service {{ service.name }}
when: service.type | default("ClusterIP") == "LoadBalancer"
kubernetes.core.k8s:
state: patched
Expand All @@ -123,8 +123,8 @@
annotations:
LoadBalancer-{{ service.name }}: "{{ _instance_external_ip }}:{{ _instance_external_ports }}"
vars:
_instance_name: "{{ _instance.name }}{{ _index+1 if _instance.count|d(1)|int > 1 }}"
loop: "{{ range(1, _instance.count | default(1)|int+1) | list }}"
_instance_name: "{{ _instance.name }}{{ _index + 1 if _instance.count | d(1) | int > 1 }}"
loop: "{{ range(1, _instance.count | default(1) | int + 1) | list }}"
loop_control:
index_var: _index
register: r_lb_annotation
Expand Down
2 changes: 1 addition & 1 deletion roles/resources/tasks/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,5 @@
api_key: "{{ k8s_auth_results.k8s_auth.api_key | default(sandbox_openshift_api_key) }}"
validate_certs: false
block:
- name: Include {{ ACTION }}_instances.yaml
- name: Include instances tasks for {{ ACTION }}
ansible.builtin.include_tasks: "{{ ACTION }}_instances.yaml"
1 change: 1 addition & 0 deletions roles/resources/tasks/status_instances.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
- name: Print status information to a file
ansible.builtin.copy:
dest: "{{ output_dir }}/status.txt"
mode: "0644"
content: |-
{{ "%-20s %-10s" | format("Instance", "State") }}
----------------------------------------------------------------
Expand Down
Loading
Loading