mirror of
https://github.com/openshift/community.okd.git
synced 2026-11-22 07:00:26 +00:00
Compare commits
32
Commits
1.1.1
..
stable-2.1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2530e51825 | ||
|
|
d154967c88 | ||
|
|
e0c6713926 | ||
|
|
11314f8280 | ||
|
|
c737d44413 | ||
|
|
c340ff6582 | ||
|
|
9bea36be5c | ||
|
|
7bb52051da | ||
|
|
ffe6025fe9 | ||
|
|
f095a4d238 | ||
|
|
b0638ad2a4 | ||
|
|
bfb2c8904f | ||
|
|
3d0dfc1ae2 | ||
|
|
c72d17b6ba | ||
|
|
0838ee48d2 | ||
|
|
e9f8c41ac4 | ||
|
|
faba4a0812 | ||
|
|
6b2f06a157 | ||
|
|
bffadb5a55 | ||
|
|
d7a8ba15c7 | ||
|
|
9ff94989ae | ||
|
|
f60ded17b0 | ||
|
|
37833d4316 | ||
|
|
4609c20a91 | ||
|
|
63deaeecf0 | ||
|
|
d696fcaa06 | ||
|
|
7e653aee65 | ||
|
|
dd2ed851ab | ||
|
|
c5f822a0a7 | ||
|
|
748d40d244 | ||
|
|
152c6e42c5 | ||
|
|
74ce4c31ae |
@@ -27,11 +27,8 @@ jobs:
|
|||||||
- stable-2.11
|
- stable-2.11
|
||||||
- devel
|
- devel
|
||||||
python:
|
python:
|
||||||
- 2.7
|
|
||||||
- 3.7
|
- 3.7
|
||||||
- 3.8
|
- 3.8
|
||||||
exclude:
|
|
||||||
- python: 3.8 # blocked by ansible/ansible#70155
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Check out code
|
- name: Check out code
|
||||||
@@ -52,73 +49,20 @@ jobs:
|
|||||||
# The docker container has all the pinned dependencies that are required.
|
# The docker container has all the pinned dependencies that are required.
|
||||||
# Explicitly specify the version of Python we want to test
|
# Explicitly specify the version of Python we want to test
|
||||||
- name: Run sanity tests
|
- name: Run sanity tests
|
||||||
run: make upstream-test-sanity TEST_ARGS='--python ${{ matrix.python }}'
|
run: make upstream-test-sanity PYTHON_VERSION='${{ matrix.python }}'
|
||||||
working-directory: ./ansible_collections/community/okd
|
working-directory: ./ansible_collections/community/okd
|
||||||
|
|
||||||
###
|
|
||||||
# Integration tests (RECOMMENDED)
|
|
||||||
#
|
|
||||||
# https://docs.ansible.com/ansible/latest/dev_guide/testing_integration.html
|
|
||||||
|
|
||||||
# integration:
|
|
||||||
# runs-on: ubuntu-latest
|
|
||||||
# name: Integration (Ⓐ${{ matrix.ansible }}+py${{ matrix.python }}})
|
|
||||||
# strategy:
|
|
||||||
# fail-fast: false
|
|
||||||
# matrix:
|
|
||||||
# ansible:
|
|
||||||
# - stable-2.9
|
|
||||||
# - stable-2.10
|
|
||||||
# - devel
|
|
||||||
# python:
|
|
||||||
# - 2.7
|
|
||||||
# - 3.7
|
|
||||||
# - 3.8
|
|
||||||
# exclude:
|
|
||||||
# - python: 3.8 # blocked by ansible/ansible#70155
|
|
||||||
|
|
||||||
# steps:
|
|
||||||
# - name: Check out code
|
|
||||||
# uses: actions/checkout@v2
|
|
||||||
# with:
|
|
||||||
# path: ansible_collections/community/okd
|
|
||||||
|
|
||||||
# - name: Set up Python ${{ matrix.ansible }}
|
|
||||||
# uses: actions/setup-python@v2
|
|
||||||
# with:
|
|
||||||
# python-version: ${{ matrix.python }}
|
|
||||||
|
|
||||||
# - name: Install ansible-base (${{ matrix.ansible }})
|
|
||||||
# run: pip install https://github.com/ansible/ansible/archive/${{ matrix.ansible }}.tar.gz --disable-pip-version-check
|
|
||||||
|
|
||||||
# # OPTIONAL If your integration test requires Python libraries or modules from other collections
|
|
||||||
# # Install them like this
|
|
||||||
# - name: Install collection dependencies
|
|
||||||
# run: ansible-galaxy collection install kubernetes.core -p .
|
|
||||||
|
|
||||||
# # Run the integration tests
|
|
||||||
# - name: Run integration test
|
|
||||||
# run: ansible-test integration -v --color --retry-on-error --continue-on-error --diff --python ${{ matrix.python }} --docker --coverage
|
|
||||||
# working-directory: ./ansible_collections/community/okd
|
|
||||||
|
|
||||||
# # ansible-test support producing code coverage date
|
|
||||||
# - name: Generate coverage report
|
|
||||||
# run: ansible-test coverage xml -v --requirements --group-by command --group-by version
|
|
||||||
# working-directory: ./ansible_collections/community/okd
|
|
||||||
|
|
||||||
# # See the reports at https://codecov.io/gh/ansible_collections/GITHUBORG/REPONAME
|
|
||||||
# - uses: codecov/codecov-action@v1
|
|
||||||
# with:
|
|
||||||
# fail_ci_if_error: false
|
|
||||||
#
|
|
||||||
downstream-sanity-29:
|
downstream-sanity-29:
|
||||||
name: Downstream Sanity (Ⓐ${{ matrix.ansible }}+py${{ matrix.python }})
|
name: Downstream Sanity (Ⓐ${{ matrix.ansible }}+py${{ matrix.python }})
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
ansible:
|
ansible:
|
||||||
- stable-2.9
|
- stable-2.9
|
||||||
|
- stable-2.10
|
||||||
|
- stable-2.11
|
||||||
python:
|
python:
|
||||||
- 3.6
|
- 3.7
|
||||||
|
- 3.8
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Check out code
|
- name: Check out code
|
||||||
@@ -131,12 +75,13 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
python-version: ${{ matrix.python }}
|
python-version: ${{ matrix.python }}
|
||||||
|
|
||||||
- name: Install ansible 2.9
|
# Install the head of the given branch (devel, stable-2.10)
|
||||||
run: pip install "ansible>=2.9.0,<2.10.0"
|
- name: Install ansible-base (${{ matrix.ansible }})
|
||||||
|
run: pip install https://github.com/ansible/ansible/archive/${{ matrix.ansible }}.tar.gz --disable-pip-version-check
|
||||||
|
|
||||||
# run ansible-test sanity inside of Docker.
|
# run ansible-test sanity inside of Docker.
|
||||||
# The docker container has all the pinned dependencies that are required.
|
# The docker container has all the pinned dependencies that are required.
|
||||||
# Explicitly specify the version of Python we want to test
|
# Explicitly specify the version of Python we want to test
|
||||||
- name: Run sanity tests
|
- name: Run sanity tests
|
||||||
run: make downstream-test-sanity
|
run: make downstream-test-sanity PYTHON_VERSION='${{ matrix.python }}'
|
||||||
working-directory: ./ansible_collections/community/okd
|
working-directory: ./ansible_collections/community/okd
|
||||||
|
|||||||
@@ -16,3 +16,6 @@ changelogs/.plugin-cache.yaml
|
|||||||
# Temporary test files.
|
# Temporary test files.
|
||||||
tests/output
|
tests/output
|
||||||
tests/integration/cloud-config-*
|
tests/integration/cloud-config-*
|
||||||
|
|
||||||
|
# Ignore the ansible_collections that the Makefile generates.
|
||||||
|
ansible_collections
|
||||||
|
|||||||
@@ -5,6 +5,61 @@ OKD Collection Release Notes
|
|||||||
.. contents:: Topics
|
.. contents:: Topics
|
||||||
|
|
||||||
|
|
||||||
|
v2.1.0
|
||||||
|
======
|
||||||
|
|
||||||
|
Minor Changes
|
||||||
|
-------------
|
||||||
|
|
||||||
|
- add support for turbo mode (https://github.com/openshift/community.okd/pull/102).
|
||||||
|
- openshift_route - Add support for Route annotations (https://github.com/ansible-collections/community.okd/pull/99).
|
||||||
|
|
||||||
|
Bugfixes
|
||||||
|
--------
|
||||||
|
|
||||||
|
- fix broken links in Automation Hub for redhat.openshift (https://github.com/openshift/community.okd/issues/100).
|
||||||
|
|
||||||
|
v2.0.1
|
||||||
|
======
|
||||||
|
|
||||||
|
Minor Changes
|
||||||
|
-------------
|
||||||
|
|
||||||
|
- increase kubernetes.core dependency version (https://github.com/openshift/community.okd/pull/97).
|
||||||
|
|
||||||
|
v2.0.0
|
||||||
|
======
|
||||||
|
|
||||||
|
Major Changes
|
||||||
|
-------------
|
||||||
|
|
||||||
|
- update to use kubernetes.core 2.0 (https://github.com/openshift/community.okd/pull/93).
|
||||||
|
|
||||||
|
Minor Changes
|
||||||
|
-------------
|
||||||
|
|
||||||
|
- Added documentation for the ``community.okd`` collection.
|
||||||
|
- openshift - inventory plugin supports FQCN ``redhat.openshift``.
|
||||||
|
|
||||||
|
Breaking Changes / Porting Guide
|
||||||
|
--------------------------------
|
||||||
|
|
||||||
|
- drop python 2 support (https://github.com/openshift/community.okd/pull/93).
|
||||||
|
|
||||||
|
Bugfixes
|
||||||
|
--------
|
||||||
|
|
||||||
|
- fixes test suite to use correct versions of python and dependencies (https://github.com/ansible-collections/community.okd/pull/89).
|
||||||
|
- openshift_process - fix module execution when template does not include a message (https://github.com/ansible-collections/community.okd/pull/87).
|
||||||
|
|
||||||
|
v1.1.2
|
||||||
|
======
|
||||||
|
|
||||||
|
Bugfixes
|
||||||
|
--------
|
||||||
|
|
||||||
|
- include requirements.txt in downstream build process (https://github.com/ansible-collections/community.okd/pull/81).
|
||||||
|
|
||||||
v1.1.1
|
v1.1.1
|
||||||
======
|
======
|
||||||
|
|
||||||
|
|||||||
+3
-3
@@ -48,7 +48,7 @@ Where modules have multiple parameters we recommend running through the 4-step m
|
|||||||
|
|
||||||
For general information on running the integration tests see the
|
For general information on running the integration tests see the
|
||||||
[Integration Tests page of the Module Development Guide](https://docs.ansible.com/ansible/devel/dev_guide/testing_integration.html#testing-integration),
|
[Integration Tests page of the Module Development Guide](https://docs.ansible.com/ansible/devel/dev_guide/testing_integration.html#testing-integration),
|
||||||
especially the section on configuration for cloud tests. For questions about writing tests the Ansible Kubernetes community can be found on Freenode IRC as detailed below.
|
especially the section on configuration for cloud tests. For questions about writing tests the Ansible Kubernetes community can be found on Libera.Chat IRC as detailed below.
|
||||||
|
|
||||||
|
|
||||||
### Code of Conduct
|
### Code of Conduct
|
||||||
@@ -58,8 +58,8 @@ Please read and familiarize yourself with this document.
|
|||||||
|
|
||||||
### IRC
|
### IRC
|
||||||
Our IRC channels may require you to register your nickname. If you receive an error when you connect, see
|
Our IRC channels may require you to register your nickname. If you receive an error when you connect, see
|
||||||
[Freenode's Nickname Registration guide](https://freenode.net/kb/answer/registration) for instructions.
|
[Libera.Chat's Nickname Registration guide](https://libera.chat/guides/registration) for instructions.
|
||||||
|
|
||||||
The `#ansible-kubernetes` channel on Freenode IRC is the main and official place to discuss use and development of the `community.okd` collection.
|
The `#ansible-kubernetes` channel on [irc.libera.chat](https://libera.chat/) is the main and official place to discuss use and development of the `community.okd` collection.
|
||||||
|
|
||||||
For more information about Ansible's Kubernetes and OpenShift integration, browse the resources in the [Kubernetes Working Group](https://github.com/ansible/community/wiki/Kubernetes) Community wiki page.
|
For more information about Ansible's Kubernetes and OpenShift integration, browse the resources in the [Kubernetes Working Group](https://github.com/ansible/community/wiki/Kubernetes) Community wiki page.
|
||||||
|
|||||||
@@ -1,34 +1,38 @@
|
|||||||
|
.PHONY: molecule
|
||||||
|
|
||||||
# Also needs to be updated in galaxy.yml
|
# Also needs to be updated in galaxy.yml
|
||||||
VERSION = 1.1.1
|
VERSION = 2.1.0
|
||||||
|
|
||||||
# To run sanity tests in a venv, set SANITY_TEST_ARGS to '--venv'
|
|
||||||
SANITY_TEST_ARGS ?= --docker --color
|
SANITY_TEST_ARGS ?= --docker --color
|
||||||
|
PYTHON_VERSION ?= `python3 -c 'import platform; print("{0}.{1}".format(platform.python_version_tuple()[0], platform.python_version_tuple()[1]))'`
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f community-okd-$(VERSION).tar.gz
|
rm -f community-okd-$(VERSION).tar.gz
|
||||||
|
rm -f redhat-openshift-$(VERSION).tar.gz
|
||||||
rm -rf ansible_collections
|
rm -rf ansible_collections
|
||||||
|
|
||||||
build: clean
|
build: clean
|
||||||
ansible-galaxy collection build
|
ansible-galaxy collection build
|
||||||
|
|
||||||
install-kubernetes-src:
|
install: build
|
||||||
ansible-galaxy collection install -p ansible_collections kubernetes.core
|
|
||||||
|
|
||||||
install: build install-kubernetes-src
|
|
||||||
ansible-galaxy collection install -p ansible_collections community-okd-$(VERSION).tar.gz
|
ansible-galaxy collection install -p ansible_collections community-okd-$(VERSION).tar.gz
|
||||||
|
|
||||||
|
sanity: install
|
||||||
|
cd ansible_collections/community/okd && ansible-test sanity -v --python $(PYTHON_VERSION) $(SANITY_TEST_ARGS)
|
||||||
|
|
||||||
|
molecule: install
|
||||||
|
molecule test
|
||||||
|
|
||||||
|
test-integration: upstream-test-integration downstream-test-integration
|
||||||
|
|
||||||
|
test-sanity: upstream-test-sanity downstream-test-sanity
|
||||||
|
|
||||||
test-integration-incluster:
|
test-integration-incluster:
|
||||||
./ci/incluster_integration.sh
|
./ci/incluster_integration.sh
|
||||||
|
|
||||||
test-sanity: upstream-test-sanity downstream-test-sanity
|
upstream-test-sanity: sanity
|
||||||
|
|
||||||
test-integration: upstream-test-integration downstream-test-integration
|
upstream-test-integration: molecule
|
||||||
|
|
||||||
upstream-test-integration: install
|
|
||||||
molecule test
|
|
||||||
|
|
||||||
upstream-test-sanity: install
|
|
||||||
cd ansible_collections/community/okd && ansible-test sanity --exclude ci/ -v $(SANITY_TEST_ARGS)
|
|
||||||
|
|
||||||
downstream-test-sanity:
|
downstream-test-sanity:
|
||||||
./ci/downstream.sh -s
|
./ci/downstream.sh -s
|
||||||
|
|||||||
@@ -1,12 +1,6 @@
|
|||||||
|
# This file just uses aliases defined in OWNERS_ALIASES.
|
||||||
|
|
||||||
approvers:
|
approvers:
|
||||||
- geerlingguy
|
- community.okd-approvers
|
||||||
- fabianvf
|
|
||||||
- maxamillion
|
|
||||||
- akasurde
|
|
||||||
- tima
|
|
||||||
reviewers:
|
reviewers:
|
||||||
- geerlingguy
|
- community.okd-reviewers
|
||||||
- fabianvf
|
|
||||||
- maxamillion
|
|
||||||
- akasurde
|
|
||||||
- tima
|
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
aliases:
|
||||||
|
community.okd-approvers:
|
||||||
|
- gravesm
|
||||||
|
- akasurde
|
||||||
|
- fabianvf
|
||||||
|
- tima
|
||||||
|
- goneri
|
||||||
|
- jillr
|
||||||
|
- alinabuzachis
|
||||||
|
- abikouo
|
||||||
|
community.okd-reviewers:
|
||||||
|
- gravesm
|
||||||
|
- akasurde
|
||||||
|
- fabianvf
|
||||||
|
- tima
|
||||||
|
- goneri
|
||||||
|
- jillr
|
||||||
|
- alinabuzachis
|
||||||
|
- abikouo
|
||||||
@@ -7,21 +7,40 @@ This repo hosts the `community.okd` Ansible Collection.
|
|||||||
|
|
||||||
The collection includes a variety of Ansible content to help automate the management of applications in OKD clusters, as well as the provisioning and maintenance of clusters themselves.
|
The collection includes a variety of Ansible content to help automate the management of applications in OKD clusters, as well as the provisioning and maintenance of clusters themselves.
|
||||||
|
|
||||||
|
<!--start requires_ansible-->
|
||||||
|
## Ansible version compatibility
|
||||||
|
|
||||||
|
This collection has been tested against following Ansible versions: **>=2.9.17**.
|
||||||
|
|
||||||
|
Plugins and modules within a collection may be tested with only specific Ansible versions.
|
||||||
|
A collection may contain metadata that identifies these versions.
|
||||||
|
PEP440 is the schema used to describe the versions of Ansible.
|
||||||
|
<!--end requires_ansible-->
|
||||||
|
|
||||||
## Included content
|
## Included content
|
||||||
|
|
||||||
Click on the name of a plugin or module to view that content's documentation:
|
Click on the name of a plugin or module to view that content's documentation:
|
||||||
|
|
||||||
- **Connection Plugins**:
|
<!--start collection content-->
|
||||||
- [oc](https://docs.ansible.com/ansible/2.10/collections/community/general/oc_connection.html)
|
### Connection plugins
|
||||||
- **Inventory Plugins**:
|
Name | Description
|
||||||
- [openshift](https://docs.ansible.com/ansible/2.10/collections/community/kubernetes/openshift_inventory.html)
|
--- | ---
|
||||||
- **Modules**:
|
[community.okd.oc](https://github.com/ansible-collections/community.okd/blob/main/docs/community.okd.oc_connection.rst)|Execute tasks in pods running on OpenShift.
|
||||||
- [k8s](https://docs.ansible.com/ansible/2.10/collections/community/kubernetes/k8s_inventory.html)
|
|
||||||
- [openshift_auth](https://github.com/ansible-collections/community.okd/blob/main/plugins/modules/openshift_auth.py)
|
|
||||||
- [openshift_process](https://github.com/ansible-collections/community.okd/blob/main/plugins/modules/openshift_process.py)
|
|
||||||
- [openshift_route](https://github.com/ansible-collections/community.okd/blob/main/plugins/modules/openshift_route.py)
|
|
||||||
|
|
||||||
> **Note**: Some of these documentation links currently link to older module versions. For the latest module documentation, please use `ansible-doc` in the CLI.
|
### Inventory plugins
|
||||||
|
Name | Description
|
||||||
|
--- | ---
|
||||||
|
[community.okd.openshift](https://github.com/ansible-collections/community.okd/blob/main/docs/community.okd.openshift_inventory.rst)|OpenShift inventory source
|
||||||
|
|
||||||
|
### Modules
|
||||||
|
Name | Description
|
||||||
|
--- | ---
|
||||||
|
[community.okd.k8s](https://github.com/ansible-collections/community.okd/blob/main/docs/community.okd.k8s_module.rst)|Manage OpenShift objects
|
||||||
|
[community.okd.openshift_auth](https://github.com/ansible-collections/community.okd/blob/main/docs/community.okd.openshift_auth_module.rst)|Authenticate to OpenShift clusters which require an explicit login step
|
||||||
|
[community.okd.openshift_process](https://github.com/ansible-collections/community.okd/blob/main/docs/community.okd.openshift_process_module.rst)|Process an OpenShift template.openshift.io/v1 Template
|
||||||
|
[community.okd.openshift_route](https://github.com/ansible-collections/community.okd/blob/main/docs/community.okd.openshift_route_module.rst)|Expose a Service as an OpenShift Route.
|
||||||
|
|
||||||
|
<!--end collection content-->
|
||||||
|
|
||||||
<!--- ENDREMOVE --->
|
<!--- ENDREMOVE --->
|
||||||
|
|
||||||
@@ -39,14 +58,14 @@ You can also include it in a `requirements.yml` file and install it via `ansible
|
|||||||
---
|
---
|
||||||
collections:
|
collections:
|
||||||
- name: community.okd
|
- name: community.okd
|
||||||
version: 1.1.1
|
version: 2.1.0
|
||||||
```
|
```
|
||||||
|
|
||||||
### Installing the OpenShift Python Library
|
### Installing the Kubernetes Python Library
|
||||||
|
|
||||||
Content in this collection requires the [OpenShift Python client](https://pypi.org/project/openshift/) to interact with Kubernetes' APIs. You can install it with:
|
Content in this collection requires the [Kubernetes Python client](https://pypi.org/project/kubernetes/) to interact with Kubernetes' APIs. You can install it with:
|
||||||
|
|
||||||
pip3 install openshift
|
pip3 install kubernetes
|
||||||
|
|
||||||
### Using modules from the OKD Collection in your playbooks
|
### Using modules from the OKD Collection in your playbooks
|
||||||
|
|
||||||
@@ -62,6 +81,22 @@ connections:
|
|||||||
|
|
||||||
For documentation on how to use individual plugins included in this collection, please see the links in the 'Included content' section earlier in this README.
|
For documentation on how to use individual plugins included in this collection, please see the links in the 'Included content' section earlier in this README.
|
||||||
|
|
||||||
|
## Ansible Turbo mode Tech Preview
|
||||||
|
|
||||||
|
|
||||||
|
The ``community.okd`` collection supports Ansible Turbo mode as a tech preview via the ``cloud.common`` collection. By default, this feature is disabled. To enable Turbo mode, set the environment variable `ENABLE_TURBO_MODE=1` on the managed node. For example:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
---
|
||||||
|
- hosts: remote
|
||||||
|
environment:
|
||||||
|
ENABLE_TURBO_MODE: 1
|
||||||
|
tasks:
|
||||||
|
...
|
||||||
|
```
|
||||||
|
|
||||||
|
Please read more about Ansible Turbo mode - [here](https://github.com/ansible-collections/community.okd/blob/main/docs/ansible_turbo_mode.rst).
|
||||||
|
|
||||||
<!--- STARTREMOVE --->
|
<!--- STARTREMOVE --->
|
||||||
## Testing and Development
|
## Testing and Development
|
||||||
|
|
||||||
@@ -87,9 +122,9 @@ These commands will create a directory called `ansible_collections` which should
|
|||||||
### Prow
|
### Prow
|
||||||
|
|
||||||
This repository uses the OpenShift [Prow](https://github.com/kubernetes/test-infra/blob/master/prow/README.md) instance for testing against live OpenShift clusters.
|
This repository uses the OpenShift [Prow](https://github.com/kubernetes/test-infra/blob/master/prow/README.md) instance for testing against live OpenShift clusters.
|
||||||
The configuration for the CI jobs that this repository runs can be found in the [`openshift/release repository`](https://github.com/openshift/release/blob/master/ci-operator/config/ansible-collections/community.okd/ansible-collections-community.okd-main.yaml).
|
The configuration for the CI jobs that this repository runs can be found in the [`openshift/release repository`](https://github.com/openshift/release/blob/master/ci-operator/config/openshift/community.okd/openshift-community.okd-main.yaml).
|
||||||
|
|
||||||
The [Prow CI integration test job](https://github.com/openshift/release/blob/master/ci-operator/config/ansible-collections/community.okd/ansible-collections-community.okd-main.yaml#L35-L38)
|
The [Prow CI integration test job](https://github.com/openshift/release/blob/master/ci-operator/config/openshift/community.okd/openshift-community.okd-main.yaml#L40-L43)
|
||||||
runs the command:
|
runs the command:
|
||||||
|
|
||||||
make test-integration-incluster
|
make test-integration-incluster
|
||||||
@@ -123,7 +158,7 @@ After the version is published, verify it exists on the [OKD Collection Galaxy p
|
|||||||
|
|
||||||
## More Information
|
## More Information
|
||||||
|
|
||||||
For more information about Ansible's Kubernetes and OpenShift integrations, join the `#ansible-kubernetes` channel on Freenode IRC, and browse the resources in the [Kubernetes Working Group](https://github.com/ansible/community/wiki/Kubernetes) Community wiki page.
|
For more information about Ansible's Kubernetes and OpenShift integrations, join the `#ansible-kubernetes` channel on [libera.chat](https://libera.chat/) IRC, and browse the resources in the [Kubernetes Working Group](https://github.com/ansible/community/wiki/Kubernetes) Community wiki page.
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
|
|||||||
@@ -102,3 +102,50 @@ releases:
|
|||||||
- 78-add-requirements-file.yaml
|
- 78-add-requirements-file.yaml
|
||||||
- 80-update-ci.yaml
|
- 80-update-ci.yaml
|
||||||
release_date: '2021-04-06'
|
release_date: '2021-04-06'
|
||||||
|
1.1.2:
|
||||||
|
changes:
|
||||||
|
bugfixes:
|
||||||
|
- include requirements.txt in downstream build process (https://github.com/ansible-collections/community.okd/pull/81).
|
||||||
|
fragments:
|
||||||
|
- 81-include-requirements.yaml
|
||||||
|
release_date: '2021-04-08'
|
||||||
|
2.0.0:
|
||||||
|
changes:
|
||||||
|
breaking_changes:
|
||||||
|
- drop python 2 support (https://github.com/openshift/community.okd/pull/93).
|
||||||
|
bugfixes:
|
||||||
|
- fixes test suite to use correct versions of python and dependencies (https://github.com/ansible-collections/community.okd/pull/89).
|
||||||
|
- openshift_process - fix module execution when template does not include a
|
||||||
|
message (https://github.com/ansible-collections/community.okd/pull/87).
|
||||||
|
major_changes:
|
||||||
|
- update to use kubernetes.core 2.0 (https://github.com/openshift/community.okd/pull/93).
|
||||||
|
minor_changes:
|
||||||
|
- Added documentation for the ``community.okd`` collection.
|
||||||
|
- openshift - inventory plugin supports FQCN ``redhat.openshift``.
|
||||||
|
fragments:
|
||||||
|
- 87-openshift_process-fix-template-without-message.yaml
|
||||||
|
- 89-clean-up-ci.yaml
|
||||||
|
- 93-update-to-k8s-2.yaml
|
||||||
|
- add_docs.yml
|
||||||
|
- fqcn_inventory.yml
|
||||||
|
release_date: '2021-06-22'
|
||||||
|
2.0.1:
|
||||||
|
changes:
|
||||||
|
minor_changes:
|
||||||
|
- increase kubernetes.core dependency version (https://github.com/openshift/community.okd/pull/97).
|
||||||
|
fragments:
|
||||||
|
- 97-bump-k8s-version.yaml
|
||||||
|
release_date: '2021-06-24'
|
||||||
|
2.1.0:
|
||||||
|
changes:
|
||||||
|
bugfixes:
|
||||||
|
- fix broken links in Automation Hub for redhat.openshift (https://github.com/openshift/community.okd/issues/100).
|
||||||
|
minor_changes:
|
||||||
|
- add support for turbo mode (https://github.com/openshift/community.okd/pull/102).
|
||||||
|
- openshift_route - Add support for Route annotations (https://github.com/ansible-collections/community.okd/pull/99).
|
||||||
|
fragments:
|
||||||
|
- 0-copy_ignore_txt.yml
|
||||||
|
- 100-fix-broken-links.yml
|
||||||
|
- 102-support-turbo-mode.yaml
|
||||||
|
- 99-openshift_route-add-support-for-annotations.yml
|
||||||
|
release_date: '2021-10-20'
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ changelog_filename_template: ../CHANGELOG.rst
|
|||||||
changelog_filename_version_depth: 0
|
changelog_filename_version_depth: 0
|
||||||
changes_file: changelog.yaml
|
changes_file: changelog.yaml
|
||||||
changes_format: combined
|
changes_format: combined
|
||||||
keep_fragments: true
|
keep_fragments: false
|
||||||
mention_ancestor: true
|
mention_ancestor: true
|
||||||
new_plugins_after_name: removed_features
|
new_plugins_after_name: removed_features
|
||||||
notesdir: fragments
|
notesdir: fragments
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
---
|
|
||||||
major_changes:
|
|
||||||
- Initial content migration from community.kubernetes (https://github.com/ansible-collections/community.okd/pull/3).
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
---
|
|
||||||
minor_changes:
|
|
||||||
- Dockerfile now is properly set up to run tests in a rootless container (https://github.com/ansible-collections/community.okd/pull/11).
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
---
|
|
||||||
minor_changes:
|
|
||||||
- Docker container can run as an arbitrary user (https://github.com/ansible-collections/community.okd/pull/12).
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
---
|
|
||||||
minor_changes:
|
|
||||||
- Add incluster Makefile target for CI (https://github.com/ansible-collections/community.okd/pull/13).
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
---
|
|
||||||
minor_changes:
|
|
||||||
- CI Documentation for working with Prow (https://github.com/ansible-collections/community.okd/pull/15).
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
---
|
|
||||||
minor_changes:
|
|
||||||
- Add tests for inventory plugin (https://github.com/ansible-collections/community.okd/pull/16).
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
---
|
|
||||||
major_changes:
|
|
||||||
- Add openshift connection plugin, update inventory plugin to use it (https://github.com/ansible-collections/community.okd/pull/18).
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
---
|
|
||||||
major_changes:
|
|
||||||
- Add downstream build scripts to build redhat.openshift (https://github.com/ansible-collections/community.okd/pull/20).
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
---
|
|
||||||
minor_changes:
|
|
||||||
- Use the API Group APIVersion for the `Route` object (https://github.com/ansible-collections/community.okd/pull/27).
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
---
|
|
||||||
major_changes:
|
|
||||||
- openshift_auth - new module (migrated from k8s_auth in community.kubernetes) (https://github.com/ansible-collections/community.okd/pull/33).
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
---
|
|
||||||
minor_changes:
|
|
||||||
- Add a contribution guide (https://github.com/ansible-collections/community.okd/pull/37).
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
---
|
|
||||||
major_changes:
|
|
||||||
- Add openshift_route module for creating routes from services (https://github.com/ansible-collections/community.okd/pull/40).
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
---
|
|
||||||
major_changes:
|
|
||||||
- Add openshift_process module for template rendering and optional application of rendered resources (https://github.com/ansible-collections/community.okd/pull/44).
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
---
|
|
||||||
minor_changes:
|
|
||||||
- Released version 1 to Automation Hub as redhat.openshift (https://github.com/ansible-collections/community.okd/issues/51).
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
---
|
|
||||||
bugfixes:
|
|
||||||
- Generate downstream redhat.openshift documentation (https://github.com/ansible-collections/community.okd/pull/59).
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
minor_changes:
|
|
||||||
- restrict the version of kubernetes.core dependency (https://github.com/ansible-collections/community.okd/pull/66).
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
---
|
|
||||||
major_changes:
|
|
||||||
- Add custom k8s module, integrate better Molecule tests (https://github.com/ansible-collections/community.okd/pull/7).
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
minor_changes:
|
|
||||||
- increase the kubernetes.core dependency version number (https://github.com/ansible-collections/community.okd/pull/71).
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
bugfixes:
|
|
||||||
- restrict molecule version to <3.3.0 to address breaking change (https://github.com/ansible-collections/community.okd/pull/77).
|
|
||||||
- openshift_route - default to ``no_log=False`` for the ``key`` parameter in TLS configuration to fix sanity failures (https://github.com/ansible-collections/community.okd/pull/77).
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
bugfixes:
|
|
||||||
- add missing requirements.txt file needed for execution environments (https://github.com/ansible-collections/community.okd/pull/78).
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
---
|
|
||||||
minor_changes:
|
|
||||||
- Integrate stale bot for issue queue maintenance (https://github.com/ansible-collections/community.okd/pull/14).
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
bugfixes:
|
|
||||||
- update CI to work with ansible 2.11 (https://github.com/ansible-collections/community.okd/pull/80).
|
|
||||||
+1
-1
@@ -16,7 +16,7 @@ RUN yum install -y \
|
|||||||
python3-setuptools \
|
python3-setuptools \
|
||||||
&& pip3 install --no-cache-dir --upgrade setuptools pip \
|
&& pip3 install --no-cache-dir --upgrade setuptools pip \
|
||||||
&& pip3 install --no-cache-dir \
|
&& pip3 install --no-cache-dir \
|
||||||
openshift \
|
kubernetes \
|
||||||
ansible==2.9.* \
|
ansible==2.9.* \
|
||||||
"molecule<3.3.0" \
|
"molecule<3.3.0" \
|
||||||
&& yum clean all \
|
&& yum clean all \
|
||||||
|
|||||||
+13
-34
@@ -9,7 +9,7 @@
|
|||||||
# - All functions are prefixed with f_ so it's obvious where they come
|
# - All functions are prefixed with f_ so it's obvious where they come
|
||||||
# from when in use throughout the script
|
# from when in use throughout the script
|
||||||
|
|
||||||
DOWNSTREAM_VERSION="1.1.1"
|
DOWNSTREAM_VERSION="2.1.0"
|
||||||
KEEP_DOWNSTREAM_TMPDIR="${KEEP_DOWNSTREAM_TMPDIR:-''}"
|
KEEP_DOWNSTREAM_TMPDIR="${KEEP_DOWNSTREAM_TMPDIR:-''}"
|
||||||
_build_dir=""
|
_build_dir=""
|
||||||
|
|
||||||
@@ -46,7 +46,7 @@ f_text_sub()
|
|||||||
sed -i.bak "s/^version\:.*$/version: ${DOWNSTREAM_VERSION}/" "${_build_dir}/galaxy.yml"
|
sed -i.bak "s/^version\:.*$/version: ${DOWNSTREAM_VERSION}/" "${_build_dir}/galaxy.yml"
|
||||||
sed -i.bak "/STARTREMOVE/,/ENDREMOVE/d" "${_build_dir}/README.md"
|
sed -i.bak "/STARTREMOVE/,/ENDREMOVE/d" "${_build_dir}/README.md"
|
||||||
|
|
||||||
find "${_build_dir}" -type f -exec sed -i.bak "s/community\.okd/redhat\.openshift/g" {} \;
|
find "${_build_dir}" -type f ! -name galaxy.yml -exec sed -i.bak "s/community\.okd/redhat\.openshift/g" {} \;
|
||||||
find "${_build_dir}" -type f -name "*.bak" -delete
|
find "${_build_dir}" -type f -name "*.bak" -delete
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,6 +66,8 @@ f_prep()
|
|||||||
Makefile
|
Makefile
|
||||||
setup.cfg
|
setup.cfg
|
||||||
.yamllint
|
.yamllint
|
||||||
|
requirements.txt
|
||||||
|
requirements.yml
|
||||||
)
|
)
|
||||||
|
|
||||||
# Directories to recursively copy downstream (relative repo root dir path)
|
# Directories to recursively copy downstream (relative repo root dir path)
|
||||||
@@ -178,17 +180,6 @@ f_handle_doc_fragments_workaround()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
f_install_kubernetes_core()
|
|
||||||
{
|
|
||||||
f_log_info "${FUNCNAME[0]}"
|
|
||||||
local install_collections_dir="${_tmp_dir}/ansible_collections"
|
|
||||||
|
|
||||||
pushd "${_tmp_dir}"
|
|
||||||
ansible-galaxy collection install -p "${install_collections_dir}" kubernetes.core
|
|
||||||
popd
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
f_copy_collection_to_working_dir()
|
f_copy_collection_to_working_dir()
|
||||||
{
|
{
|
||||||
f_log_info "${FUNCNAME[0]}"
|
f_log_info "${FUNCNAME[0]}"
|
||||||
@@ -210,20 +201,15 @@ f_test_sanity_option()
|
|||||||
{
|
{
|
||||||
f_log_info "${FUNCNAME[0]}"
|
f_log_info "${FUNCNAME[0]}"
|
||||||
f_common_steps
|
f_common_steps
|
||||||
f_install_kubernetes_core
|
|
||||||
pushd "${_build_dir}" || return
|
pushd "${_build_dir}" || return
|
||||||
ansible-galaxy collection build
|
|
||||||
f_log_info "SANITY TEST PWD: ${PWD}"
|
|
||||||
## Can't do this because the upstream kubernetes.core dependency logic
|
|
||||||
## is bound as a Makefile dep to the test-sanity target
|
|
||||||
#SANITY_TEST_ARGS="--docker --color --python 3.6" make test-sanity
|
|
||||||
# Run tests in docker if available, venv otherwise
|
|
||||||
if command -v docker &> /dev/null
|
if command -v docker &> /dev/null
|
||||||
then
|
then
|
||||||
ansible-test sanity --docker -v --exclude ci/ --color --python 3.6
|
make sanity
|
||||||
else
|
else
|
||||||
ansible-test sanity --venv -v --exclude ci/ --color --python 3.6
|
SANITY_TEST_ARGS="--venv --color" make sanity
|
||||||
fi
|
fi
|
||||||
|
f_log_info "SANITY TEST PWD: ${PWD}"
|
||||||
|
make sanity
|
||||||
popd || return
|
popd || return
|
||||||
f_cleanup
|
f_cleanup
|
||||||
}
|
}
|
||||||
@@ -233,10 +219,9 @@ f_test_integration_option()
|
|||||||
{
|
{
|
||||||
f_log_info "${FUNCNAME[0]}"
|
f_log_info "${FUNCNAME[0]}"
|
||||||
f_common_steps
|
f_common_steps
|
||||||
f_install_kubernetes_core
|
|
||||||
pushd "${_build_dir}" || return
|
pushd "${_build_dir}" || return
|
||||||
f_log_info "INTEGRATION TEST WD: ${PWD}"
|
f_log_info "INTEGRATION TEST WD: ${PWD}"
|
||||||
OVERRIDE_COLLECTION_PATH="${_tmp_dir}" molecule test
|
make molecule
|
||||||
popd || return
|
popd || return
|
||||||
f_cleanup
|
f_cleanup
|
||||||
}
|
}
|
||||||
@@ -248,13 +233,7 @@ f_build_option()
|
|||||||
f_common_steps
|
f_common_steps
|
||||||
pushd "${_build_dir}" || return
|
pushd "${_build_dir}" || return
|
||||||
f_log_info "BUILD WD: ${PWD}"
|
f_log_info "BUILD WD: ${PWD}"
|
||||||
# FIXME
|
make build
|
||||||
# This doesn't work because we end up either recursively curl'ing
|
|
||||||
# kubernetes.core and redoing the text replacement over and over
|
|
||||||
#
|
|
||||||
# make build
|
|
||||||
ansible-galaxy collection build
|
|
||||||
|
|
||||||
popd || return
|
popd || return
|
||||||
f_copy_collection_to_working_dir
|
f_copy_collection_to_working_dir
|
||||||
f_cleanup
|
f_cleanup
|
||||||
|
|||||||
@@ -13,7 +13,11 @@ NAMESPACE=${NAMESPACE:-default}
|
|||||||
# would resolve to quay.io/mynamespace/molecule-test-runner
|
# would resolve to quay.io/mynamespace/molecule-test-runner
|
||||||
# shellcheck disable=SC2034
|
# shellcheck disable=SC2034
|
||||||
component='molecule-test-runner'
|
component='molecule-test-runner'
|
||||||
eval IMAGE="$IMAGE_FORMAT"
|
if [[ -n "${MOLECULE_IMAGE}" ]]; then
|
||||||
|
IMAGE="${MOLECULE_IMAGE}"
|
||||||
|
else
|
||||||
|
IMAGE="${IMAGE_FORMAT}"
|
||||||
|
fi
|
||||||
|
|
||||||
PULL_POLICY=${PULL_POLICY:-IfNotPresent}
|
PULL_POLICY=${PULL_POLICY:-IfNotPresent}
|
||||||
|
|
||||||
@@ -84,4 +88,5 @@ do
|
|||||||
sleep 10
|
sleep 10
|
||||||
done
|
done
|
||||||
|
|
||||||
|
oc logs job/molecule-integration-test
|
||||||
exit 1
|
exit 1
|
||||||
|
|||||||
@@ -0,0 +1,147 @@
|
|||||||
|
.. _ansible_turbo_mode:
|
||||||
|
|
||||||
|
|
||||||
|
******************
|
||||||
|
Ansible Turbo mode
|
||||||
|
******************
|
||||||
|
|
||||||
|
Following document provides overview of Ansible Turbo mode in ``community.okd`` collection.
|
||||||
|
|
||||||
|
.. contents::
|
||||||
|
:local:
|
||||||
|
:depth: 1
|
||||||
|
|
||||||
|
|
||||||
|
Synopsis
|
||||||
|
--------
|
||||||
|
- A brief introduction about Ansible Turbo mode in ``community.okd`` collection.
|
||||||
|
- Ansible Turbo mode is an optional performance optimization. It can be enabled by installing the cloud.common collection and setting the ``ENABLE_TURBO_MODE`` environment variable.
|
||||||
|
|
||||||
|
Requirements
|
||||||
|
------------
|
||||||
|
|
||||||
|
The following requirement is needed on the host that executes this module.
|
||||||
|
|
||||||
|
- The ``cloud.common`` collection (https://github.com/ansible-collections/cloud.common)
|
||||||
|
|
||||||
|
You will also need to set the environment variable ``ENABLE_TURBO_MODE=1`` on the managed host. This can be done in the same ways you would usually do so, for example::
|
||||||
|
|
||||||
|
---
|
||||||
|
- hosts: remote
|
||||||
|
environment:
|
||||||
|
ENABLE_TURBO_MODE: 1
|
||||||
|
tasks:
|
||||||
|
...
|
||||||
|
|
||||||
|
|
||||||
|
Installation
|
||||||
|
------------
|
||||||
|
|
||||||
|
You can install ``cloud.common`` collection using following command::
|
||||||
|
|
||||||
|
# ansible-galaxy collection install cloud.common
|
||||||
|
|
||||||
|
|
||||||
|
Current situation without Ansible Turbo mode
|
||||||
|
============================================
|
||||||
|
|
||||||
|
The traditional execution flow of an Ansible module includes the following steps:
|
||||||
|
|
||||||
|
- Upload of a ZIP archive with the module and its dependencies
|
||||||
|
- Execution of the module
|
||||||
|
- Ansible collects the results once the script is finished
|
||||||
|
|
||||||
|
These steps happen for each task of a playbook, and on every host.
|
||||||
|
|
||||||
|
Most of the time, the execution of a module is fast enough for
|
||||||
|
the user. However, sometime the module requires significant amount of time,
|
||||||
|
just to initialize itself. This is a common situation with the API based modules.
|
||||||
|
|
||||||
|
A classic initialization involves the following steps:
|
||||||
|
|
||||||
|
- Load a Python library to access the remote resource (via SDK)
|
||||||
|
- Open a client
|
||||||
|
- Load a bunch of Python modules.
|
||||||
|
- Request a new TCP connection.
|
||||||
|
- Create a session.
|
||||||
|
- Authenticate the client.
|
||||||
|
|
||||||
|
All these steps are time consuming and the same operations will be running again and again.
|
||||||
|
|
||||||
|
For instance, here:
|
||||||
|
|
||||||
|
- ``import openstack``: takes 0.569s
|
||||||
|
- ``client = openstack.connect()``: takes 0.065s
|
||||||
|
- ``client.authorize()``: takes 1.360s,
|
||||||
|
|
||||||
|
These numbers are from test running against VexxHost public cloud.
|
||||||
|
|
||||||
|
In this case, it's a 2s-ish overhead per task. If the playbook
|
||||||
|
comes with 10 tasks, the execution time cannot go below 20s.
|
||||||
|
|
||||||
|
How Ansible Turbo Module improve the situation
|
||||||
|
==============================================
|
||||||
|
|
||||||
|
``AnsibleTurboModule`` is actually a class that inherites from
|
||||||
|
the standard ``AnsibleModule`` class that your modules probably
|
||||||
|
already use.
|
||||||
|
The big difference is that when a module starts, it also spawns
|
||||||
|
a little Python daemon. If a daemon already exists, it will just
|
||||||
|
reuse it.
|
||||||
|
All the module logic is run inside this Python daemon. This means:
|
||||||
|
|
||||||
|
- Python modules are actually loaded one time
|
||||||
|
- Ansible module can reuse an existing authenticated session.
|
||||||
|
|
||||||
|
The background service
|
||||||
|
======================
|
||||||
|
|
||||||
|
The daemon kills itself after 15s, and communication are done
|
||||||
|
through an Unix socket.
|
||||||
|
It runs in one single process and uses ``asyncio`` internally.
|
||||||
|
Consequently you can use the ``async`` keyword in your Ansible module.
|
||||||
|
This will be handy if you interact with a lot of remote systems
|
||||||
|
at the same time.
|
||||||
|
|
||||||
|
Security impact
|
||||||
|
===============
|
||||||
|
|
||||||
|
``ansible_module.turbo`` open an Unix socket to interact with the background service.
|
||||||
|
We use this service to open the connection toward the different target systems.
|
||||||
|
|
||||||
|
This is similar to what SSH does with the sockets.
|
||||||
|
|
||||||
|
Keep in mind that:
|
||||||
|
|
||||||
|
- All the modules can access the same cache. Soon an isolation will be done at the collection level (https://github.com/ansible-collections/cloud.common/pull/17)
|
||||||
|
- A task can load a different version of a library and impact the next tasks.
|
||||||
|
- If the same user runs two ``ansible-playbook`` at the same time, they will have access to the same cache.
|
||||||
|
|
||||||
|
When a module stores a session in a cache, it's a good idea to use a hash of the authentication information to identify the session.
|
||||||
|
|
||||||
|
Error management
|
||||||
|
================
|
||||||
|
|
||||||
|
``ansible_module.turbo`` uses exceptions to communicate a result back to the module.
|
||||||
|
|
||||||
|
- ``EmbeddedModuleFailure`` is raised when ``json_fail()`` is called.
|
||||||
|
- ``EmbeddedModuleSuccess`` is raised in case of success and returns the result to the origin module process.
|
||||||
|
|
||||||
|
These exceptions are defined in ``ansible_collections.cloud.common.plugins.module_utils.turbo.exceptions``.
|
||||||
|
You can raise ``EmbeddedModuleFailure`` exception yourself, for instance from a module in ``module_utils``.
|
||||||
|
|
||||||
|
.. note:: Be careful with the ``except Exception:`` blocks.
|
||||||
|
Not only they are bad practice, but also may interface with this
|
||||||
|
mechanism.
|
||||||
|
|
||||||
|
|
||||||
|
Troubleshooting
|
||||||
|
===============
|
||||||
|
|
||||||
|
You may want to manually start the server. This can be done with the following command:
|
||||||
|
|
||||||
|
.. code-block:: shell
|
||||||
|
|
||||||
|
PYTHONPATH=$HOME/.ansible/collections python -m ansible_collections.cloud.common.plugins.module_utils.turbo.server --socket-path $HOME/.ansible/tmp/turbo_mode.kubernetes.core.socket
|
||||||
|
|
||||||
|
You can use the ``--help`` argument to get a list of the optional parameters.
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,315 @@
|
|||||||
|
.. _community.okd.oc_connection:
|
||||||
|
|
||||||
|
|
||||||
|
****************
|
||||||
|
community.okd.oc
|
||||||
|
****************
|
||||||
|
|
||||||
|
**Execute tasks in pods running on OpenShift.**
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
.. contents::
|
||||||
|
:local:
|
||||||
|
:depth: 1
|
||||||
|
|
||||||
|
|
||||||
|
Synopsis
|
||||||
|
--------
|
||||||
|
- Use the oc exec command to run tasks in, or put/fetch files to, pods running on the OpenShift container platform.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Requirements
|
||||||
|
------------
|
||||||
|
The below requirements are needed on the local Ansible controller node that executes this connection.
|
||||||
|
|
||||||
|
- oc (go binary)
|
||||||
|
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
|
||||||
|
.. raw:: html
|
||||||
|
|
||||||
|
<table border=0 cellpadding=0 class="documentation-table">
|
||||||
|
<tr>
|
||||||
|
<th colspan="1">Parameter</th>
|
||||||
|
<th>Choices/<font color="blue">Defaults</font></th>
|
||||||
|
<th>Configuration</th>
|
||||||
|
<th width="100%">Comments</th>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>ca_cert</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">-</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<b>Default:</b><br/><div style="color: blue">""</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>env:K8S_AUTH_SSL_CA_CERT</div>
|
||||||
|
<div>var: ansible_oc_ssl_ca_cert</div>
|
||||||
|
<div>var: ansible_oc_ca_cert</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Path to a CA certificate used to authenticate with the API.</div>
|
||||||
|
<div style="font-size: small; color: darkgreen"><br/>aliases: oc_ssl_ca_cert</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>client_cert</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">-</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<b>Default:</b><br/><div style="color: blue">""</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>env:K8S_AUTH_CERT_FILE</div>
|
||||||
|
<div>var: ansible_oc_cert_file</div>
|
||||||
|
<div>var: ansible_oc_client_cert</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Path to a certificate used to authenticate with the API.</div>
|
||||||
|
<div style="font-size: small; color: darkgreen"><br/>aliases: oc_cert_file</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>client_key</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">-</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<b>Default:</b><br/><div style="color: blue">""</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>env:K8S_AUTH_KEY_FILE</div>
|
||||||
|
<div>var: ansible_oc_key_file</div>
|
||||||
|
<div>var: ansible_oc_client_key</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Path to a key file used to authenticate with the API.</div>
|
||||||
|
<div style="font-size: small; color: darkgreen"><br/>aliases: oc_key_file</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>oc_container</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">-</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<b>Default:</b><br/><div style="color: blue">""</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>env:K8S_AUTH_CONTAINER</div>
|
||||||
|
<div>var: ansible_oc_container</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Container name. Required when a pod contains more than one container.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>oc_context</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">-</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<b>Default:</b><br/><div style="color: blue">""</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>env:K8S_AUTH_CONTEXT</div>
|
||||||
|
<div>var: ansible_oc_context</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>The name of a context found in the K8s config file.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>oc_extra_args</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">-</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<b>Default:</b><br/><div style="color: blue">""</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>env:K8S_AUTH_EXTRA_ARGS</div>
|
||||||
|
<div>var: ansible_oc_extra_args</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Extra arguments to pass to the oc command line.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>oc_host</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">-</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<b>Default:</b><br/><div style="color: blue">""</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>env:K8S_AUTH_HOST</div>
|
||||||
|
<div>env:K8S_AUTH_SERVER</div>
|
||||||
|
<div>var: ansible_oc_host</div>
|
||||||
|
<div>var: ansible_oc_server</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>URL for accessing the API.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>oc_kubeconfig</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">-</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<b>Default:</b><br/><div style="color: blue">""</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>env:K8S_AUTH_KUBECONFIG</div>
|
||||||
|
<div>var: ansible_oc_kubeconfig</div>
|
||||||
|
<div>var: ansible_oc_config</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Path to a oc config file. Defaults to <em>~/.kube/config</em></div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>oc_namespace</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">-</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<b>Default:</b><br/><div style="color: blue">""</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>env:K8S_AUTH_NAMESPACE</div>
|
||||||
|
<div>var: ansible_oc_namespace</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>The namespace of the pod</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>oc_pod</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">-</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<b>Default:</b><br/><div style="color: blue">""</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>env:K8S_AUTH_POD</div>
|
||||||
|
<div>var: ansible_oc_pod</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Pod name. Required when the host name does not match pod name.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>oc_token</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">-</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>env:K8S_AUTH_TOKEN</div>
|
||||||
|
<div>env:K8S_AUTH_API_KEY</div>
|
||||||
|
<div>var: ansible_oc_token</div>
|
||||||
|
<div>var: ansible_oc_api_key</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>API authentication bearer token.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>validate_certs</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">-</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<b>Default:</b><br/><div style="color: blue">""</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>env:K8S_AUTH_VERIFY_SSL</div>
|
||||||
|
<div>var: ansible_oc_verify_ssl</div>
|
||||||
|
<div>var: ansible_oc_validate_certs</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Whether or not to verify the API server's SSL certificate. Defaults to <em>true</em>.</div>
|
||||||
|
<div style="font-size: small; color: darkgreen"><br/>aliases: oc_verify_ssl</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
<br/>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Status
|
||||||
|
------
|
||||||
|
|
||||||
|
|
||||||
|
Authors
|
||||||
|
~~~~~~~
|
||||||
|
|
||||||
|
- xuxinkun
|
||||||
|
|
||||||
|
|
||||||
|
.. hint::
|
||||||
|
Configuration entries for each entry type have a low to high priority order. For example, a variable that is lower in the list will override a variable that is higher up.
|
||||||
@@ -0,0 +1,424 @@
|
|||||||
|
.. _community.okd.openshift_auth_module:
|
||||||
|
|
||||||
|
|
||||||
|
****************************
|
||||||
|
community.okd.openshift_auth
|
||||||
|
****************************
|
||||||
|
|
||||||
|
**Authenticate to OpenShift clusters which require an explicit login step**
|
||||||
|
|
||||||
|
|
||||||
|
Version added: 0.2.0
|
||||||
|
|
||||||
|
.. contents::
|
||||||
|
:local:
|
||||||
|
:depth: 1
|
||||||
|
|
||||||
|
|
||||||
|
Synopsis
|
||||||
|
--------
|
||||||
|
- This module handles authenticating to OpenShift clusters requiring *explicit* authentication procedures, meaning ones where a client logs in (obtains an authentication token), performs API operations using said token and then logs out (revokes the token).
|
||||||
|
- On the other hand a popular configuration for username+password authentication is one utilizing HTTP Basic Auth, which does not involve any additional login/logout steps (instead login credentials can be attached to each and every API call performed) and as such is handled directly by the ``k8s`` module (and other resource–specific modules) by utilizing the ``host``, ``username`` and ``password`` parameters. Please consult your preferred module's documentation for more details.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Requirements
|
||||||
|
------------
|
||||||
|
The below requirements are needed on the host that executes this module.
|
||||||
|
|
||||||
|
- python >= 3.6
|
||||||
|
- urllib3
|
||||||
|
- requests
|
||||||
|
- requests-oauthlib
|
||||||
|
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
|
||||||
|
.. raw:: html
|
||||||
|
|
||||||
|
<table border=0 cellpadding=0 class="documentation-table">
|
||||||
|
<tr>
|
||||||
|
<th colspan="1">Parameter</th>
|
||||||
|
<th>Choices/<font color="blue">Defaults</font></th>
|
||||||
|
<th width="100%">Comments</th>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>api_key</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>When <code>state</code> is set to <em>absent</em>, this specifies the token to revoke.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>ca_cert</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">path</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Path to a CA certificate file used to verify connection to the API server. The full certificate chain must be provided to avoid certificate validation errors.</div>
|
||||||
|
<div style="font-size: small; color: darkgreen"><br/>aliases: ssl_ca_cert</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>host</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
/ <span style="color: red">required</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Provide a URL for accessing the API server.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>password</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Provide a password for authenticating with the API server.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>state</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<ul style="margin: 0; padding: 0"><b>Choices:</b>
|
||||||
|
<li><div style="color: blue"><b>present</b> ←</div></li>
|
||||||
|
<li>absent</li>
|
||||||
|
</ul>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>If set to <em>present</em> connect to the API server using the URL specified in <code>host</code> and attempt to log in.</div>
|
||||||
|
<div>If set to <em>absent</em> attempt to log out by revoking the authentication token specified in <code>api_key</code>.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>username</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Provide a username for authenticating with the API server.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>validate_certs</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">boolean</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<ul style="margin: 0; padding: 0"><b>Choices:</b>
|
||||||
|
<li>no</li>
|
||||||
|
<li><div style="color: blue"><b>yes</b> ←</div></li>
|
||||||
|
</ul>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Whether or not to verify the API server's SSL certificates.</div>
|
||||||
|
<div style="font-size: small; color: darkgreen"><br/>aliases: verify_ssl</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
<br/>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Examples
|
||||||
|
--------
|
||||||
|
|
||||||
|
.. code-block:: yaml
|
||||||
|
|
||||||
|
- hosts: localhost
|
||||||
|
module_defaults:
|
||||||
|
group/k8s:
|
||||||
|
host: https://k8s.example.com/
|
||||||
|
ca_cert: ca.pem
|
||||||
|
tasks:
|
||||||
|
- block:
|
||||||
|
# It's good practice to store login credentials in a secure vault and not
|
||||||
|
# directly in playbooks.
|
||||||
|
- include_vars: openshift_passwords.yml
|
||||||
|
|
||||||
|
- name: Log in (obtain access token)
|
||||||
|
community.okd.openshift_auth:
|
||||||
|
username: admin
|
||||||
|
password: "{{ openshift_admin_password }}"
|
||||||
|
register: openshift_auth_results
|
||||||
|
|
||||||
|
# Previous task provides the token/api_key, while all other parameters
|
||||||
|
# are taken from module_defaults
|
||||||
|
- name: Get a list of all pods from any namespace
|
||||||
|
kubernetes.core.k8s_info:
|
||||||
|
api_key: "{{ openshift_auth_results.openshift_auth.api_key }}"
|
||||||
|
kind: Pod
|
||||||
|
register: pod_list
|
||||||
|
|
||||||
|
always:
|
||||||
|
- name: If login succeeded, try to log out (revoke access token)
|
||||||
|
when: openshift_auth_results.openshift_auth.api_key is defined
|
||||||
|
community.okd.openshift_auth:
|
||||||
|
state: absent
|
||||||
|
api_key: "{{ openshift_auth_results.openshift_auth.api_key }}"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Return Values
|
||||||
|
-------------
|
||||||
|
Common return values are documented `here <https://docs.ansible.com/ansible/latest/reference_appendices/common_return_values.html#common-return-values>`_, the following are the fields unique to this module:
|
||||||
|
|
||||||
|
.. raw:: html
|
||||||
|
|
||||||
|
<table border=0 cellpadding=0 class="documentation-table">
|
||||||
|
<tr>
|
||||||
|
<th colspan="2">Key</th>
|
||||||
|
<th>Returned</th>
|
||||||
|
<th width="100%">Description</th>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="return-"></div>
|
||||||
|
<b>k8s_auth</b>
|
||||||
|
<a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">complex</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>success</td>
|
||||||
|
<td>
|
||||||
|
<div>Same as returned openshift_auth. Kept only for backwards compatibility</div>
|
||||||
|
<br/>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="elbow-placeholder"> </td>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="return-"></div>
|
||||||
|
<b>api_key</b>
|
||||||
|
<a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>success</td>
|
||||||
|
<td>
|
||||||
|
<div>Authentication token.</div>
|
||||||
|
<br/>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="elbow-placeholder"> </td>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="return-"></div>
|
||||||
|
<b>ca_cert</b>
|
||||||
|
<a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>success</td>
|
||||||
|
<td>
|
||||||
|
<div>Path to a CA certificate file used to verify connection to the API server.</div>
|
||||||
|
<br/>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="elbow-placeholder"> </td>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="return-"></div>
|
||||||
|
<b>host</b>
|
||||||
|
<a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>success</td>
|
||||||
|
<td>
|
||||||
|
<div>URL for accessing the API server.</div>
|
||||||
|
<br/>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="elbow-placeholder"> </td>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="return-"></div>
|
||||||
|
<b>username</b>
|
||||||
|
<a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>success</td>
|
||||||
|
<td>
|
||||||
|
<div>Username for authenticating with the API server.</div>
|
||||||
|
<br/>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="elbow-placeholder"> </td>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="return-"></div>
|
||||||
|
<b>validate_certs</b>
|
||||||
|
<a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">boolean</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>success</td>
|
||||||
|
<td>
|
||||||
|
<div>Whether or not to verify the API server's SSL certificates.</div>
|
||||||
|
<br/>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="return-"></div>
|
||||||
|
<b>openshift_auth</b>
|
||||||
|
<a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">complex</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>success</td>
|
||||||
|
<td>
|
||||||
|
<div>OpenShift authentication facts.</div>
|
||||||
|
<br/>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="elbow-placeholder"> </td>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="return-"></div>
|
||||||
|
<b>api_key</b>
|
||||||
|
<a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>success</td>
|
||||||
|
<td>
|
||||||
|
<div>Authentication token.</div>
|
||||||
|
<br/>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="elbow-placeholder"> </td>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="return-"></div>
|
||||||
|
<b>ca_cert</b>
|
||||||
|
<a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>success</td>
|
||||||
|
<td>
|
||||||
|
<div>Path to a CA certificate file used to verify connection to the API server.</div>
|
||||||
|
<br/>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="elbow-placeholder"> </td>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="return-"></div>
|
||||||
|
<b>host</b>
|
||||||
|
<a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>success</td>
|
||||||
|
<td>
|
||||||
|
<div>URL for accessing the API server.</div>
|
||||||
|
<br/>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="elbow-placeholder"> </td>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="return-"></div>
|
||||||
|
<b>username</b>
|
||||||
|
<a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>success</td>
|
||||||
|
<td>
|
||||||
|
<div>Username for authenticating with the API server.</div>
|
||||||
|
<br/>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="elbow-placeholder"> </td>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="return-"></div>
|
||||||
|
<b>validate_certs</b>
|
||||||
|
<a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">boolean</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>success</td>
|
||||||
|
<td>
|
||||||
|
<div>Whether or not to verify the API server's SSL certificates.</div>
|
||||||
|
<br/>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
</table>
|
||||||
|
<br/><br/>
|
||||||
|
|
||||||
|
|
||||||
|
Status
|
||||||
|
------
|
||||||
|
|
||||||
|
|
||||||
|
Authors
|
||||||
|
~~~~~~~
|
||||||
|
|
||||||
|
- KubeVirt Team (@kubevirt)
|
||||||
|
- Fabian von Feilitzsch (@fabianvf)
|
||||||
@@ -0,0 +1,356 @@
|
|||||||
|
.. _community.okd.openshift_inventory:
|
||||||
|
|
||||||
|
|
||||||
|
***********************
|
||||||
|
community.okd.openshift
|
||||||
|
***********************
|
||||||
|
|
||||||
|
**OpenShift inventory source**
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
.. contents::
|
||||||
|
:local:
|
||||||
|
:depth: 1
|
||||||
|
|
||||||
|
|
||||||
|
Synopsis
|
||||||
|
--------
|
||||||
|
- Fetch containers, services and routes for one or more clusters
|
||||||
|
- Groups by cluster name, namespace, namespace_services, namespace_pods, namespace_routes, and labels
|
||||||
|
- Uses openshift.(yml|yaml) YAML configuration file to set parameter values.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Requirements
|
||||||
|
------------
|
||||||
|
The below requirements are needed on the local Ansible controller node that executes this inventory.
|
||||||
|
|
||||||
|
- python >= 3.6
|
||||||
|
- kubernetes >= 12.0.0
|
||||||
|
- PyYAML >= 3.11
|
||||||
|
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
|
||||||
|
.. raw:: html
|
||||||
|
|
||||||
|
<table border=0 cellpadding=0 class="documentation-table">
|
||||||
|
<tr>
|
||||||
|
<th colspan="2">Parameter</th>
|
||||||
|
<th>Choices/<font color="blue">Defaults</font></th>
|
||||||
|
<th>Configuration</th>
|
||||||
|
<th width="100%">Comments</th>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>connections</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">-</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Optional list of cluster connection settings. If no connections are provided, the default <em>~/.kube/config</em> and active context will be used, and objects will be returned for all namespaces the active user is authorized to access.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="elbow-placeholder"></td>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>api_key</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">-</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Token used to authenticate with the API. Can also be specified via K8S_AUTH_API_KEY environment variable.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="elbow-placeholder"></td>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>ca_cert</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">-</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Path to a CA certificate used to authenticate with the API. Can also be specified via K8S_AUTH_SSL_CA_CERT environment variable.</div>
|
||||||
|
<div style="font-size: small; color: darkgreen"><br/>aliases: ssl_ca_cert</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="elbow-placeholder"></td>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>client_cert</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">-</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Path to a certificate used to authenticate with the API. Can also be specified via K8S_AUTH_CERT_FILE environment variable.</div>
|
||||||
|
<div style="font-size: small; color: darkgreen"><br/>aliases: cert_file</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="elbow-placeholder"></td>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>client_key</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">-</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Path to a key file used to authenticate with the API. Can also be specified via K8S_AUTH_KEY_FILE environment variable.</div>
|
||||||
|
<div style="font-size: small; color: darkgreen"><br/>aliases: key_file</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="elbow-placeholder"></td>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>context</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">-</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>The name of a context found in the config file. Can also be specified via K8S_AUTH_CONTEXT environment variable.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="elbow-placeholder"></td>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>host</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">-</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Provide a URL for accessing the API. Can also be specified via K8S_AUTH_HOST environment variable.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="elbow-placeholder"></td>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>kubeconfig</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">-</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Path to an existing Kubernetes config file. If not provided, and no other connection options are provided, the Kubernetes client will attempt to load the default configuration file from <em>~/.kube/config</em>. Can also be specified via K8S_AUTH_KUBECONFIG environment variable.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="elbow-placeholder"></td>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>name</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">-</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Optional name to assign to the cluster. If not provided, a name is constructed from the server and port.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="elbow-placeholder"></td>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>namespaces</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">-</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>List of namespaces. If not specified, will fetch all containers for all namespaces user is authorized to access.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="elbow-placeholder"></td>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>password</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">-</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Provide a password for authenticating with the API. Can also be specified via K8S_AUTH_PASSWORD environment variable.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="elbow-placeholder"></td>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>username</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">-</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Provide a username for authenticating with the API. Can also be specified via K8S_AUTH_USERNAME environment variable.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="elbow-placeholder"></td>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>validate_certs</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">boolean</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<ul style="margin: 0; padding: 0"><b>Choices:</b>
|
||||||
|
<li>no</li>
|
||||||
|
<li>yes</li>
|
||||||
|
</ul>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Whether or not to verify the API server's SSL certificates. Can also be specified via K8S_AUTH_VERIFY_SSL environment variable.</div>
|
||||||
|
<div style="font-size: small; color: darkgreen"><br/>aliases: verify_ssl</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>plugin</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">-</span>
|
||||||
|
/ <span style="color: red">required</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<ul style="margin: 0; padding: 0"><b>Choices:</b>
|
||||||
|
<li>openshift</li>
|
||||||
|
<li>community.okd.openshift</li>
|
||||||
|
</ul>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>token that ensures this is a source file for the 'openshift' plugin.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
<br/>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Examples
|
||||||
|
--------
|
||||||
|
|
||||||
|
.. code-block:: yaml
|
||||||
|
|
||||||
|
# File must be named openshift.yaml or openshift.yml
|
||||||
|
|
||||||
|
# Authenticate with token, and return all pods and services for all namespaces
|
||||||
|
plugin: community.okd.openshift
|
||||||
|
connections:
|
||||||
|
- host: https://192.168.64.4:8443
|
||||||
|
api_key: xxxxxxxxxxxxxxxx
|
||||||
|
verify_ssl: false
|
||||||
|
|
||||||
|
# Use default config (~/.kube/config) file and active context, and return objects for a specific namespace
|
||||||
|
plugin: community.okd.openshift
|
||||||
|
connections:
|
||||||
|
- namespaces:
|
||||||
|
- testing
|
||||||
|
|
||||||
|
# Use a custom config file, and a specific context.
|
||||||
|
plugin: community.okd.openshift
|
||||||
|
connections:
|
||||||
|
- kubeconfig: /path/to/config
|
||||||
|
context: 'awx/192-168-64-4:8443/developer'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Status
|
||||||
|
------
|
||||||
|
|
||||||
|
|
||||||
|
Authors
|
||||||
|
~~~~~~~
|
||||||
|
|
||||||
|
- Chris Houseknecht <@chouseknecht>
|
||||||
|
|
||||||
|
|
||||||
|
.. hint::
|
||||||
|
Configuration entries for each entry type have a low to high priority order. For example, a variable that is lower in the list will override a variable that is higher up.
|
||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
+4
-4
@@ -5,16 +5,16 @@ authors:
|
|||||||
- willthames (https://github.com/willthames)
|
- willthames (https://github.com/willthames)
|
||||||
- Akasurde (https://github.com/akasurde)
|
- Akasurde (https://github.com/akasurde)
|
||||||
dependencies:
|
dependencies:
|
||||||
kubernetes.core: '>=1.2.0,<1.3.0'
|
kubernetes.core: '>=2.1.0,<2.3.0'
|
||||||
description: OKD Collection for Ansible.
|
description: OKD Collection for Ansible.
|
||||||
documentation: ''
|
documentation: ''
|
||||||
homepage: ''
|
homepage: ''
|
||||||
issues: https://github.com/ansible-collections/community.okd/issues
|
issues: https://github.com/openshift/community.okd/issues
|
||||||
license_file: LICENSE
|
license_file: LICENSE
|
||||||
name: okd
|
name: okd
|
||||||
namespace: community
|
namespace: community
|
||||||
readme: README.md
|
readme: README.md
|
||||||
repository: https://github.com/ansible-collections/community.okd
|
repository: https://github.com/openshift/community.okd
|
||||||
tags:
|
tags:
|
||||||
- kubernetes
|
- kubernetes
|
||||||
- k8s
|
- k8s
|
||||||
@@ -24,4 +24,4 @@ tags:
|
|||||||
- okd
|
- okd
|
||||||
- cluster
|
- cluster
|
||||||
# Also needs to be updated in the Makefile
|
# Also needs to be updated in the Makefile
|
||||||
version: 1.1.1
|
version: 2.1.0
|
||||||
|
|||||||
+4
-1
@@ -1,6 +1,9 @@
|
|||||||
---
|
---
|
||||||
requires_ansible: '>=2.9'
|
requires_ansible: '>=2.9.17'
|
||||||
plugin_routing:
|
plugin_routing:
|
||||||
modules:
|
modules:
|
||||||
k8s_auth:
|
k8s_auth:
|
||||||
redirect: community.okd.openshift_auth
|
redirect: community.okd.openshift_auth
|
||||||
|
action:
|
||||||
|
k8s:
|
||||||
|
redirect: kubernetes.core.k8s_info
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
---
|
||||||
|
kind: Template
|
||||||
|
apiVersion: template.openshift.io/v1
|
||||||
|
metadata:
|
||||||
|
name: pod-template
|
||||||
|
objects:
|
||||||
|
- apiVersion: v1
|
||||||
|
kind: Pod
|
||||||
|
metadata:
|
||||||
|
name: "Pod-${{ NAME }}"
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- args:
|
||||||
|
- /bin/sh
|
||||||
|
- -c
|
||||||
|
- while true; do echo $(date); sleep 15; done
|
||||||
|
image: python:3.7-alpine
|
||||||
|
imagePullPolicy: Always
|
||||||
|
name: python
|
||||||
|
parameters:
|
||||||
|
- name: NAME
|
||||||
|
description: trailing name of the pod
|
||||||
|
required: true
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
---
|
---
|
||||||
dependency:
|
dependency:
|
||||||
name: galaxy
|
name: galaxy
|
||||||
|
options:
|
||||||
|
requirements-file: requirements.yml
|
||||||
driver:
|
driver:
|
||||||
name: delegated
|
name: delegated
|
||||||
platforms:
|
platforms:
|
||||||
@@ -38,6 +40,7 @@ verifier:
|
|||||||
scenario:
|
scenario:
|
||||||
name: default
|
name: default
|
||||||
test_sequence:
|
test_sequence:
|
||||||
|
- dependency
|
||||||
- lint
|
- lint
|
||||||
- syntax
|
- syntax
|
||||||
- prepare
|
- prepare
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
- pip:
|
- pip:
|
||||||
name:
|
name:
|
||||||
- openshift>=0.9.2
|
- kubernetes>=12.0.0
|
||||||
- coverage
|
- coverage
|
||||||
virtualenv: "{{ virtualenv }}"
|
virtualenv: "{{ virtualenv }}"
|
||||||
virtualenv_command: "{{ virtualenv_command }}"
|
virtualenv_command: "{{ virtualenv_command }}"
|
||||||
|
|||||||
@@ -1,8 +1,13 @@
|
|||||||
---
|
---
|
||||||
- vars:
|
- block:
|
||||||
# TODO(fabianvf) Get this parameter working locally as well
|
- name: Retrieve cluster info
|
||||||
openshift_host: 'https://kubernetes.default.svc'
|
kubernetes.core.k8s_cluster_info:
|
||||||
block:
|
register: k8s_cluster
|
||||||
|
|
||||||
|
- name: set openshift host value
|
||||||
|
set_fact:
|
||||||
|
openshift_host: "{{ k8s_cluster.connection.host }}"
|
||||||
|
|
||||||
- name: Log in (obtain access token)
|
- name: Log in (obtain access token)
|
||||||
community.okd.openshift_auth:
|
community.okd.openshift_auth:
|
||||||
username: test
|
username: test
|
||||||
|
|||||||
@@ -162,3 +162,22 @@
|
|||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
that: result is not changed
|
that: result is not changed
|
||||||
|
|
||||||
|
# Processing template without message
|
||||||
|
- name: create template with file {{ files_dir }}/pod-template.yaml
|
||||||
|
kubernetes.core.k8s:
|
||||||
|
namespace: process-test
|
||||||
|
src: "{{ files_dir }}/pod-template.yaml"
|
||||||
|
state: present
|
||||||
|
|
||||||
|
- name: Process pod template
|
||||||
|
community.okd.openshift_process:
|
||||||
|
name: pod-template
|
||||||
|
namespace: process-test
|
||||||
|
state: rendered
|
||||||
|
parameters:
|
||||||
|
NAME: ansible
|
||||||
|
register: rendered_template
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that: rendered_template.message == ""
|
||||||
|
|||||||
@@ -51,7 +51,7 @@
|
|||||||
url: 'http://{{ route.result.spec.host }}'
|
url: 'http://{{ route.result.spec.host }}'
|
||||||
return_content: yes
|
return_content: yes
|
||||||
until: result is successful
|
until: result is successful
|
||||||
retries: 10
|
retries: 20
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
- name: Assert the page content is as expected
|
- name: Assert the page content is as expected
|
||||||
@@ -87,6 +87,8 @@
|
|||||||
uri:
|
uri:
|
||||||
url: 'http://{{ route.result.spec.host }}'
|
url: 'http://{{ route.result.spec.host }}'
|
||||||
return_content: yes
|
return_content: yes
|
||||||
|
until: result is successful
|
||||||
|
retries: 20
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
- name: Assert the page content is as expected
|
- name: Assert the page content is as expected
|
||||||
@@ -118,7 +120,7 @@
|
|||||||
url: 'http://{{ route.result.spec.host }}'
|
url: 'http://{{ route.result.spec.host }}'
|
||||||
return_content: yes
|
return_content: yes
|
||||||
until: result is successful
|
until: result is successful
|
||||||
retries: 10
|
retries: 20
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
- name: Assert the page content is as expected
|
- name: Assert the page content is as expected
|
||||||
@@ -178,7 +180,7 @@
|
|||||||
validate_certs: no
|
validate_certs: no
|
||||||
return_content: yes
|
return_content: yes
|
||||||
until: result is successful
|
until: result is successful
|
||||||
retries: 10
|
retries: 20
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
- name: Assert the page content is as expected
|
- name: Assert the page content is as expected
|
||||||
@@ -206,7 +208,7 @@
|
|||||||
validate_certs: no
|
validate_certs: no
|
||||||
return_content: yes
|
return_content: yes
|
||||||
until: result is successful
|
until: result is successful
|
||||||
retries: 10
|
retries: 20
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
- name: Assert the page content is as expected
|
- name: Assert the page content is as expected
|
||||||
@@ -221,7 +223,7 @@
|
|||||||
url: 'http://{{ route.result.spec.host }}'
|
url: 'http://{{ route.result.spec.host }}'
|
||||||
status_code: 503
|
status_code: 503
|
||||||
until: result is successful
|
until: result is successful
|
||||||
retries: 10
|
retries: 20
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
- debug: var=result
|
- debug: var=result
|
||||||
@@ -238,3 +240,36 @@
|
|||||||
namespace: default
|
namespace: default
|
||||||
state: absent
|
state: absent
|
||||||
wait: yes
|
wait: yes
|
||||||
|
|
||||||
|
# Route with labels and annotations
|
||||||
|
- name: Create route with labels and annotations
|
||||||
|
community.okd.openshift_route:
|
||||||
|
service: hello-kubernetes
|
||||||
|
namespace: default
|
||||||
|
name: route-label-annotation
|
||||||
|
labels:
|
||||||
|
ansible: test
|
||||||
|
annotations:
|
||||||
|
haproxy.router.openshift.io/balance: roundrobin
|
||||||
|
|
||||||
|
- name: Get route information
|
||||||
|
kubernetes.core.k8s_info:
|
||||||
|
api_version: route.openshift.io/v1
|
||||||
|
kind: Route
|
||||||
|
name: route-label-annotation
|
||||||
|
namespace: default
|
||||||
|
register: route
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- route.resources[0].metadata.annotations is defined
|
||||||
|
- '"haproxy.router.openshift.io/balance" in route.resources[0].metadata.annotations'
|
||||||
|
- route.resources[0].metadata.labels is defined
|
||||||
|
- '"ansible" in route.resources[0].metadata.labels'
|
||||||
|
|
||||||
|
- name: Delete route
|
||||||
|
community.okd.openshift_route:
|
||||||
|
name: route-label-annotation
|
||||||
|
namespace: default
|
||||||
|
state: absent
|
||||||
|
wait: yes
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ DOCUMENTATION = '''
|
|||||||
plugin:
|
plugin:
|
||||||
description: token that ensures this is a source file for the 'openshift' plugin.
|
description: token that ensures this is a source file for the 'openshift' plugin.
|
||||||
required: True
|
required: True
|
||||||
choices: ['openshift']
|
choices: ['openshift', 'community.okd.openshift']
|
||||||
connections:
|
connections:
|
||||||
description:
|
description:
|
||||||
- Optional list of cluster connection settings. If no connections are provided, the default
|
- Optional list of cluster connection settings. If no connections are provided, the default
|
||||||
@@ -36,8 +36,8 @@ DOCUMENTATION = '''
|
|||||||
kubeconfig:
|
kubeconfig:
|
||||||
description:
|
description:
|
||||||
- Path to an existing Kubernetes config file. If not provided, and no other connection
|
- Path to an existing Kubernetes config file. If not provided, and no other connection
|
||||||
options are provided, the OpenShift client will attempt to load the default
|
options are provided, the Kubernetes client will attempt to load the default
|
||||||
configuration file from I(~/.kube/config.json). Can also be specified via K8S_AUTH_KUBECONFIG
|
configuration file from I(~/.kube/config). Can also be specified via K8S_AUTH_KUBECONFIG
|
||||||
environment variable.
|
environment variable.
|
||||||
context:
|
context:
|
||||||
description:
|
description:
|
||||||
@@ -85,8 +85,8 @@ DOCUMENTATION = '''
|
|||||||
to access.
|
to access.
|
||||||
|
|
||||||
requirements:
|
requirements:
|
||||||
- "python >= 2.7"
|
- "python >= 3.6"
|
||||||
- "openshift >= 0.6"
|
- "kubernetes >= 12.0.0"
|
||||||
- "PyYAML >= 3.11"
|
- "PyYAML >= 3.11"
|
||||||
'''
|
'''
|
||||||
|
|
||||||
@@ -114,9 +114,10 @@ connections:
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
from ansible_collections.kubernetes.core.plugins.inventory.k8s import K8sInventoryException, InventoryModule as K8sInventoryModule, format_dynamic_api_exc
|
from ansible_collections.kubernetes.core.plugins.inventory.k8s import K8sInventoryException, InventoryModule as K8sInventoryModule, format_dynamic_api_exc
|
||||||
|
from ansible_collections.kubernetes.core.plugins.module_utils.common import get_api_client
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from openshift.dynamic.exceptions import DynamicApiError
|
from kubernetes.dynamic.exceptions import DynamicApiError
|
||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -135,7 +136,7 @@ class InventoryModule(K8sInventoryModule):
|
|||||||
raise K8sInventoryException("Expecting connections to be a list.")
|
raise K8sInventoryException("Expecting connections to be a list.")
|
||||||
|
|
||||||
for connection in connections:
|
for connection in connections:
|
||||||
client = self.get_api_client(**connection)
|
client = get_api_client(**connection)
|
||||||
name = connection.get('name', self.get_default_host_name(client.configuration.host))
|
name = connection.get('name', self.get_default_host_name(client.configuration.host))
|
||||||
if connection.get('namespaces'):
|
if connection.get('namespaces'):
|
||||||
namespaces = connection['namespaces']
|
namespaces = connection['namespaces']
|
||||||
@@ -144,7 +145,7 @@ class InventoryModule(K8sInventoryModule):
|
|||||||
for namespace in namespaces:
|
for namespace in namespaces:
|
||||||
self.get_routes_for_namespace(client, name, namespace)
|
self.get_routes_for_namespace(client, name, namespace)
|
||||||
else:
|
else:
|
||||||
client = self.get_api_client()
|
client = get_api_client()
|
||||||
name = self.get_default_host_name(client.configuration.host)
|
name = self.get_default_host_name(client.configuration.host)
|
||||||
namespaces = self.get_available_namespaces(client)
|
namespaces = self.get_available_namespaces(client)
|
||||||
for namespace in namespaces:
|
for namespace in namespaces:
|
||||||
|
|||||||
@@ -0,0 +1,186 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
from __future__ import (absolute_import, division, print_function)
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
import re
|
||||||
|
import operator
|
||||||
|
from functools import reduce
|
||||||
|
import traceback
|
||||||
|
from ansible_collections.kubernetes.core.plugins.module_utils.common import (
|
||||||
|
K8sAnsibleMixin,
|
||||||
|
get_api_client,
|
||||||
|
)
|
||||||
|
from ansible.module_utils._text import to_native
|
||||||
|
|
||||||
|
|
||||||
|
try:
|
||||||
|
from kubernetes.dynamic.exceptions import DynamicApiError, NotFoundError, ForbiddenError
|
||||||
|
HAS_KUBERNETES_COLLECTION = True
|
||||||
|
except ImportError as e:
|
||||||
|
HAS_KUBERNETES_COLLECTION = False
|
||||||
|
k8s_collection_import_exception = e
|
||||||
|
K8S_COLLECTION_ERROR = traceback.format_exc()
|
||||||
|
|
||||||
|
|
||||||
|
TRIGGER_ANNOTATION = 'image.openshift.io/triggers'
|
||||||
|
TRIGGER_CONTAINER = re.compile(r"(?P<path>.*)\[((?P<index>[0-9]+)|\?\(@\.name==[\"'\\]*(?P<name>[a-z0-9]([-a-z0-9]*[a-z0-9])?))")
|
||||||
|
|
||||||
|
|
||||||
|
class OKDRawModule(K8sAnsibleMixin):
|
||||||
|
|
||||||
|
def __init__(self, module, k8s_kind=None, *args, **kwargs):
|
||||||
|
self.module = module
|
||||||
|
self.client = get_api_client(module=module)
|
||||||
|
self.check_mode = self.module.check_mode
|
||||||
|
self.params = self.module.params
|
||||||
|
self.fail_json = self.module.fail_json
|
||||||
|
self.fail = self.module.fail_json
|
||||||
|
self.exit_json = self.module.exit_json
|
||||||
|
|
||||||
|
super(OKDRawModule, self).__init__(module, *args, **kwargs)
|
||||||
|
|
||||||
|
self.warnings = []
|
||||||
|
|
||||||
|
self.kind = k8s_kind or self.params.get('kind')
|
||||||
|
self.api_version = self.params.get('api_version')
|
||||||
|
self.name = self.params.get('name')
|
||||||
|
self.namespace = self.params.get('namespace')
|
||||||
|
|
||||||
|
self.check_library_version()
|
||||||
|
self.set_resource_definitions(module)
|
||||||
|
|
||||||
|
def perform_action(self, resource, definition):
|
||||||
|
state = self.params.get('state', None)
|
||||||
|
name = definition['metadata'].get('name')
|
||||||
|
namespace = definition['metadata'].get('namespace')
|
||||||
|
|
||||||
|
if state != 'absent':
|
||||||
|
|
||||||
|
if resource.kind in ['Project', 'ProjectRequest']:
|
||||||
|
try:
|
||||||
|
resource.get(name, namespace)
|
||||||
|
except (NotFoundError, ForbiddenError):
|
||||||
|
return self.create_project_request(definition)
|
||||||
|
except DynamicApiError as exc:
|
||||||
|
self.fail_json(msg='Failed to retrieve requested object: {0}'.format(exc.body),
|
||||||
|
error=exc.status, status=exc.status, reason=exc.reason)
|
||||||
|
|
||||||
|
try:
|
||||||
|
existing = resource.get(name=name, namespace=namespace).to_dict()
|
||||||
|
except Exception:
|
||||||
|
existing = None
|
||||||
|
|
||||||
|
if existing:
|
||||||
|
if resource.kind == 'DeploymentConfig':
|
||||||
|
if definition.get('spec', {}).get('triggers'):
|
||||||
|
definition = self.resolve_imagestream_triggers(existing, definition)
|
||||||
|
elif existing['metadata'].get('annotations', {}).get(TRIGGER_ANNOTATION):
|
||||||
|
definition = self.resolve_imagestream_trigger_annotation(existing, definition)
|
||||||
|
|
||||||
|
return super(OKDRawModule, self).perform_action(resource, definition)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_index(desired, objects, keys):
|
||||||
|
""" Iterates over keys, returns the first object from objects where the value of the key
|
||||||
|
matches the value in desired
|
||||||
|
"""
|
||||||
|
# pylint: disable=use-a-generator
|
||||||
|
# Use a generator instead 'all(desired.get(key, True) == item.get(key, False) for key in keys)'
|
||||||
|
for i, item in enumerate(objects):
|
||||||
|
if item and all([desired.get(key, True) == item.get(key, False) for key in keys]):
|
||||||
|
return i
|
||||||
|
|
||||||
|
def resolve_imagestream_trigger_annotation(self, existing, definition):
|
||||||
|
import yaml
|
||||||
|
|
||||||
|
def get_from_fields(d, fields):
|
||||||
|
try:
|
||||||
|
return reduce(operator.getitem, fields, d)
|
||||||
|
except Exception:
|
||||||
|
return None
|
||||||
|
|
||||||
|
def set_from_fields(d, fields, value):
|
||||||
|
get_from_fields(d, fields[:-1])[fields[-1]] = value
|
||||||
|
|
||||||
|
if TRIGGER_ANNOTATION in definition['metadata'].get('annotations', {}).keys():
|
||||||
|
triggers = yaml.safe_load(definition['metadata']['annotations'][TRIGGER_ANNOTATION] or '[]')
|
||||||
|
else:
|
||||||
|
triggers = yaml.safe_load(existing['metadata'].get('annotations', '{}').get(TRIGGER_ANNOTATION, '[]'))
|
||||||
|
|
||||||
|
if not isinstance(triggers, list):
|
||||||
|
return definition
|
||||||
|
|
||||||
|
for trigger in triggers:
|
||||||
|
if trigger.get('fieldPath'):
|
||||||
|
parsed = self.parse_trigger_fieldpath(trigger['fieldPath'])
|
||||||
|
path = parsed.get('path', '').split('.')
|
||||||
|
if path:
|
||||||
|
existing_containers = get_from_fields(existing, path)
|
||||||
|
new_containers = get_from_fields(definition, path)
|
||||||
|
if parsed.get('name'):
|
||||||
|
existing_index = self.get_index({'name': parsed['name']}, existing_containers, ['name'])
|
||||||
|
new_index = self.get_index({'name': parsed['name']}, new_containers, ['name'])
|
||||||
|
elif parsed.get('index') is not None:
|
||||||
|
existing_index = new_index = int(parsed['index'])
|
||||||
|
else:
|
||||||
|
existing_index = new_index = None
|
||||||
|
if existing_index is not None and new_index is not None:
|
||||||
|
if existing_index < len(existing_containers) and new_index < len(new_containers):
|
||||||
|
set_from_fields(definition, path + [new_index, 'image'], get_from_fields(existing, path + [existing_index, 'image']))
|
||||||
|
return definition
|
||||||
|
|
||||||
|
def resolve_imagestream_triggers(self, existing, definition):
|
||||||
|
|
||||||
|
existing_triggers = existing.get('spec', {}).get('triggers')
|
||||||
|
new_triggers = definition['spec']['triggers']
|
||||||
|
existing_containers = existing.get('spec', {}).get('template', {}).get('spec', {}).get('containers', [])
|
||||||
|
new_containers = definition.get('spec', {}).get('template', {}).get('spec', {}).get('containers', [])
|
||||||
|
for i, trigger in enumerate(new_triggers):
|
||||||
|
if trigger.get('type') == 'ImageChange' and trigger.get('imageChangeParams'):
|
||||||
|
names = trigger['imageChangeParams'].get('containerNames', [])
|
||||||
|
for name in names:
|
||||||
|
old_container_index = self.get_index({'name': name}, existing_containers, ['name'])
|
||||||
|
new_container_index = self.get_index({'name': name}, new_containers, ['name'])
|
||||||
|
if old_container_index is not None and new_container_index is not None:
|
||||||
|
image = existing['spec']['template']['spec']['containers'][old_container_index]['image']
|
||||||
|
definition['spec']['template']['spec']['containers'][new_container_index]['image'] = image
|
||||||
|
|
||||||
|
existing_index = self.get_index(trigger['imageChangeParams'],
|
||||||
|
[x.get('imageChangeParams') for x in existing_triggers],
|
||||||
|
['containerNames'])
|
||||||
|
if existing_index is not None:
|
||||||
|
existing_image = existing_triggers[existing_index].get('imageChangeParams', {}).get('lastTriggeredImage')
|
||||||
|
if existing_image:
|
||||||
|
definition['spec']['triggers'][i]['imageChangeParams']['lastTriggeredImage'] = existing_image
|
||||||
|
existing_from = existing_triggers[existing_index].get('imageChangeParams', {}).get('from', {})
|
||||||
|
new_from = trigger['imageChangeParams'].get('from', {})
|
||||||
|
existing_namespace = existing_from.get('namespace')
|
||||||
|
existing_name = existing_from.get('name', False)
|
||||||
|
new_name = new_from.get('name', True)
|
||||||
|
add_namespace = existing_namespace and 'namespace' not in new_from.keys() and existing_name == new_name
|
||||||
|
if add_namespace:
|
||||||
|
definition['spec']['triggers'][i]['imageChangeParams']['from']['namespace'] = existing_from['namespace']
|
||||||
|
|
||||||
|
return definition
|
||||||
|
|
||||||
|
def parse_trigger_fieldpath(self, expression):
|
||||||
|
parsed = TRIGGER_CONTAINER.search(expression).groupdict()
|
||||||
|
if parsed.get('index'):
|
||||||
|
parsed['index'] = int(parsed['index'])
|
||||||
|
return parsed
|
||||||
|
|
||||||
|
def create_project_request(self, definition):
|
||||||
|
definition['kind'] = 'ProjectRequest'
|
||||||
|
result = {'changed': False, 'result': {}}
|
||||||
|
resource = self.find_resource('ProjectRequest', definition['apiVersion'], fail=True)
|
||||||
|
if not self.check_mode:
|
||||||
|
try:
|
||||||
|
k8s_obj = resource.create(definition)
|
||||||
|
result['result'] = k8s_obj.to_dict()
|
||||||
|
except DynamicApiError as exc:
|
||||||
|
self.fail_json(msg="Failed to create object: {0}".format(exc.body),
|
||||||
|
error=exc.status, status=exc.status, reason=exc.reason)
|
||||||
|
result['changed'] = True
|
||||||
|
result['method'] = 'create'
|
||||||
|
return result
|
||||||
@@ -0,0 +1,199 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
from __future__ import (absolute_import, division, print_function)
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
import os
|
||||||
|
import traceback
|
||||||
|
|
||||||
|
from ansible_collections.kubernetes.core.plugins.module_utils.common import (
|
||||||
|
K8sAnsibleMixin,
|
||||||
|
get_api_client,
|
||||||
|
)
|
||||||
|
from ansible.module_utils._text import to_native
|
||||||
|
|
||||||
|
|
||||||
|
try:
|
||||||
|
from kubernetes.dynamic.exceptions import DynamicApiError, NotFoundError
|
||||||
|
HAS_KUBERNETES_COLLECTION = True
|
||||||
|
except ImportError as e:
|
||||||
|
HAS_KUBERNETES_COLLECTION = False
|
||||||
|
k8s_collection_import_exception = e
|
||||||
|
K8S_COLLECTION_ERROR = traceback.format_exc()
|
||||||
|
|
||||||
|
try:
|
||||||
|
from kubernetes.dynamic.exceptions import DynamicApiError, NotFoundError
|
||||||
|
except ImportError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class OpenShiftProcess(K8sAnsibleMixin):
|
||||||
|
def __init__(self, module):
|
||||||
|
self.module = module
|
||||||
|
self.fail_json = self.module.fail_json
|
||||||
|
self.exit_json = self.module.exit_json
|
||||||
|
|
||||||
|
if not HAS_KUBERNETES_COLLECTION:
|
||||||
|
self.module.fail_json(
|
||||||
|
msg="The kubernetes.core collection must be installed",
|
||||||
|
exception=K8S_COLLECTION_ERROR,
|
||||||
|
error=to_native(k8s_collection_import_exception),
|
||||||
|
)
|
||||||
|
|
||||||
|
super(OpenShiftProcess, self).__init__(self.module)
|
||||||
|
|
||||||
|
self.params = self.module.params
|
||||||
|
self.check_mode = self.module.check_mode
|
||||||
|
self.client = get_api_client(self.module)
|
||||||
|
|
||||||
|
def execute_module(self):
|
||||||
|
v1_templates = self.find_resource(
|
||||||
|
"templates", "template.openshift.io/v1", fail=True
|
||||||
|
)
|
||||||
|
v1_processed_templates = self.find_resource(
|
||||||
|
"processedtemplates", "template.openshift.io/v1", fail=True
|
||||||
|
)
|
||||||
|
|
||||||
|
name = self.params.get("name")
|
||||||
|
namespace = self.params.get("namespace")
|
||||||
|
namespace_target = self.params.get("namespace_target")
|
||||||
|
definition = self.params.get("resource_definition")
|
||||||
|
src = self.params.get("src")
|
||||||
|
|
||||||
|
state = self.params.get("state")
|
||||||
|
|
||||||
|
parameters = self.params.get("parameters") or {}
|
||||||
|
parameter_file = self.params.get("parameter_file")
|
||||||
|
|
||||||
|
if (name and definition) or (name and src) or (src and definition):
|
||||||
|
self.fail_json("Only one of src, name, or definition may be provided")
|
||||||
|
|
||||||
|
if name and not namespace:
|
||||||
|
self.fail_json("namespace is required when name is set")
|
||||||
|
|
||||||
|
template = None
|
||||||
|
|
||||||
|
if src or definition:
|
||||||
|
self.set_resource_definitions(self.module)
|
||||||
|
if len(self.resource_definitions) < 1:
|
||||||
|
self.fail_json(
|
||||||
|
"Unable to load a Template resource from src or resource_definition"
|
||||||
|
)
|
||||||
|
elif len(self.resource_definitions) > 1:
|
||||||
|
self.fail_json(
|
||||||
|
"Multiple Template resources found in src or resource_definition, only one Template may be processed at a time"
|
||||||
|
)
|
||||||
|
template = self.resource_definitions[0]
|
||||||
|
template_namespace = template.get("metadata", {}).get("namespace")
|
||||||
|
namespace = template_namespace or namespace or namespace_target or "default"
|
||||||
|
elif name and namespace:
|
||||||
|
try:
|
||||||
|
template = v1_templates.get(name=name, namespace=namespace).to_dict()
|
||||||
|
except DynamicApiError as exc:
|
||||||
|
self.fail_json(
|
||||||
|
msg="Failed to retrieve Template with name '{0}' in namespace '{1}': {2}".format(
|
||||||
|
name, namespace, exc.body
|
||||||
|
),
|
||||||
|
error=exc.status,
|
||||||
|
status=exc.status,
|
||||||
|
reason=exc.reason,
|
||||||
|
)
|
||||||
|
except Exception as exc:
|
||||||
|
self.module.fail_json(
|
||||||
|
msg="Failed to retrieve Template with name '{0}' in namespace '{1}': {2}".format(
|
||||||
|
name, namespace, to_native(exc)
|
||||||
|
),
|
||||||
|
error="",
|
||||||
|
status="",
|
||||||
|
reason="",
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
self.fail_json(
|
||||||
|
"One of resource_definition, src, or name and namespace must be provided"
|
||||||
|
)
|
||||||
|
|
||||||
|
if parameter_file:
|
||||||
|
parameters = self.parse_dotenv_and_merge(parameters, parameter_file)
|
||||||
|
|
||||||
|
for k, v in parameters.items():
|
||||||
|
template = self.update_template_param(template, k, v)
|
||||||
|
|
||||||
|
result = {"changed": False}
|
||||||
|
|
||||||
|
try:
|
||||||
|
response = v1_processed_templates.create(
|
||||||
|
body=template, namespace=namespace
|
||||||
|
).to_dict()
|
||||||
|
except DynamicApiError as exc:
|
||||||
|
self.fail_json(
|
||||||
|
msg="Server failed to render the Template: {0}".format(exc.body),
|
||||||
|
error=exc.status,
|
||||||
|
status=exc.status,
|
||||||
|
reason=exc.reason,
|
||||||
|
)
|
||||||
|
except Exception as exc:
|
||||||
|
self.module.fail_json(
|
||||||
|
msg="Server failed to render the Template: {0}".format(to_native(exc)),
|
||||||
|
error="",
|
||||||
|
status="",
|
||||||
|
reason="",
|
||||||
|
)
|
||||||
|
result["message"] = ""
|
||||||
|
if "message" in response:
|
||||||
|
result["message"] = response["message"]
|
||||||
|
result["resources"] = response["objects"]
|
||||||
|
|
||||||
|
if state != "rendered":
|
||||||
|
self.resource_definitions = response["objects"]
|
||||||
|
self.kind = self.api_version = self.name = None
|
||||||
|
self.namespace = self.params.get("namespace_target")
|
||||||
|
self.append_hash = False
|
||||||
|
self.apply = False
|
||||||
|
self.params["validate"] = None
|
||||||
|
self.params["merge_type"] = None
|
||||||
|
super(OpenShiftProcess, self).execute_module()
|
||||||
|
|
||||||
|
self.module.exit_json(**result)
|
||||||
|
|
||||||
|
def update_template_param(self, template, k, v):
|
||||||
|
for i, param in enumerate(template["parameters"]):
|
||||||
|
if param["name"] == k:
|
||||||
|
template["parameters"][i]["value"] = v
|
||||||
|
return template
|
||||||
|
return template
|
||||||
|
|
||||||
|
def parse_dotenv_and_merge(self, parameters, parameter_file):
|
||||||
|
import re
|
||||||
|
|
||||||
|
DOTENV_PARSER = re.compile(
|
||||||
|
r"(?x)^(\s*(\#.*|\s*|(export\s+)?(?P<key>[A-z_][A-z0-9_.]*)=(?P<value>.+?)?)\s*)[\r\n]*$"
|
||||||
|
)
|
||||||
|
path = os.path.normpath(parameter_file)
|
||||||
|
if not os.path.exists(path):
|
||||||
|
self.fail(msg="Error accessing {0}. Does the file exist?".format(path))
|
||||||
|
try:
|
||||||
|
with open(path, "r") as f:
|
||||||
|
multiline = ""
|
||||||
|
for line in f.readlines():
|
||||||
|
line = line.strip()
|
||||||
|
if line.endswith("\\"):
|
||||||
|
multiline += " ".join(line.rsplit("\\", 1))
|
||||||
|
continue
|
||||||
|
if multiline:
|
||||||
|
line = multiline + line
|
||||||
|
multiline = ""
|
||||||
|
match = DOTENV_PARSER.search(line)
|
||||||
|
if not match:
|
||||||
|
continue
|
||||||
|
match = match.groupdict()
|
||||||
|
if match.get("key"):
|
||||||
|
if match["key"] in parameters:
|
||||||
|
self.fail_json(
|
||||||
|
msg="Duplicate value for '{0}' detected in parameter file".format(
|
||||||
|
match["key"]
|
||||||
|
)
|
||||||
|
)
|
||||||
|
parameters[match["key"]] = match["value"]
|
||||||
|
except IOError as exc:
|
||||||
|
self.fail(msg="Error loading parameter file: {0}".format(exc))
|
||||||
|
return parameters
|
||||||
+108
-231
@@ -1,15 +1,16 @@
|
|||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
# (c) 2018, Chris Houseknecht <@chouseknecht>
|
# Copyright: (c) 2018, Chris Houseknecht <@chouseknecht>
|
||||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
|
||||||
|
|
||||||
from __future__ import absolute_import, division, print_function
|
from __future__ import absolute_import, division, print_function
|
||||||
|
|
||||||
__metaclass__ = type
|
__metaclass__ = type
|
||||||
|
|
||||||
# STARTREMOVE (downstream)
|
# STARTREMOVE (downstream)
|
||||||
DOCUMENTATION = '''
|
DOCUMENTATION = r'''
|
||||||
|
|
||||||
module: k8s
|
module: k8s
|
||||||
|
|
||||||
@@ -20,29 +21,38 @@ author:
|
|||||||
- "Fabian von Feilitzsch (@fabianvf)"
|
- "Fabian von Feilitzsch (@fabianvf)"
|
||||||
|
|
||||||
description:
|
description:
|
||||||
- Use the OpenShift Python client to perform CRUD operations on K8s objects.
|
- Use the Kubernetes Python client to perform CRUD operations on K8s objects.
|
||||||
- Pass the object definition from a source file or inline. See examples for reading
|
- Pass the object definition from a source file or inline. See examples for reading
|
||||||
files and using Jinja templates or vault-encrypted files.
|
files and using Jinja templates or vault-encrypted files.
|
||||||
- Access to the full range of K8s APIs.
|
- Access to the full range of K8s APIs.
|
||||||
- Use the M(k8s_info) module to obtain a list of items about an object of type C(kind)
|
- Use the M(kubernetes.core.k8s_info) module to obtain a list of items about an object of type C(kind).
|
||||||
- Authenticate using either a config file, certificates, password or token.
|
- Authenticate using either a config file, certificates, password or token.
|
||||||
- Supports check mode.
|
- Supports check mode.
|
||||||
- Optimized for OKD/OpenShift Kubernetes flavors
|
- Optimized for OKD/OpenShift Kubernetes flavors.
|
||||||
|
|
||||||
extends_documentation_fragment:
|
extends_documentation_fragment:
|
||||||
- kubernetes.core.k8s_state_options
|
|
||||||
- kubernetes.core.k8s_name_options
|
- kubernetes.core.k8s_name_options
|
||||||
- kubernetes.core.k8s_resource_options
|
- kubernetes.core.k8s_resource_options
|
||||||
- kubernetes.core.k8s_auth_options
|
- kubernetes.core.k8s_auth_options
|
||||||
|
- kubernetes.core.k8s_wait_options
|
||||||
notes:
|
- kubernetes.core.k8s_delete_options
|
||||||
- If your OpenShift Python library is not 0.9.0 or newer and you are trying to
|
|
||||||
remove an item from an associative array/dictionary, for example a label or
|
|
||||||
an annotation, you will need to explicitly set the value of the item to be
|
|
||||||
removed to `null`. Simply deleting the entry in the dictionary will not
|
|
||||||
remove it from openshift or kubernetes.
|
|
||||||
|
|
||||||
options:
|
options:
|
||||||
|
state:
|
||||||
|
description:
|
||||||
|
- Determines if an object should be created, patched, or deleted. When set to C(present), an object will be
|
||||||
|
created, if it does not already exist. If set to C(absent), an existing object will be deleted. If set to
|
||||||
|
C(present), an existing object will be patched, if its attributes differ from those specified using
|
||||||
|
I(resource_definition) or I(src).
|
||||||
|
- C(patched) state is an existing resource that has a given patch applied. If the resource doesn't exist, silently skip it (do not raise an error).
|
||||||
|
type: str
|
||||||
|
default: present
|
||||||
|
choices: [ absent, present, patched ]
|
||||||
|
force:
|
||||||
|
description:
|
||||||
|
- If set to C(yes), and I(state) is C(present), an existing object will be replaced.
|
||||||
|
type: bool
|
||||||
|
default: no
|
||||||
merge_type:
|
merge_type:
|
||||||
description:
|
description:
|
||||||
- Whether to override the default patch merge approach with a specific type. By default, the strategic
|
- Whether to override the default patch merge approach with a specific type. By default, the strategic
|
||||||
@@ -50,65 +60,17 @@ options:
|
|||||||
- For example, Custom Resource Definitions typically aren't updatable by the usual strategic merge. You may
|
- For example, Custom Resource Definitions typically aren't updatable by the usual strategic merge. You may
|
||||||
want to use C(merge) if you see "strategic merge patch format is not supported"
|
want to use C(merge) if you see "strategic merge patch format is not supported"
|
||||||
- See U(https://kubernetes.io/docs/tasks/run-application/update-api-object-kubectl-patch/#use-a-json-merge-patch-to-update-a-deployment)
|
- See U(https://kubernetes.io/docs/tasks/run-application/update-api-object-kubectl-patch/#use-a-json-merge-patch-to-update-a-deployment)
|
||||||
- Requires openshift >= 0.6.2
|
|
||||||
- If more than one merge_type is given, the merge_types will be tried in order
|
- If more than one merge_type is given, the merge_types will be tried in order
|
||||||
- If openshift >= 0.6.2, this defaults to C(['strategic-merge', 'merge']), which is ideal for using the same parameters
|
- Defaults to C(['strategic-merge', 'merge']), which is ideal for using the same parameters
|
||||||
on resource kinds that combine Custom Resources and built-in resources. For openshift < 0.6.2, the default
|
on resource kinds that combine Custom Resources and built-in resources.
|
||||||
is simply C(strategic-merge).
|
|
||||||
- mutually exclusive with C(apply)
|
- mutually exclusive with C(apply)
|
||||||
|
- I(merge_type=json) is deprecated and will be removed in version 3.0.0. Please use M(kubernetes.core.k8s_json_patch) instead.
|
||||||
choices:
|
choices:
|
||||||
- json
|
- json
|
||||||
- merge
|
- merge
|
||||||
- strategic-merge
|
- strategic-merge
|
||||||
type: list
|
type: list
|
||||||
elements: str
|
elements: str
|
||||||
wait:
|
|
||||||
description:
|
|
||||||
- Whether to wait for certain resource kinds to end up in the desired state. By default the module exits once Kubernetes has
|
|
||||||
received the request
|
|
||||||
- Implemented for C(state=present) for C(Deployment), C(DaemonSet) and C(Pod), and for C(state=absent) for all resource kinds.
|
|
||||||
- For resource kinds without an implementation, C(wait) returns immediately unless C(wait_condition) is set.
|
|
||||||
default: no
|
|
||||||
type: bool
|
|
||||||
wait_sleep:
|
|
||||||
description:
|
|
||||||
- Number of seconds to sleep between checks.
|
|
||||||
default: 5
|
|
||||||
type: int
|
|
||||||
wait_timeout:
|
|
||||||
description:
|
|
||||||
- How long in seconds to wait for the resource to end up in the desired state. Ignored if C(wait) is not set.
|
|
||||||
default: 120
|
|
||||||
type: int
|
|
||||||
wait_condition:
|
|
||||||
description:
|
|
||||||
- Specifies a custom condition on the status to wait for. Ignored if C(wait) is not set or is set to False.
|
|
||||||
suboptions:
|
|
||||||
type:
|
|
||||||
type: str
|
|
||||||
description:
|
|
||||||
- The type of condition to wait for. For example, the C(Pod) resource will set the C(Ready) condition (among others)
|
|
||||||
- Required if you are specifying a C(wait_condition). If left empty, the C(wait_condition) field will be ignored.
|
|
||||||
- The possible types for a condition are specific to each resource type in Kubernetes. See the API documentation of the status field
|
|
||||||
for a given resource to see possible choices.
|
|
||||||
status:
|
|
||||||
type: str
|
|
||||||
description:
|
|
||||||
- The value of the status field in your desired condition.
|
|
||||||
- For example, if a C(Deployment) is paused, the C(Progressing) C(type) will have the C(Unknown) status.
|
|
||||||
choices:
|
|
||||||
- True
|
|
||||||
- False
|
|
||||||
- Unknown
|
|
||||||
default: "True"
|
|
||||||
reason:
|
|
||||||
type: str
|
|
||||||
description:
|
|
||||||
- The value of the reason field in your desired condition
|
|
||||||
- For example, if a C(Deployment) is paused, The C(Progressing) C(type) will have the C(DeploymentPaused) reason.
|
|
||||||
- The possible reasons in a condition are specific to each resource type in Kubernetes.
|
|
||||||
See the API documentation of the status field for a given resource to see possible choices.
|
|
||||||
type: dict
|
|
||||||
validate:
|
validate:
|
||||||
description:
|
description:
|
||||||
- how (if at all) to validate the resource definition against the kubernetes schema.
|
- how (if at all) to validate the resource definition against the kubernetes schema.
|
||||||
@@ -143,14 +105,46 @@ options:
|
|||||||
- mutually exclusive with C(merge_type)
|
- mutually exclusive with C(merge_type)
|
||||||
type: bool
|
type: bool
|
||||||
default: false
|
default: false
|
||||||
|
template:
|
||||||
|
description:
|
||||||
|
- Provide a valid YAML template definition file for an object when creating or updating.
|
||||||
|
- Value can be provided as string or dictionary.
|
||||||
|
- Mutually exclusive with C(src) and C(resource_definition).
|
||||||
|
- Template files needs to be present on the Ansible Controller's file system.
|
||||||
|
- Additional parameters can be specified using dictionary.
|
||||||
|
- 'Valid additional parameters - '
|
||||||
|
- 'C(newline_sequence) (str): Specify the newline sequence to use for templating files.
|
||||||
|
valid choices are "\n", "\r", "\r\n". Default value "\n".'
|
||||||
|
- 'C(block_start_string) (str): The string marking the beginning of a block.
|
||||||
|
Default value "{%".'
|
||||||
|
- 'C(block_end_string) (str): The string marking the end of a block.
|
||||||
|
Default value "%}".'
|
||||||
|
- 'C(variable_start_string) (str): The string marking the beginning of a print statement.
|
||||||
|
Default value "{{".'
|
||||||
|
- 'C(variable_end_string) (str): The string marking the end of a print statement.
|
||||||
|
Default value "}}".'
|
||||||
|
- 'C(trim_blocks) (bool): Determine when newlines should be removed from blocks. When set to C(yes) the first newline
|
||||||
|
after a block is removed (block, not variable tag!). Default value is true.'
|
||||||
|
- 'C(lstrip_blocks) (bool): Determine when leading spaces and tabs should be stripped.
|
||||||
|
When set to C(yes) leading spaces and tabs are stripped from the start of a line to a block.
|
||||||
|
This functionality requires Jinja 2.7 or newer. Default value is false.'
|
||||||
|
type: raw
|
||||||
|
version_added: '2.0.0'
|
||||||
|
continue_on_error:
|
||||||
|
description:
|
||||||
|
- Whether to continue on creation/deletion errors when multiple resources are defined.
|
||||||
|
- This has no effect on the validation step which is controlled by the C(validate.fail_on_error) parameter.
|
||||||
|
type: bool
|
||||||
|
default: False
|
||||||
|
version_added: 2.0.0
|
||||||
|
|
||||||
requirements:
|
requirements:
|
||||||
- "python >= 2.7"
|
- "python >= 3.6"
|
||||||
- "openshift >= 0.6"
|
- "kubernetes >= 12.0.0"
|
||||||
- "PyYAML >= 3.11"
|
- "PyYAML >= 3.11"
|
||||||
'''
|
'''
|
||||||
|
|
||||||
EXAMPLES = '''
|
EXAMPLES = r'''
|
||||||
- name: Create a k8s namespace
|
- name: Create a k8s namespace
|
||||||
community.okd.k8s:
|
community.okd.k8s:
|
||||||
name: testing
|
name: testing
|
||||||
@@ -223,7 +217,7 @@ EXAMPLES = '''
|
|||||||
strict: yes
|
strict: yes
|
||||||
'''
|
'''
|
||||||
|
|
||||||
RETURN = '''
|
RETURN = r'''
|
||||||
result:
|
result:
|
||||||
description:
|
description:
|
||||||
- The created, patched, or otherwise present object. Will be empty in the case of a deletion.
|
- The created, patched, or otherwise present object. Will be empty in the case of a deletion.
|
||||||
@@ -259,182 +253,65 @@ result:
|
|||||||
returned: when C(wait) is true
|
returned: when C(wait) is true
|
||||||
type: int
|
type: int
|
||||||
sample: 48
|
sample: 48
|
||||||
|
error:
|
||||||
|
description: error while trying to create/delete the object.
|
||||||
|
returned: error
|
||||||
|
type: complex
|
||||||
'''
|
'''
|
||||||
# ENDREMOVE (downstream)
|
# ENDREMOVE (downstream)
|
||||||
|
|
||||||
import re
|
|
||||||
import operator
|
|
||||||
import traceback
|
|
||||||
from functools import reduce
|
|
||||||
|
|
||||||
from ansible.module_utils._text import to_native
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from ansible_collections.kubernetes.core.plugins.module_utils.raw import KubernetesRawModule
|
from ansible_collections.kubernetes.core.plugins.module_utils.ansiblemodule import AnsibleModule
|
||||||
HAS_KUBERNETES_COLLECTION = True
|
|
||||||
except ImportError as e:
|
|
||||||
HAS_KUBERNETES_COLLECTION = False
|
|
||||||
k8s_collection_import_exception = e
|
|
||||||
K8S_COLLECTION_ERROR = traceback.format_exc()
|
|
||||||
from ansible.module_utils.basic import AnsibleModule as KubernetesRawModule
|
|
||||||
|
|
||||||
try:
|
|
||||||
import yaml
|
|
||||||
from openshift.dynamic.exceptions import DynamicApiError, NotFoundError, ForbiddenError
|
|
||||||
except ImportError:
|
except ImportError:
|
||||||
# Exceptions handled in common
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
pass
|
|
||||||
|
|
||||||
TRIGGER_ANNOTATION = 'image.openshift.io/triggers'
|
from ansible_collections.kubernetes.core.plugins.module_utils.args_common import (
|
||||||
TRIGGER_CONTAINER = re.compile(r"(?P<path>.*)\[((?P<index>[0-9]+)|\?\(@\.name==[\"'\\]*(?P<name>[a-z0-9]([-a-z0-9]*[a-z0-9])?))")
|
NAME_ARG_SPEC, RESOURCE_ARG_SPEC, AUTH_ARG_SPEC, WAIT_ARG_SPEC, DELETE_OPTS_ARG_SPEC)
|
||||||
|
|
||||||
|
|
||||||
class OKDRawModule(KubernetesRawModule):
|
def validate_spec():
|
||||||
|
return dict(
|
||||||
|
fail_on_error=dict(type='bool'),
|
||||||
|
version=dict(),
|
||||||
|
strict=dict(type='bool', default=True)
|
||||||
|
)
|
||||||
|
|
||||||
def __init__(self):
|
|
||||||
if not HAS_KUBERNETES_COLLECTION:
|
|
||||||
self.fail_json(
|
|
||||||
msg="The kubernetes.core collection must be installed",
|
|
||||||
exception=K8S_COLLECTION_ERROR,
|
|
||||||
error=to_native(k8s_collection_import_exception)
|
|
||||||
)
|
|
||||||
super(OKDRawModule, self).__init__()
|
|
||||||
|
|
||||||
def perform_action(self, resource, definition):
|
def argspec():
|
||||||
state = self.params.get('state', None)
|
argument_spec = {}
|
||||||
name = definition['metadata'].get('name')
|
argument_spec.update(NAME_ARG_SPEC)
|
||||||
namespace = definition['metadata'].get('namespace')
|
argument_spec.update(RESOURCE_ARG_SPEC)
|
||||||
|
argument_spec.update(AUTH_ARG_SPEC)
|
||||||
if state != 'absent':
|
argument_spec.update(WAIT_ARG_SPEC)
|
||||||
|
argument_spec['merge_type'] = dict(type='list', elements='str', choices=['json', 'merge', 'strategic-merge'])
|
||||||
if resource.kind in ['Project', 'ProjectRequest']:
|
argument_spec['validate'] = dict(type='dict', default=None, options=validate_spec())
|
||||||
try:
|
argument_spec['append_hash'] = dict(type='bool', default=False)
|
||||||
resource.get(name, namespace)
|
argument_spec['apply'] = dict(type='bool', default=False)
|
||||||
except (NotFoundError, ForbiddenError):
|
argument_spec['template'] = dict(type='raw', default=None)
|
||||||
return self.create_project_request(definition)
|
argument_spec['delete_options'] = dict(type='dict', default=None, options=DELETE_OPTS_ARG_SPEC)
|
||||||
except DynamicApiError as exc:
|
argument_spec['continue_on_error'] = dict(type='bool', default=False)
|
||||||
self.fail_json(msg='Failed to retrieve requested object: {0}'.format(exc.body),
|
argument_spec['state'] = dict(default='present', choices=['present', 'absent', 'patched'])
|
||||||
error=exc.status, status=exc.status, reason=exc.reason)
|
argument_spec['force'] = dict(type='bool', default=False)
|
||||||
|
return argument_spec
|
||||||
try:
|
|
||||||
existing = resource.get(name=name, namespace=namespace).to_dict()
|
|
||||||
except Exception:
|
|
||||||
existing = None
|
|
||||||
|
|
||||||
if existing:
|
|
||||||
if resource.kind == 'DeploymentConfig':
|
|
||||||
if definition.get('spec', {}).get('triggers'):
|
|
||||||
definition = self.resolve_imagestream_triggers(existing, definition)
|
|
||||||
elif existing['metadata'].get('annotations', {}).get(TRIGGER_ANNOTATION):
|
|
||||||
definition = self.resolve_imagestream_trigger_annotation(existing, definition)
|
|
||||||
|
|
||||||
return super(OKDRawModule, self).perform_action(resource, definition)
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def get_index(desired, objects, keys):
|
|
||||||
""" Iterates over keys, returns the first object from objects where the value of the key
|
|
||||||
matches the value in desired
|
|
||||||
"""
|
|
||||||
for i, item in enumerate(objects):
|
|
||||||
if item and all([desired.get(key, True) == item.get(key, False) for key in keys]):
|
|
||||||
return i
|
|
||||||
|
|
||||||
def resolve_imagestream_trigger_annotation(self, existing, definition):
|
|
||||||
|
|
||||||
def get_from_fields(d, fields):
|
|
||||||
try:
|
|
||||||
return reduce(operator.getitem, fields, d)
|
|
||||||
except Exception:
|
|
||||||
return None
|
|
||||||
|
|
||||||
def set_from_fields(d, fields, value):
|
|
||||||
get_from_fields(d, fields[:-1])[fields[-1]] = value
|
|
||||||
|
|
||||||
if TRIGGER_ANNOTATION in definition['metadata'].get('annotations', {}).keys():
|
|
||||||
triggers = yaml.safe_load(definition['metadata']['annotations'][TRIGGER_ANNOTATION] or '[]')
|
|
||||||
else:
|
|
||||||
triggers = yaml.safe_load(existing['metadata'].get('annotations', '{}').get(TRIGGER_ANNOTATION, '[]'))
|
|
||||||
|
|
||||||
if not isinstance(triggers, list):
|
|
||||||
return definition
|
|
||||||
|
|
||||||
for trigger in triggers:
|
|
||||||
if trigger.get('fieldPath'):
|
|
||||||
parsed = self.parse_trigger_fieldpath(trigger['fieldPath'])
|
|
||||||
path = parsed.get('path', '').split('.')
|
|
||||||
if path:
|
|
||||||
existing_containers = get_from_fields(existing, path)
|
|
||||||
new_containers = get_from_fields(definition, path)
|
|
||||||
if parsed.get('name'):
|
|
||||||
existing_index = self.get_index({'name': parsed['name']}, existing_containers, ['name'])
|
|
||||||
new_index = self.get_index({'name': parsed['name']}, new_containers, ['name'])
|
|
||||||
elif parsed.get('index') is not None:
|
|
||||||
existing_index = new_index = int(parsed['index'])
|
|
||||||
else:
|
|
||||||
existing_index = new_index = None
|
|
||||||
if existing_index is not None and new_index is not None:
|
|
||||||
if existing_index < len(existing_containers) and new_index < len(new_containers):
|
|
||||||
set_from_fields(definition, path + [new_index, 'image'], get_from_fields(existing, path + [existing_index, 'image']))
|
|
||||||
return definition
|
|
||||||
|
|
||||||
def resolve_imagestream_triggers(self, existing, definition):
|
|
||||||
|
|
||||||
existing_triggers = existing.get('spec', {}).get('triggers')
|
|
||||||
new_triggers = definition['spec']['triggers']
|
|
||||||
existing_containers = existing.get('spec', {}).get('template', {}).get('spec', {}).get('containers', [])
|
|
||||||
new_containers = definition.get('spec', {}).get('template', {}).get('spec', {}).get('containers', [])
|
|
||||||
for i, trigger in enumerate(new_triggers):
|
|
||||||
if trigger.get('type') == 'ImageChange' and trigger.get('imageChangeParams'):
|
|
||||||
names = trigger['imageChangeParams'].get('containerNames', [])
|
|
||||||
for name in names:
|
|
||||||
old_container_index = self.get_index({'name': name}, existing_containers, ['name'])
|
|
||||||
new_container_index = self.get_index({'name': name}, new_containers, ['name'])
|
|
||||||
if old_container_index is not None and new_container_index is not None:
|
|
||||||
image = existing['spec']['template']['spec']['containers'][old_container_index]['image']
|
|
||||||
definition['spec']['template']['spec']['containers'][new_container_index]['image'] = image
|
|
||||||
|
|
||||||
existing_index = self.get_index(trigger['imageChangeParams'],
|
|
||||||
[x.get('imageChangeParams') for x in existing_triggers],
|
|
||||||
['containerNames'])
|
|
||||||
if existing_index is not None:
|
|
||||||
existing_image = existing_triggers[existing_index].get('imageChangeParams', {}).get('lastTriggeredImage')
|
|
||||||
if existing_image:
|
|
||||||
definition['spec']['triggers'][i]['imageChangeParams']['lastTriggeredImage'] = existing_image
|
|
||||||
existing_from = existing_triggers[existing_index].get('imageChangeParams', {}).get('from', {})
|
|
||||||
new_from = trigger['imageChangeParams'].get('from', {})
|
|
||||||
existing_namespace = existing_from.get('namespace')
|
|
||||||
existing_name = existing_from.get('name', False)
|
|
||||||
new_name = new_from.get('name', True)
|
|
||||||
add_namespace = existing_namespace and 'namespace' not in new_from.keys() and existing_name == new_name
|
|
||||||
if add_namespace:
|
|
||||||
definition['spec']['triggers'][i]['imageChangeParams']['from']['namespace'] = existing_from['namespace']
|
|
||||||
|
|
||||||
return definition
|
|
||||||
|
|
||||||
def parse_trigger_fieldpath(self, expression):
|
|
||||||
parsed = TRIGGER_CONTAINER.search(expression).groupdict()
|
|
||||||
if parsed.get('index'):
|
|
||||||
parsed['index'] = int(parsed['index'])
|
|
||||||
return parsed
|
|
||||||
|
|
||||||
def create_project_request(self, definition):
|
|
||||||
definition['kind'] = 'ProjectRequest'
|
|
||||||
result = {'changed': False, 'result': {}}
|
|
||||||
resource = self.find_resource('ProjectRequest', definition['apiVersion'], fail=True)
|
|
||||||
if not self.check_mode:
|
|
||||||
try:
|
|
||||||
k8s_obj = resource.create(definition)
|
|
||||||
result['result'] = k8s_obj.to_dict()
|
|
||||||
except DynamicApiError as exc:
|
|
||||||
self.fail_json(msg="Failed to create object: {0}".format(exc.body),
|
|
||||||
error=exc.status, status=exc.status, reason=exc.reason)
|
|
||||||
result['changed'] = True
|
|
||||||
result['method'] = 'create'
|
|
||||||
return result
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
OKDRawModule().execute_module()
|
mutually_exclusive = [
|
||||||
|
('resource_definition', 'src'),
|
||||||
|
('merge_type', 'apply'),
|
||||||
|
('template', 'resource_definition'),
|
||||||
|
('template', 'src'),
|
||||||
|
]
|
||||||
|
|
||||||
|
module = AnsibleModule(argument_spec=argspec(), supports_check_mode=True, mutually_exclusive=mutually_exclusive)
|
||||||
|
|
||||||
|
from ansible_collections.community.okd.plugins.module_utils.k8s import OKDRawModule
|
||||||
|
okdraw_module = OKDRawModule(module)
|
||||||
|
|
||||||
|
# remove_aliases from kubernetes.core's common requires the argspec attribute. Ideally, it should
|
||||||
|
# read that throught the module class, but we cannot change that.
|
||||||
|
okdraw_module.argspec = argspec()
|
||||||
|
okdraw_module.execute_module()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ options:
|
|||||||
type: str
|
type: str
|
||||||
|
|
||||||
requirements:
|
requirements:
|
||||||
- python >= 2.7
|
- python >= 3.6
|
||||||
- urllib3
|
- urllib3
|
||||||
- requests
|
- requests
|
||||||
- requests-oauthlib
|
- requests-oauthlib
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
# Copyright (c) 2020, Red Hat
|
|
||||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
||||||
|
|
||||||
from __future__ import absolute_import, division, print_function
|
from __future__ import absolute_import, division, print_function
|
||||||
__metaclass__ = type
|
__metaclass__ = type
|
||||||
|
|
||||||
|
# Copyright (c) 2020-2021, Red Hat
|
||||||
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
|
||||||
# STARTREMOVE (downstream)
|
# STARTREMOVE (downstream)
|
||||||
DOCUMENTATION = r'''
|
DOCUMENTATION = r'''
|
||||||
module: openshift_process
|
module: openshift_process
|
||||||
@@ -29,8 +29,8 @@ extends_documentation_fragment:
|
|||||||
- kubernetes.core.k8s_resource_options
|
- kubernetes.core.k8s_resource_options
|
||||||
|
|
||||||
requirements:
|
requirements:
|
||||||
- "python >= 2.7"
|
- "python >= 3.6"
|
||||||
- "openshift >= 0.11.0"
|
- "kubernetes >= 12.0.0"
|
||||||
- "PyYAML >= 3.11"
|
- "PyYAML >= 3.11"
|
||||||
|
|
||||||
options:
|
options:
|
||||||
@@ -203,186 +203,43 @@ resources:
|
|||||||
'''
|
'''
|
||||||
# ENDREMOVE (downstream)
|
# ENDREMOVE (downstream)
|
||||||
|
|
||||||
import re
|
|
||||||
import os
|
|
||||||
import copy
|
|
||||||
import traceback
|
|
||||||
|
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
|
||||||
from ansible.module_utils._text import to_native
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from ansible_collections.kubernetes.core.plugins.module_utils.common import (
|
from ansible_collections.kubernetes.core.plugins.module_utils.ansiblemodule import AnsibleModule
|
||||||
K8sAnsibleMixin, AUTH_ARG_SPEC, RESOURCE_ARG_SPEC, WAIT_ARG_SPEC
|
|
||||||
)
|
|
||||||
HAS_KUBERNETES_COLLECTION = True
|
|
||||||
except ImportError as e:
|
|
||||||
HAS_KUBERNETES_COLLECTION = False
|
|
||||||
k8s_collection_import_exception = e
|
|
||||||
K8S_COLLECTION_ERROR = traceback.format_exc()
|
|
||||||
K8sAnsibleMixin = object
|
|
||||||
AUTH_ARG_SPEC = RESOURCE_ARG_SPEC = WAIT_ARG_SPEC = {}
|
|
||||||
|
|
||||||
try:
|
|
||||||
from openshift.dynamic.exceptions import DynamicApiError, NotFoundError
|
|
||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
|
|
||||||
DOTENV_PARSER = re.compile(r"(?x)^(\s*(\#.*|\s*|(export\s+)?(?P<key>[A-z_][A-z0-9_.]*)=(?P<value>.+?)?)\s*)[\r\n]*$")
|
from ansible_collections.kubernetes.core.plugins.module_utils.args_common import (
|
||||||
|
AUTH_ARG_SPEC, RESOURCE_ARG_SPEC, WAIT_ARG_SPEC
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class OpenShiftProcess(K8sAnsibleMixin):
|
def argspec():
|
||||||
|
argument_spec = {}
|
||||||
|
argument_spec.update(AUTH_ARG_SPEC)
|
||||||
|
argument_spec.update(WAIT_ARG_SPEC)
|
||||||
|
argument_spec.update(RESOURCE_ARG_SPEC)
|
||||||
|
argument_spec['state'] = dict(type='str', default='rendered', choices=['present', 'absent', 'rendered'])
|
||||||
|
argument_spec['namespace'] = dict(type='str')
|
||||||
|
argument_spec['namespace_target'] = dict(type='str')
|
||||||
|
argument_spec['parameters'] = dict(type='dict')
|
||||||
|
argument_spec['name'] = dict(type='str')
|
||||||
|
argument_spec['parameter_file'] = dict(type='str')
|
||||||
|
|
||||||
def __init__(self):
|
return argument_spec
|
||||||
self.module = AnsibleModule(
|
|
||||||
argument_spec=self.argspec,
|
|
||||||
supports_check_mode=True,
|
|
||||||
)
|
|
||||||
self.fail_json = self.module.fail_json
|
|
||||||
self.exit_json = self.module.exit_json
|
|
||||||
|
|
||||||
if not HAS_KUBERNETES_COLLECTION:
|
|
||||||
self.module.fail_json(
|
|
||||||
msg="The kubernetes.core collection must be installed",
|
|
||||||
exception=K8S_COLLECTION_ERROR,
|
|
||||||
error=to_native(k8s_collection_import_exception)
|
|
||||||
)
|
|
||||||
|
|
||||||
super(OpenShiftProcess, self).__init__()
|
|
||||||
|
|
||||||
self.params = self.module.params
|
|
||||||
self.check_mode = self.module.check_mode
|
|
||||||
|
|
||||||
@property
|
|
||||||
def argspec(self):
|
|
||||||
spec = copy.deepcopy(AUTH_ARG_SPEC)
|
|
||||||
spec.update(copy.deepcopy(WAIT_ARG_SPEC))
|
|
||||||
spec.update(copy.deepcopy(RESOURCE_ARG_SPEC))
|
|
||||||
|
|
||||||
spec['state'] = dict(type='str', default='rendered', choices=['present', 'absent', 'rendered'])
|
|
||||||
spec['namespace'] = dict(type='str')
|
|
||||||
spec['namespace_target'] = dict(type='str')
|
|
||||||
spec['parameters'] = dict(type='dict')
|
|
||||||
spec['name'] = dict(type='str')
|
|
||||||
spec['parameter_file'] = dict(type='str')
|
|
||||||
|
|
||||||
return spec
|
|
||||||
|
|
||||||
def execute_module(self):
|
|
||||||
self.client = self.get_api_client()
|
|
||||||
|
|
||||||
v1_templates = self.find_resource('templates', 'template.openshift.io/v1', fail=True)
|
|
||||||
v1_processed_templates = self.find_resource('processedtemplates', 'template.openshift.io/v1', fail=True)
|
|
||||||
|
|
||||||
name = self.params.get('name')
|
|
||||||
namespace = self.params.get('namespace')
|
|
||||||
namespace_target = self.params.get('namespace_target')
|
|
||||||
definition = self.params.get('resource_definition')
|
|
||||||
src = self.params.get('src')
|
|
||||||
|
|
||||||
state = self.params.get('state')
|
|
||||||
|
|
||||||
parameters = self.params.get('parameters') or {}
|
|
||||||
parameter_file = self.params.get('parameter_file')
|
|
||||||
|
|
||||||
if (name and definition) or (name and src) or (src and definition):
|
|
||||||
self.fail_json("Only one of src, name, or definition may be provided")
|
|
||||||
|
|
||||||
if name and not namespace:
|
|
||||||
self.fail_json("namespace is required when name is set")
|
|
||||||
|
|
||||||
template = None
|
|
||||||
|
|
||||||
if src or definition:
|
|
||||||
self.set_resource_definitions()
|
|
||||||
if len(self.resource_definitions) < 1:
|
|
||||||
self.fail_json('Unable to load a Template resource from src or resource_definition')
|
|
||||||
elif len(self.resource_definitions) > 1:
|
|
||||||
self.fail_json('Multiple Template resources found in src or resource_definition, only one Template may be processed at a time')
|
|
||||||
template = self.resource_definitions[0]
|
|
||||||
template_namespace = template.get('metadata', {}).get('namespace')
|
|
||||||
namespace = template_namespace or namespace or namespace_target or 'default'
|
|
||||||
elif name and namespace:
|
|
||||||
try:
|
|
||||||
template = v1_templates.get(name=name, namespace=namespace).to_dict()
|
|
||||||
except DynamicApiError as exc:
|
|
||||||
self.fail_json(msg="Failed to retrieve Template with name '{0}' in namespace '{1}': {2}".format(name, namespace, exc.body),
|
|
||||||
error=exc.status, status=exc.status, reason=exc.reason)
|
|
||||||
except Exception as exc:
|
|
||||||
self.module.fail_json(msg="Failed to retrieve Template with name '{0}' in namespace '{1}': {2}".format(name, namespace, to_native(exc)),
|
|
||||||
error='', status='', reason='')
|
|
||||||
else:
|
|
||||||
self.fail_json("One of resource_definition, src, or name and namespace must be provided")
|
|
||||||
|
|
||||||
if parameter_file:
|
|
||||||
parameters = self.parse_dotenv_and_merge(parameters, parameter_file)
|
|
||||||
|
|
||||||
for k, v in parameters.items():
|
|
||||||
template = self.update_template_param(template, k, v)
|
|
||||||
|
|
||||||
result = {'changed': False}
|
|
||||||
|
|
||||||
try:
|
|
||||||
response = v1_processed_templates.create(body=template, namespace=namespace).to_dict()
|
|
||||||
except DynamicApiError as exc:
|
|
||||||
self.fail_json(msg="Server failed to render the Template: {0}".format(exc.body),
|
|
||||||
error=exc.status, status=exc.status, reason=exc.reason)
|
|
||||||
except Exception as exc:
|
|
||||||
self.module.fail_json(msg="Server failed to render the Template: {0}".format(to_native(exc)),
|
|
||||||
error='', status='', reason='')
|
|
||||||
|
|
||||||
result['message'] = response['message']
|
|
||||||
result['resources'] = response['objects']
|
|
||||||
|
|
||||||
if state != 'rendered':
|
|
||||||
self.resource_definitions = response['objects']
|
|
||||||
self.kind = self.api_version = self.name = None
|
|
||||||
self.namespace = self.params.get('namespace_target')
|
|
||||||
self.append_hash = False
|
|
||||||
self.apply = False
|
|
||||||
self.params['validate'] = None
|
|
||||||
self.params['merge_type'] = None
|
|
||||||
super(OpenShiftProcess, self).execute_module()
|
|
||||||
|
|
||||||
self.module.exit_json(**result)
|
|
||||||
|
|
||||||
def update_template_param(self, template, k, v):
|
|
||||||
for i, param in enumerate(template['parameters']):
|
|
||||||
if param['name'] == k:
|
|
||||||
template['parameters'][i]['value'] = v
|
|
||||||
return template
|
|
||||||
return template
|
|
||||||
|
|
||||||
def parse_dotenv_and_merge(self, parameters, parameter_file):
|
|
||||||
path = os.path.normpath(parameter_file)
|
|
||||||
if not os.path.exists(path):
|
|
||||||
self.fail(msg="Error accessing {0}. Does the file exist?".format(path))
|
|
||||||
try:
|
|
||||||
with open(path, 'r') as f:
|
|
||||||
multiline = ''
|
|
||||||
for line in f.readlines():
|
|
||||||
line = line.strip()
|
|
||||||
if line.endswith('\\'):
|
|
||||||
multiline += ' '.join(line.rsplit('\\', 1))
|
|
||||||
continue
|
|
||||||
if multiline:
|
|
||||||
line = multiline + line
|
|
||||||
multiline = ''
|
|
||||||
match = DOTENV_PARSER.search(line)
|
|
||||||
if not match:
|
|
||||||
continue
|
|
||||||
match = match.groupdict()
|
|
||||||
if match.get('key'):
|
|
||||||
if match['key'] in parameters:
|
|
||||||
self.fail_json(msg="Duplicate value for '{0}' detected in parameter file".format(match['key']))
|
|
||||||
parameters[match['key']] = match['value']
|
|
||||||
except IOError as exc:
|
|
||||||
self.fail(msg="Error loading parameter file: {0}".format(exc))
|
|
||||||
return parameters
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
OpenShiftProcess().execute_module()
|
argument_spec = argspec()
|
||||||
|
module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True)
|
||||||
|
|
||||||
|
from ansible_collections.community.okd.plugins.module_utils.openshift_process import (
|
||||||
|
OpenShiftProcess)
|
||||||
|
|
||||||
|
openshift_process = OpenShiftProcess(module)
|
||||||
|
# remove_aliases from kubernetes.core's common requires the argspec attribute. Ideally, it should
|
||||||
|
# read that throught the module class, but we cannot change that.
|
||||||
|
openshift_process.argspec = argument_spec
|
||||||
|
openshift_process.execute_module()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ author: "Fabian von Feilitzsch (@fabianvf)"
|
|||||||
description:
|
description:
|
||||||
- Looks up a Service and creates a new Route based on it.
|
- Looks up a Service and creates a new Route based on it.
|
||||||
- Analogous to `oc expose` and `oc create route` for creating Routes, but does not support creating Services.
|
- Analogous to `oc expose` and `oc create route` for creating Routes, but does not support creating Services.
|
||||||
- For creating Services from other resources, see kubernetes.core.k8s_expose
|
- For creating Services from other resources, see kubernetes.core.k8s.
|
||||||
|
|
||||||
extends_documentation_fragment:
|
extends_documentation_fragment:
|
||||||
- kubernetes.core.k8s_auth_options
|
- kubernetes.core.k8s_auth_options
|
||||||
@@ -29,8 +29,8 @@ extends_documentation_fragment:
|
|||||||
- kubernetes.core.k8s_state_options
|
- kubernetes.core.k8s_state_options
|
||||||
|
|
||||||
requirements:
|
requirements:
|
||||||
- "python >= 2.7"
|
- "python >= 3.6"
|
||||||
- "openshift >= 0.11.0"
|
- "kubernetes >= 12.0.0"
|
||||||
- "PyYAML >= 3.11"
|
- "PyYAML >= 3.11"
|
||||||
|
|
||||||
options:
|
options:
|
||||||
@@ -51,6 +51,12 @@ options:
|
|||||||
- Specify the labels to apply to the created Route.
|
- Specify the labels to apply to the created Route.
|
||||||
- 'A set of key: value pairs.'
|
- 'A set of key: value pairs.'
|
||||||
type: dict
|
type: dict
|
||||||
|
annotations:
|
||||||
|
description:
|
||||||
|
- Specify the Route Annotations.
|
||||||
|
- 'A set of key: value pairs.'
|
||||||
|
type: dict
|
||||||
|
version_added: "2.1.0"
|
||||||
name:
|
name:
|
||||||
description:
|
description:
|
||||||
- The desired name of the Route to be created.
|
- The desired name of the Route to be created.
|
||||||
@@ -174,6 +180,8 @@ EXAMPLES = r'''
|
|||||||
service: hello-kubernetes
|
service: hello-kubernetes
|
||||||
namespace: default
|
namespace: default
|
||||||
insecure_policy: allow
|
insecure_policy: allow
|
||||||
|
annotations:
|
||||||
|
haproxy.router.openshift.io/balance: roundrobin
|
||||||
register: route
|
register: route
|
||||||
'''
|
'''
|
||||||
|
|
||||||
@@ -301,12 +309,16 @@ duration:
|
|||||||
import copy
|
import copy
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
try:
|
||||||
|
from ansible_collections.kubernetes.core.plugins.module_utils.ansiblemodule import AnsibleModule
|
||||||
|
except ImportError:
|
||||||
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
from ansible.module_utils._text import to_native
|
from ansible.module_utils._text import to_native
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from ansible_collections.kubernetes.core.plugins.module_utils.common import (
|
from ansible_collections.kubernetes.core.plugins.module_utils.common import K8sAnsibleMixin, get_api_client
|
||||||
K8sAnsibleMixin, AUTH_ARG_SPEC, WAIT_ARG_SPEC, COMMON_ARG_SPEC
|
from ansible_collections.kubernetes.core.plugins.module_utils.args_common import (
|
||||||
|
AUTH_ARG_SPEC, WAIT_ARG_SPEC, COMMON_ARG_SPEC
|
||||||
)
|
)
|
||||||
HAS_KUBERNETES_COLLECTION = True
|
HAS_KUBERNETES_COLLECTION = True
|
||||||
except ImportError as e:
|
except ImportError as e:
|
||||||
@@ -317,7 +329,7 @@ except ImportError as e:
|
|||||||
AUTH_ARG_SPEC = WAIT_ARG_SPEC = COMMON_ARG_SPEC = {}
|
AUTH_ARG_SPEC = WAIT_ARG_SPEC = COMMON_ARG_SPEC = {}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from openshift.dynamic.exceptions import DynamicApiError, NotFoundError
|
from kubernetes.dynamic.exceptions import DynamicApiError, NotFoundError
|
||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -338,7 +350,7 @@ class OpenShiftRoute(K8sAnsibleMixin):
|
|||||||
error=to_native(k8s_collection_import_exception)
|
error=to_native(k8s_collection_import_exception)
|
||||||
)
|
)
|
||||||
|
|
||||||
super(OpenShiftRoute, self).__init__()
|
super(OpenShiftRoute, self).__init__(self.module)
|
||||||
|
|
||||||
self.params = self.module.params
|
self.params = self.module.params
|
||||||
# TODO: should probably make it so that at least some of these aren't required for perform_action to work
|
# TODO: should probably make it so that at least some of these aren't required for perform_action to work
|
||||||
@@ -348,6 +360,7 @@ class OpenShiftRoute(K8sAnsibleMixin):
|
|||||||
self.check_mode = self.module.check_mode
|
self.check_mode = self.module.check_mode
|
||||||
self.warnings = []
|
self.warnings = []
|
||||||
self.params['merge_type'] = None
|
self.params['merge_type'] = None
|
||||||
|
self.client = get_api_client(self.module)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def argspec(self):
|
def argspec(self):
|
||||||
@@ -371,11 +384,11 @@ class OpenShiftRoute(K8sAnsibleMixin):
|
|||||||
insecure_policy=dict(type='str', choices=['allow', 'redirect', 'disallow'], default='disallow'),
|
insecure_policy=dict(type='str', choices=['allow', 'redirect', 'disallow'], default='disallow'),
|
||||||
))
|
))
|
||||||
spec['termination'] = dict(choices=['edge', 'passthrough', 'reencrypt', 'insecure'], default='insecure')
|
spec['termination'] = dict(choices=['edge', 'passthrough', 'reencrypt', 'insecure'], default='insecure')
|
||||||
|
spec['annotations'] = dict(type='dict')
|
||||||
|
|
||||||
return spec
|
return spec
|
||||||
|
|
||||||
def execute_module(self):
|
def execute_module(self):
|
||||||
self.client = self.get_api_client()
|
|
||||||
v1_routes = self.find_resource('Route', 'route.openshift.io/v1', fail=True)
|
v1_routes = self.find_resource('Route', 'route.openshift.io/v1', fail=True)
|
||||||
|
|
||||||
service_name = self.params.get('service')
|
service_name = self.params.get('service')
|
||||||
@@ -400,6 +413,7 @@ class OpenShiftRoute(K8sAnsibleMixin):
|
|||||||
path = self.params.get('path')
|
path = self.params.get('path')
|
||||||
wildcard_policy = self.params.get('wildcard_policy')
|
wildcard_policy = self.params.get('wildcard_policy')
|
||||||
port = self.params.get('port')
|
port = self.params.get('port')
|
||||||
|
annotations = self.params.get('annotations')
|
||||||
|
|
||||||
if termination_type and self.params.get('tls'):
|
if termination_type and self.params.get('tls'):
|
||||||
tls_ca_cert = self.params['tls'].get('ca_certificate')
|
tls_ca_cert = self.params['tls'].get('ca_certificate')
|
||||||
@@ -423,6 +437,9 @@ class OpenShiftRoute(K8sAnsibleMixin):
|
|||||||
'spec': {}
|
'spec': {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if annotations:
|
||||||
|
route['metadata']['annotations'] = annotations
|
||||||
|
|
||||||
if state != 'absent':
|
if state != 'absent':
|
||||||
route['spec'] = self.build_route_spec(
|
route['spec'] = self.build_route_spec(
|
||||||
service_name, namespace,
|
service_name, namespace,
|
||||||
|
|||||||
+1
-1
@@ -1,2 +1,2 @@
|
|||||||
openshift>=0.6.2
|
kubernetes>=12.0.0
|
||||||
requests-oauthlib
|
requests-oauthlib
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
collections:
|
||||||
|
- name: kubernetes.core
|
||||||
|
version: '>=2.1.0,<2.3.0'
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
plugins/modules/k8s.py validate-modules:parameter-type-not-in-doc
|
plugins/modules/k8s.py validate-modules:parameter-type-not-in-doc
|
||||||
plugins/modules/k8s.py validate-modules:return-syntax-error
|
plugins/modules/k8s.py validate-modules:return-syntax-error
|
||||||
|
plugins/module_utils/k8s.py pylint:bad-option-value
|
||||||
plugins/modules/openshift_process.py validate-modules:parameter-type-not-in-doc
|
plugins/modules/openshift_process.py validate-modules:parameter-type-not-in-doc
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
plugins/modules/k8s.py validate-modules:parameter-type-not-in-doc
|
plugins/modules/k8s.py validate-modules:parameter-type-not-in-doc
|
||||||
plugins/modules/k8s.py validate-modules:return-syntax-error
|
plugins/modules/k8s.py validate-modules:return-syntax-error
|
||||||
|
plugins/module_utils/k8s.py pylint:bad-option-value
|
||||||
plugins/modules/openshift_process.py validate-modules:parameter-type-not-in-doc
|
plugins/modules/openshift_process.py validate-modules:parameter-type-not-in-doc
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
plugins/modules/k8s.py validate-modules:parameter-type-not-in-doc
|
||||||
|
plugins/modules/k8s.py validate-modules:return-syntax-error
|
||||||
|
plugins/modules/openshift_process.py validate-modules:parameter-type-not-in-doc
|
||||||
@@ -1,2 +1,3 @@
|
|||||||
plugins/modules/k8s.py validate-modules:parameter-type-not-in-doc
|
plugins/modules/k8s.py validate-modules:parameter-type-not-in-doc
|
||||||
|
plugins/module_utils/k8s.py pylint:bad-option-value
|
||||||
plugins/modules/openshift_process.py validate-modules:parameter-type-not-in-doc
|
plugins/modules/openshift_process.py validate-modules:parameter-type-not-in-doc
|
||||||
|
|||||||
Reference in New Issue
Block a user