Skip to content

Commit

Permalink
Merge tag 'v4.2.0' into rel420
Browse files Browse the repository at this point in the history
Release 4.2.0
  • Loading branch information
evgeni committed Aug 30, 2024
2 parents fdd951c + 270736f commit 03e0cac
Show file tree
Hide file tree
Showing 164 changed files with 8,230 additions and 8,199 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ jobs:
- name: prepare a redhat-uep.pem, even if we run on Ubuntu
run: sudo mkdir -p /etc/rhsm/ca/ && sudo curl -o /etc/rhsm/ca/redhat-uep.pem https://ftp.redhat.com/redhat/convert2rhel/redhat-uep.pem
- name: Install required collections for ansible-base (2.10+)
run: ansible-galaxy collection install community.docker
run: ansible-galaxy collection install https://galaxy.ansible.com/api/v3/plugin/ansible/content/published/collections/artifacts/community-docker-3.12.0.tar.gz
if: matrix.ansible != 'v2.9.17'
- name: Run crud tests
run: make test-crud
Expand Down
41 changes: 41 additions & 0 deletions .packit.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# See the documentation for more information:
# https://packit.dev/docs/configuration/

specfile_path: ansible-collection-theforeman-foreman.spec

# add or remove files that should be synced
files_to_sync:
- ansible-collection-theforeman-foreman.spec
- .packit.yaml

# name in upstream package repository or registry (e.g. in PyPI)
upstream_package_name: theforeman.foreman
# downstream (Fedora) RPM package name
downstream_package_name: ansible-collection-theforeman-foreman

upstream_tag_template: v{version}

actions:
post-upstream-clone:
- "wget https://github.com/theforeman/foreman-packaging/raw/rpm/develop/packages/plugins/ansible-collection-theforeman-foreman/ansible-collection-theforeman-foreman.spec -O ansible-collection-theforeman-foreman.spec"
get-current-version:
- python3 -c 'import yaml; print(yaml.safe_load(open("galaxy.yml"))["version"].replace("-dev", ""))'
create-archive:
- make dist PYTHON_COMMAND=python3
- bash -c "ls -1t ./theforeman-foreman-*.tar.gz | head -n 1"

jobs:
- job: copr_build
trigger: pull_request
targets:
- rhel-8
- rhel-9
module_hotfixes: true

srpm_build_deps:
- wget
- python3
- python3-py
- python3-pyyaml
- make
- ansible-core
16 changes: 16 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,22 @@ redhat.satellite Release Notes

This changelog describes changes after version 0.8.1.

v4.2.0
======

Minor Changes
-------------

- content_export_* - document that ``chunk_size_gb`` parameter is only applicable for ``importable`` exports (https://github.com/theforeman/foreman-ansible-modules/issues/1738)
- lifecycle_environments role - allow setting ``state`` for the LCE, allowing deletion of existing ones
- location, locations role - add ``description`` parameter to set the description

Bugfixes
--------

- callback plugin - correctly catch facts with vault data and replace it with ``ENCRYPTED_VAULT_VALUE_NOT_REPORTED``, preventing ``Object of type AnsibleVaultEncryptedUnicode is not JSON serializable`` errors
- redhat_manifest - do not send empty JSON bodies in GET requests which confuse the portal sometimes (https://github.com/theforeman/foreman-ansible-modules/issues/1768)

v4.1.0
======

Expand Down
21 changes: 21 additions & 0 deletions changelogs/changelog.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -894,3 +894,24 @@ releases:
name: content_import_version
namespace: ''
release_date: '2024-07-12'
4.2.0:
changes:
bugfixes:
- callback plugin - correctly catch facts with vault data and replace it with
``ENCRYPTED_VAULT_VALUE_NOT_REPORTED``, preventing ``Object of type AnsibleVaultEncryptedUnicode
is not JSON serializable`` errors
- redhat_manifest - do not send empty JSON bodies in GET requests which confuse
the portal sometimes (https://github.com/theforeman/foreman-ansible-modules/issues/1768)
minor_changes:
- content_export_* - document that ``chunk_size_gb`` parameter is only applicable
for ``importable`` exports (https://github.com/theforeman/foreman-ansible-modules/issues/1738)
- lifecycle_environments role - allow setting ``state`` for the LCE, allowing
deletion of existing ones
- location, locations role - add ``description`` parameter to set the description
fragments:
- 1724-location_description.yml
- 1738-export_chunk_size.yml
- 1768-empty-get-body.yml
- 1769-callback-vault-facts.yml
- lce-role-state.yml
release_date: '2024-08-30'
5 changes: 4 additions & 1 deletion galaxy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,14 @@ authors:
- "Partha Aji <[email protected]>"
- "Patrick C. F. Ernzer <[email protected]>"
- "Patrick Creech <[email protected]>"
- "Patrick Pfurtscheller <[email protected]>"
- "Paul Armstrong <[email protected]>"
- "Paul Belanger <[email protected]>"
- "Paul Gration <[email protected]>"
- "Peter Ondrejka <[email protected]>"
- "Philipp <[email protected]>"
- "Quirin Pamp <[email protected]>"
- "Richard J Osborne <[email protected]>"
- "Richard Stempfl <[email protected]>"
- "Richard Waax <[email protected]>"
- "Sam <[email protected]>"
Expand All @@ -94,6 +96,7 @@ authors:
- "alesc <[email protected]>"
- "bob <[email protected]>"
- "calvingsmith <[email protected]>"
- "cojmckee <[email protected]>"
- "divialth <[email protected]>"
- "furhouse <[email protected]>"
- "gardar <[email protected]>"
Expand All @@ -105,7 +108,7 @@ authors:
- "russianguppie <[email protected]>"
- "willtome <[email protected]>"
- "yuqo2450 <[email protected]>"
version: "4.1.0"
version: "4.2.0"
license:
- "GPL-3.0-or-later"
tags:
Expand Down
19 changes: 16 additions & 3 deletions plugins/callback/foreman.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@
HAS_REQUESTS = False

from ansible.module_utils._text import to_text
from ansible.module_utils.common.json import AnsibleJSONEncoder
from ansible.module_utils.parsing.convert_bool import boolean as to_bool
from ansible.plugins.callback import CallbackBase

Expand Down Expand Up @@ -172,6 +173,15 @@ def get_now():
return datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S+00:00")


class AnsibleNoVaultJSONEncoder(AnsibleJSONEncoder):
def default(self, o):
if getattr(o, '__ENCRYPTED__', False):
value = 'ENCRYPTED_VAULT_VALUE_NOT_REPORTED'
else:
value = super(AnsibleNoVaultJSONEncoder, self).default(o)
return value


class CallbackModule(CallbackBase):
CALLBACK_VERSION = 2.0
CALLBACK_TYPE = 'notification'
Expand Down Expand Up @@ -243,14 +253,17 @@ def _send_data(self, data_type, report_type, host, data):
else:
self._display.warning(u'Unknown report_type: {rt}'.format(rt=report_type))

json_data = json.dumps(data, indent=2, sort_keys=True, cls=AnsibleNoVaultJSONEncoder)

if len(self.dir_store) > 0:
filename = u'{host}.json'.format(host=to_text(host))
filename = u'{host}-{dt}.json'.format(host=to_text(host), dt=data_type)
filename = os.path.join(self.dir_store, filename)
with open(filename, 'w') as f:
json.dump(data, f, indent=2, sort_keys=True)
f.write(json_data)
else:
try:
response = self.session.post(url=url, json=data)
headers = {'content-type': 'application/json'}
response = self.session.post(url=url, data=json_data, headers=headers)
response.raise_for_status()
except requests.exceptions.RequestException as err:
self._display.warning(u'Sending data to Foreman at {url} failed for {host}: {err}'.format(
Expand Down
1 change: 1 addition & 0 deletions plugins/doc_fragments/foreman.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ class ModuleDocFragment(object):
chunk_size_gb:
description:
- Split the exported content into archives no greater than the specified size in gigabytes.
- Only applicable for C(format=importable). C(syncable) exports can't be split.
required: false
type: int
format:
Expand Down
3 changes: 3 additions & 0 deletions plugins/module_utils/foreman_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -1585,6 +1585,9 @@ def run(self, **kwargs):
if self.params.get('from_history_id') and incremental is not True:
self.fail_json(msg='from_history_id is only valid for incremental exports')

if 'chunk_size_gb' in self.foreman_params and self.foreman_params['format'] == 'syncable':
self.fail_json(msg='chunk_size_gb is only valid for importable exports')

self.auto_lookup_entities()

payload = _flatten_entity(self.foreman_params, self.foreman_spec)
Expand Down
7 changes: 7 additions & 0 deletions plugins/modules/location.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@
- Name of the Location
required: true
type: str
description:
description:
- Description of the Location
required: false
type: str
version_added: 4.2.0
parent:
description:
- Title of a parent Location for nesting
Expand Down Expand Up @@ -123,6 +129,7 @@ def main():
module = ForemanLocationModule(
foreman_spec=dict(
name=dict(required=True),
description=dict(required=False),
parent=dict(type='entity'),
organizations=dict(type='entity_list'),
ignore_types=dict(type='list', elements='str', required=False, aliases=['select_all_types']),
Expand Down
12 changes: 6 additions & 6 deletions plugins/modules/redhat_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,24 +146,24 @@


def fetch_portal(module, path, method, data=None, accept_header='application/json'):
if data is None:
data = {}
headers = {'accept': accept_header}
if data is not None:
data = json.dumps(data)
headers['content-type'] = 'application/json'
url = module.params['portal'] + path
headers = {'accept': accept_header,
'content-type': 'application/json'}
fetch_kwargs = {'timeout': 30}
if os.path.exists(REDHAT_UEP):
fetch_kwargs['ca_path'] = REDHAT_UEP
try:
resp, info = fetch_url(module, url, json.dumps(data), headers, method, **fetch_kwargs)
resp, info = fetch_url(module, url, data, headers, method, **fetch_kwargs)
except TypeError:
# ca_path was added in Ansible 2.9 and backported to 2.8 in 2.8.6
# older Ansible releases don't support that and we have to omit the CA cert here
if module.params['validate_certs']:
module.warn("Your Ansible version does not support providing custom CA certificates for HTTP requests. "
"Talking to the Red Hat portal might fail without validate_certs=False. Please update.")
del fetch_kwargs['ca_path']
resp, info = fetch_url(module, url, json.dumps(data), headers, method, **fetch_kwargs)
resp, info = fetch_url(module, url, data, headers, method, **fetch_kwargs)
if resp is None or info["status"] >= 400:
try:
error = json.loads(info['body'])['displayMessage']
Expand Down
3 changes: 2 additions & 1 deletion plugins/modules/sync_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@
type: bool
sync_date:
description:
- Start date and time of the first synchronization
- Start date and time of the first synchronization.
- Multiple formats are accepted, but only C(YYYY-mm-dd HH:MM:SS +z) (e.g. C(2024-08-01 00:00:00 +0000)) will be idempotent.
required: true
type: str
cron_expression:
Expand Down
16 changes: 16 additions & 0 deletions roles/activation_keys/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,19 @@ Define two Activation Keys. The first registers hosts in the "ACME" organization
```
Following the second example, a Host which is registered using `subscription-manager register --activationkey ACME_App_Key,ACME_RHEL7_Base_Test` will get the ACME_App subscription, Test LCE, RHEL7_Base Content View, and auto-attach any additional necessary subscriptions from ACME Organization to cover the Base OS and any other products which require an entitlement certificate.

To delete multiple activation_keys
```yaml
- hosts: localhost
roles:
- role: redhat.satellite.activation_keys
vars:
satellite_server_url: https://satellite.example.com
satellite_username: "admin"
satellite_password: "changeme"
satellite_organization: "ACME"
satellite_activation_keys:
- name: "ACME_App_Key"
state: absent
- name: "ACME_OS_Key"
state: absent
4 changes: 2 additions & 2 deletions roles/activation_keys/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
- name: 'Create Activation Keys' # noqa: args[module]
- name: 'Create or Delete Activation Keys' # noqa: args[module]
redhat.satellite.activation_key:
username: "{{ satellite_username | default(omit) }}"
password: "{{ satellite_password | default(omit) }}"
Expand All @@ -21,6 +21,6 @@
purpose_usage: "{{ item.purpose_usage | default(omit) }}"
purpose_role: "{{ item.purpose_role | default(omit) }}"
purpose_addons: "{{ item.purpose_addons | default(omit) }}"
state: present
state: "{{ item.state | default('present') }}"
with_items:
- "{{ satellite_activation_keys }}"
2 changes: 1 addition & 1 deletion roles/lifecycle_environments/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
description: "{{ item.description | default(omit) }}"
prior: "{{ item.prior }}"
label: "{{ item.label | default(omit) }}"
state: present
state: "{{ item.state | default('present') }}"
with_items:
- "{{ satellite_lifecycle_environments }}"
1 change: 1 addition & 0 deletions roles/locations/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
server_url: "{{ satellite_server_url | default(omit) }}"
validate_certs: "{{ satellite_validate_certs | default(omit) }}"
name: "{{ item.name }}"
description: "{{ item.description | default(omit) }}"
parent: "{{ item.parent | default(omit) }}"
organizations: "{{ item.organizations | default(omit) }}"
parameters: "{{ item.parameters | default(omit) }}"
Expand Down
5 changes: 5 additions & 0 deletions roles/repositories/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,14 @@
validate_certs: "{{ satellite_validate_certs | default(omit) }}"
organization: "{{ satellite_organization }}"
name: "{{ item.name }}"
description: "{{ item.description | default(omit) }}"
label: "{{ item.label | default(omit) }}"
gpg_key: "{{ item.gpg_key | default(omit) }}"
ssl_ca_cert: "{{ item.ssl_ca_cert | default(omit) }}"
ssl_client_cert: "{{ item.ssl_client_cert | default(omit) }}"
ssl_client_key: "{{ item.ssl_client_key | default(omit) }}"
state: "{{ item.state | default(omit) }}"
sync_plan: "{{ item.sync_plan | default(omit) }}"
with_items:
- "{{ satellite_products | selectattr('repositories', 'defined') | map('combine', {'repositories': '[FILTERED]'}) | list }}"

Expand Down
23 changes: 23 additions & 0 deletions tests/callback/three_hosts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
gather_facts: false
vars:
foo: foo bar
crypt: !vault |
$ANSIBLE_VAULT;1.1;AES256
62343962363339363461373565656663663734393265636161313466326163666638333735303061
6134346238366533616262663462396332363535363662660a323339326635373330633230336332
38363334373037356466383063616532656632303636333839313831626264386132386661303535
3864663564356332390a633631363962353163316236323038363861623763616265343762366435
6237
tasks:
- name: Changed task
command: echo foo
Expand Down Expand Up @@ -34,6 +41,22 @@
loop_control:
label: foo-{{ item }}

- name: Vault command
command: echo {{ crypt }}

- name: Vault fact
set_fact:
geheim: "{{ crypt }}"
crypt: !vault |
$ANSIBLE_VAULT;1.1;AES256
62343962363339363461373565656663663734393265636161313466326163666638333735303061
6134346238366533616262663462396332363535363662660a323339326635373330633230336332
38363334373037356466383063616532656632303636333839313831626264386132386661303535
3864663564356332390a633631363962353163316236323038363861623763616265343762366435
6237
unsafe: !unsafe |
THIS IS {{ crypt }}
handlers:
- name: Test handler 1
command: echo foo
Expand Down
1 change: 1 addition & 0 deletions tests/callback/vault-pass
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
changeme
1 change: 1 addition & 0 deletions tests/fixtures/apidoc/content_view_filter_deb.json
1 change: 1 addition & 0 deletions tests/fixtures/apidoc/content_view_filter_info_deb.json
1 change: 1 addition & 0 deletions tests/fixtures/apidoc/content_view_filter_rule_deb.json
12 changes: 12 additions & 0 deletions tests/fixtures/callback/dir_store/foreman/testhost-facts.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"facts": {
"_timestamp": "2000-01-01 12:00:00+00:00",
"_type": "ansible",
"ansible_facts": {
"crypt": "ENCRYPTED_VAULT_VALUE_NOT_REPORTED",
"geheim": "admin",
"unsafe": "THIS IS {{ crypt }}\n"
}
},
"name": "testhost"
}
Loading

0 comments on commit 03e0cac

Please sign in to comment.