Last active
November 24, 2020 02:56
-
-
Save richm/f3338790eb48b6a3f0963f908a2f4a03 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- name: set collection paths | |
set_fact: | |
collection_paths: | | |
{{ | |
(lookup("env","ANSIBLE_COLLECTIONS_PATH").split(":") + | |
lookup("env","ANSIBLE_COLLECTIONS_PATHS").split(":") + | |
lookup("config", "COLLECTIONS_PATHS")) | | |
select | list | |
}} | |
- name: get collection modules paths | |
shell: | | |
set -euxo pipefail | |
for dir in {{ collection_paths | join(" ") }}; do | |
for subdir in $dir/ansible_collections/*/*/plugins/modules; do | |
if [ -d "$subdir" ]; then | |
echo "$subdir" | |
fi | |
done | |
done | |
register: collection_modules | |
- name: get collection module_utils paths | |
shell: | | |
set -euxo pipefail | |
for dir in {{ collection_paths | join(" ") }}; do | |
for subdir in $dir/ansible_collections/*/*/plugins/module_utils; do | |
if [ -d "$subdir" ]; then | |
echo "$subdir" | |
fi | |
done | |
done | |
register: collection_module_utils | |
- name: set search paths | |
set_fact: | |
modules_search_path: | | |
{{ | |
(lookup("env", "ANSIBLE_LIBRARY").split(":") + | |
["../../library"] + | |
lookup("config", "DEFAULT_MODULE_PATH")) | | |
select | list + collection_modules.stdout_lines | |
}} | |
module_utils_search_path: | | |
{{ | |
(lookup("env", "ANSIBLE_MODULE_UTILS").split(":") + | |
["../../module_utils"] + | |
lookup("config", "DEFAULT_MODULE_UTILS_PATH")) | | |
select | list + collection_module_utils.stdout_lines | |
}} | |
- name: find modules file | |
set_fact: | |
modules_file: "{{ lookup('first_found', params) }}" | |
vars: | |
params: | |
files: | |
- network_connections.py | |
paths: "{{ modules_search_path }}" | |
- name: find module_utils file | |
set_fact: | |
module_utils_file: "{{ lookup('first_found', params) }}" | |
vars: | |
params: | |
files: | |
- network_lsr | |
paths: "{{ module_utils_search_path }}" | |
- name: get tempfile for tar | |
tempfile: | |
prefix: lsrtest_ | |
suffix: ".tar" | |
register: temptar | |
delegate_to: localhost | |
# TODO: using tar and copying the file is a workaround for the synchronize | |
# module that does not work in test-harness. Related issue: | |
# https://github.com/linux-system-roles/test-harness/issues/102 | |
# | |
- name: Create Tar file | |
command: > | |
tar -cvf {{ temptar.path }} --exclude "*.pyc" --exclude "__pycache__" | |
-C ../.. tests | |
-C {{ modules_file | realpath | dirname | dirname }} {{ modules_file | realpath | dirname | basename }} | |
-C {{ module_utils_file | realpath | dirname | dirname }} {{ module_utils_file | realpath | dirname | basename }} | |
delegate_to: localhost | |
- name: Copy testrepo.tar to the remote system | |
copy: | |
src: "{{ temptar.path }}" | |
dest: "{{ rundir }}" | |
- name: Untar testrepo.tar | |
command: tar xf {{ temptar.path | basename }} | |
args: | |
chdir: "{{ rundir }}" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment