Skip to content

Commit 29f2119

Browse files
Merge pull request #676 from redhatci/template-dir
add the copy_and_render role
2 parents 4602960 + 225c774 commit 29f2119

File tree

14 files changed

+143
-5
lines changed

14 files changed

+143
-5
lines changed

.ansible-lint

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ exclude_paths:
1515
- plugins
1616
- hack
1717
- tests
18+
- roles/**/molecule
1819

1920
skip_list:
2021
- var-naming[no-role-prefix]

.github/workflows/pr.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ jobs:
114114
run: pip install https://github.com/ansible/ansible/archive/${{ matrix.ansible }}.tar.gz --disable-pip-version-check
115115

116116
# Fail when new errors appear
117-
- name: Run ansible-test sanity/units
117+
- name: Run ansible-test sanity/units/integration
118118
run: |
119119
set -x
120120
# Prefer using podman over docker

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
*.tar.gz
22
roles/**/.linted
3+
tests/integration/inventory
34
tests/output
45
__pycache__

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ The collection has multiple CI pipelines that run on every PR:
6262

6363
- PR pipeline: [`.github/workflows/pr.yml`](../.github/workflows/pr.yml) that runs the sanity tests and Ansible lint. It fails if there is any regression. It also runs a check on the PR Dependencies (`Depends-On:` lines in the commit message) to make sure that the dependencies are merged before the PR. Tests can be run locally:
6464
- For Ansible lint tests, run [`./hack/ansible-lint.sh -d`](hack/ansible-lint.sh).
65-
- For Sanity and Unit tests, run [`./hack/run_ansible_test.sh`](hack/run_ansible_test.sh).
65+
- For Sanity, Integration and Unit tests, run [`./hack/run_ansible_test.sh`](hack/run_ansible_test.sh).
6666
- For Doc checks, run [`./hack/check_doc.sh`](hack/check_doc.sh).
6767
- For version checks, run [`./hack/check_version.sh`](hack/check_version.sh).
6868
- DCI BOS2 pipeline: [`.github/workflows/dci.yml`](../.github/workflows/dci.yml) that runs a DCI job to test the collection in a virtual environment at the BOS2 Telco Partner CI lab. It is triggered only when a change is modifying files in the `/roles/` directory.

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ Name | Description
5555
[redhatci.ocp.create_vms](https://github.com/redhatci/ansible-collection-redhatci-ocp/blob/main/roles/create_vms/README.md) | Provisions libvirt network, storage pools and the KVM Nodes.
5656
[redhatci.ocp.create_helmchart](https://github.com/redhatci/ansible-collection-redhatci-ocp/blob/main/roles/create_helmchart/README.md) | Creation of a Helm Chart certification project
5757
[redhatci.ocp.create_pr](https://github.com/redhatci/ansible-collection-redhatci-ocp/blob/main/roles/create_pr/README.md) | Pull-Request handling for helm chart certification and operator bundle certification.
58+
[redhatci.ocp.copy_and_render](https://github.com/redhatci/ansible-collection-redhatci-ocp/blob/main/roles/copy_and_render/README.md) | Copies files and subdirectories from a source dir to a target dir, then renders and replaces all Jinja2 .j2 templates
5859
[redhatci.ocp.deploy_cr](https://github.com/redhatci/ansible-collection-redhatci-ocp/blob/main/roles/deploy_cr/README.md) | Deploys a custom resource
5960
[redhatci.ocp.deprecated_api](https://github.com/redhatci/ansible-collection-redhatci-ocp/blob/main/roles/deprecated_api/README.md) | Extracts deprecated API calls in a cluster
6061
[redhatci.ocp.destroy_vms](https://github.com/redhatci/ansible-collection-redhatci-ocp/blob/main/roles/destroy_vms/README.md) | Destroys libvirt network, storage pools and the KVM Nodes and the network bridge connection.

ansible-collection-redhatci-ocp.spec

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
%global forgeurl https://github.com/%{org}/%{repo}
44

55
Name: %{repo}
6-
Version: 2.4.EPOCH
6+
Version: 2.5.EPOCH
77
Release: VERS%{?dist}
88
Summary: Red Hat OCP CI Collection for Ansible
99

@@ -54,6 +54,9 @@ find -type f ! -executable -name '*.py' -print -exec sed -i -e '1{\@^#!.*@d}' '{
5454

5555

5656
%changelog
57+
* Mon May 26 2025 Frederic Lepied <[email protected]> - 2.5.EPOCH-VERS
58+
- New role copy_and_render
59+
5760
* Tue May 20 2025 Tony Garcia <[email protected]> - 2.4.EPOCH-VERS
5861
- Version bump for role updates - acm.utils
5962

galaxy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ name: ocp
99
# Always leave patch version as .0
1010
# Patch version is replaced from commit date in UNIX epoch format
1111
# example: 1.3.2147483647
12-
version: 2.4.0
12+
version: 2.5.0
1313

1414
# The path to the Markdown (.md) readme file.
1515
readme: README.md

hack/run_ansible_test.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,21 @@ trap 'git checkout -- "$branch"' EXIT
2828
git fetch --unshallow origin main || :
2929

3030
# extract all the supported python versions from the error message, excluding 3.5
31-
EXCLUDE="--exclude hack/ --exclude plugins/modules/nmcli.py"
31+
EXCLUDE="--exclude tests/ --exclude hack/ --exclude plugins/modules/nmcli.py"
3232
PY_VERS=$(ansible-test sanity $EXCLUDE --verbose --docker --python 1.0 --color --coverage --failure-ok 2>&1 |
3333
grep -Po "invalid.*?\K'3.*\d'" |
3434
tr -d ,\' |
3535
sed -e 's/3.5 //g')
3636
for version in $PY_VERS; do
3737
ansible-test sanity $EXCLUDE --verbose --docker --python $version --color --coverage --failure-ok
3838
ansible-test units --verbose --docker --python $version --color --coverage || :
39+
ansible-test integration --verbose --docker --python $version --color --coverage || :
3940
done 2> >(tee -a branch.output >&2)
4041
git checkout origin/main
4142
for version in $PY_VERS; do
4243
ansible-test sanity $EXCLUDE --verbose --docker --python $version --color --coverage --failure-ok
4344
ansible-test units --verbose --docker --python $version --color --coverage || :
45+
ansible-test integration --verbose --docker --python $version --color --coverage || :
4446
done 2> main.output 1>/dev/null
4547
for key in branch main; do
4648
grep -E "((ERROR|FATAL):|FAILED )" "$key.output" |

roles/copy_and_render/README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# copy_and_render
2+
3+
Role to copy files and subdirectories from a source directory to a target directory, then render and replace all Jinja2 `.j2` templates.
4+
5+
Role Variables:
6+
7+
`car_source_dir` (string, required): Source directory on the control machine containing files and `.j2` templates.
8+
`car_target_dir` (string, required): Destination directory on the remote host where files will be copied and templates rendered.
9+
10+
Example Playbook:
11+
12+
```yaml
13+
- hosts: all
14+
roles:
15+
- role: copy_and_render
16+
vars:
17+
car_source_dir: "/path/to/source"
18+
car_target_dir: "/path/to/target"
19+
```
20+
21+
Requirements:
22+
23+
- Ansible 2.9 or higher
24+
25+
License:
26+
27+
Apache-2.0
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
3+
- name: Validate that car_source_dir and car_target_dir are set
4+
ansible.builtin.assert:
5+
that:
6+
- car_source_dir is defined
7+
- car_source_dir | length > 0
8+
- car_target_dir is defined
9+
- car_target_dir | length > 0
10+
fail_msg: "Both car_source_dir and car_target_dir must be defined and non-empty"
11+
12+
- name: Copy files and subdirectories from source to target
13+
ansible.builtin.copy:
14+
src: "{{ car_source_dir | regex_replace('/$', '') }}/"
15+
dest: "{{ car_target_dir }}"
16+
mode: '0644'
17+
18+
- name: Find Jinja2 template files
19+
ansible.builtin.find:
20+
paths: "{{ car_source_dir }}"
21+
patterns: "*.j2"
22+
file_type: file
23+
register: _car_j2_templates
24+
25+
- name: Render Jinja2 templates to target directory
26+
ansible.builtin.template:
27+
src: "{{ item.path }}"
28+
dest: "{{ car_target_dir }}/{{ item.path | basename | regex_replace('\\.j2$', '') }}"
29+
mode: '0644'
30+
loop: "{{ _car_j2_templates.files }}"
31+
32+
- name: Remove original .j2 template files from target directory
33+
ansible.builtin.file:
34+
path: "{{ car_target_dir }}/{{ item.path | basename }}"
35+
state: absent
36+
loop: "{{ _car_j2_templates.files }}"
37+
38+
...

0 commit comments

Comments
 (0)