From 020a76c3ad1ccd537eb198e09620ff63cdd3eb63 Mon Sep 17 00:00:00 2001 From: Alan Rominger Date: Mon, 11 Nov 2024 08:08:02 -0500 Subject: [PATCH] Use lookup for test failures, update docs --- awx_collection/README.md | 27 ++-------- .../plugins/lookup/schedule_rrule.py | 2 +- .../plugins/lookup/schedule_rruleset.py | 2 +- .../targets/lookup_rruleset/tasks/main.yml | 54 +++++++++---------- .../targets/schedule_rrule/tasks/main.yml | 10 ++-- .../template_galaxy/templates/README.md.j2 | 1 + 6 files changed, 37 insertions(+), 59 deletions(-) diff --git a/awx_collection/README.md b/awx_collection/README.md index b6dd3f3a8dc7..2482568a28a6 100644 --- a/awx_collection/README.md +++ b/awx_collection/README.md @@ -32,33 +32,11 @@ Installing the `tar.gz` involves no special instructions. ## Running Non-deprecated modules in this collection have no Python requirements, but -may require the official [AWX CLI](https://pypi.org/project/awxkit/) +may require the AWX CLI in the future. The `DOCUMENTATION` for each module will report this. -You can specify authentication by a combination of either: +You can specify authentication by host, username, and password. - - host, username, password - - host, OAuth2 token - -The OAuth2 token is the preferred method. You can obtain a token via the -``login`` command with the AWX CLI. - -These can be specified via (from highest to lowest precedence): - - - direct module parameters - - environment variables (most useful when running against localhost) - - a config file path specified by the `tower_config_file` parameter - - a config file at `~/.tower_cli.cfg` - - a config file at `/etc/tower/tower_cli.cfg` - -Config file syntax looks like this: - -``` -[general] -host = https://localhost:8043 -verify_ssl = true -oauth_token = LEdCpKVKc4znzffcpQL5vLG8oyeku6 -``` ## Release and Upgrade Notes @@ -101,6 +79,7 @@ The following notes are changes that may require changes to playbooks: - The `notification_configuration` parameter of `tower_notification_template` has changed from a string to a dict. Please use the `lookup` plugin to read an existing file into a dict. - `tower_credential` no longer supports passing a file name to `ssh_key_data`. - The HipChat `notification_type` has been removed and can no longer be created using the `tower_notification_template` module. + - Lookup plugins now always reutrn a list, and if you want a scalar value use `lookup` as opposed to `query` ## Running Unit Tests diff --git a/awx_collection/plugins/lookup/schedule_rrule.py b/awx_collection/plugins/lookup/schedule_rrule.py index b6326eda4972..8931a75dfb52 100644 --- a/awx_collection/plugins/lookup/schedule_rrule.py +++ b/awx_collection/plugins/lookup/schedule_rrule.py @@ -75,7 +75,7 @@ EXAMPLES = """ - name: Create a string for a schedule debug: - msg: "{{ query('awx.awx.schedule_rrule', 'none', start_date='1979-09-13 03:45:07') }}" + msg: "{{ lookup('awx.awx.schedule_rrule', 'none', start_date='1979-09-13 03:45:07') }}" """ RETURN = """ diff --git a/awx_collection/plugins/lookup/schedule_rruleset.py b/awx_collection/plugins/lookup/schedule_rruleset.py index fb78920e9f72..bbb9f6542ea3 100644 --- a/awx_collection/plugins/lookup/schedule_rruleset.py +++ b/awx_collection/plugins/lookup/schedule_rruleset.py @@ -109,7 +109,7 @@ EXAMPLES = """ - name: Create a ruleset for everyday except Sundays set_fact: - complex_rule: "{{ query(awx.awx.schedule_rruleset, '2022-04-30 10:30:45', rules=rrules, timezone='UTC' ) }}" + complex_rule: "{{ lookup(awx.awx.schedule_rruleset, '2022-04-30 10:30:45', rules=rrules, timezone='UTC' ) }}" vars: rrules: - frequency: 'day' diff --git a/awx_collection/tests/integration/targets/lookup_rruleset/tasks/main.yml b/awx_collection/tests/integration/targets/lookup_rruleset/tasks/main.yml index 1552e5eb2861..a779454f4978 100644 --- a/awx_collection/tests/integration/targets/lookup_rruleset/tasks/main.yml +++ b/awx_collection/tests/integration/targets/lookup_rruleset/tasks/main.yml @@ -11,7 +11,7 @@ - name: Call ruleset with no rules set_fact: - complex_rule: "{{ query(ruleset_plugin_name | string, '2022-04-30 10:30:45') }}" + complex_rule: "{{ lookup(ruleset_plugin_name | string, '2022-04-30 10:30:45') }}" ignore_errors: True register: results @@ -23,7 +23,7 @@ - name: call ruleset with a missing frequency set_fact: - complex_rule: "{{ query(ruleset_plugin_name, '2022-04-30 10:30:45', rules=rrules ) }}" + complex_rule: "{{ lookup(ruleset_plugin_name, '2022-04-30 10:30:45', rules=rrules ) }}" ignore_errors: True register: results vars: @@ -41,7 +41,7 @@ - name: call ruleset with a missing frequency set_fact: - complex_rule: "{{ query(ruleset_plugin_name, '2022-04-30 10:30:45', rules=rrules ) }}" + complex_rule: "{{ lookup(ruleset_plugin_name, '2022-04-30 10:30:45', rules=rrules ) }}" ignore_errors: True register: results vars: @@ -59,7 +59,7 @@ - name: call rruleset with an invalid frequency set_fact: - complex_rule: "{{ query(ruleset_plugin_name, '2022-04-30 10:30:45', rules=rrules ) }}" + complex_rule: "{{ lookup(ruleset_plugin_name, '2022-04-30 10:30:45', rules=rrules ) }}" ignore_errors: True register: results vars: @@ -78,7 +78,7 @@ - name: call rruleset with an invalid end_on set_fact: - complex_rule: "{{ query(ruleset_plugin_name, '2022-04-30 10:30:45', rules=rrules ) }}" + complex_rule: "{{ lookup(ruleset_plugin_name, '2022-04-30 10:30:45', rules=rrules ) }}" ignore_errors: True register: results vars: @@ -97,7 +97,7 @@ - name: Every Mondays set_fact: - complex_rule: "{{ query(ruleset_plugin_name, '2022-04-30 10:30:45', rules=rrules, timezone='UTC' ) }}" + complex_rule: "{{ lookup(ruleset_plugin_name, '2022-04-30 10:30:45', rules=rrules, timezone='UTC' ) }}" ignore_errors: True register: results vars: @@ -106,17 +106,15 @@ interval: 1 byweekday: 'monday' -- debug: msg='{{complex_rule}}' - - assert: that: - results is success - - "['DTSTART;TZID=UTC:20220430T103045 RRULE:FREQ=DAILY;BYDAY=MO;INTERVAL=1'] == complex_rule" + - "'DTSTART;TZID=UTC:20220430T103045 RRULE:FREQ=DAILY;BYDAY=MO;INTERVAL=1' == complex_rule" - name: call rruleset with an invalid byweekday set_fact: - complex_rule: "{{ query(ruleset_plugin_name, '2022-04-30 10:30:45', rules=rrules ) }}" + complex_rule: "{{ lookup(ruleset_plugin_name, '2022-04-30 10:30:45', rules=rrules ) }}" ignore_errors: True register: results vars: @@ -135,7 +133,7 @@ - name: call rruleset with a monthly rule with invalid bymonthday (a) set_fact: - complex_rule: "{{ query(ruleset_plugin_name, '2022-04-30 10:30:45', rules=rrules ) }}" + complex_rule: "{{ lookup(ruleset_plugin_name, '2022-04-30 10:30:45', rules=rrules ) }}" ignore_errors: True register: results vars: @@ -154,7 +152,7 @@ - name: call rruleset with a monthly rule with invalid bymonthday (-1) set_fact: - complex_rule: "{{ query(ruleset_plugin_name, '2022-04-30 10:30:45', rules=rrules ) }}" + complex_rule: "{{ lookup(ruleset_plugin_name, '2022-04-30 10:30:45', rules=rrules ) }}" ignore_errors: True register: results vars: @@ -173,7 +171,7 @@ - name: call rruleset with a monthly rule with invalid bymonthday (32) set_fact: - complex_rule: "{{ query(ruleset_plugin_name, '2022-04-30 10:30:45', rules=rrules ) }}" + complex_rule: "{{ lookup(ruleset_plugin_name, '2022-04-30 10:30:45', rules=rrules ) }}" ignore_errors: True register: results vars: @@ -192,7 +190,7 @@ - name: call rruleset with a monthly rule with invalid bysetpos (junk) set_fact: - complex_rule: "{{ query(ruleset_plugin_name, '2022-04-30 10:30:45', rules=rrules ) }}" + complex_rule: "{{ lookup(ruleset_plugin_name, '2022-04-30 10:30:45', rules=rrules ) }}" ignore_errors: True register: results vars: @@ -211,7 +209,7 @@ - name: call rruleset with an invalid timezone set_fact: - complex_rule: "{{ query(ruleset_plugin_name, '2022-04-30 10:30:45', rules=rrules, timezone='junk' ) }}" + complex_rule: "{{ lookup(ruleset_plugin_name, '2022-04-30 10:30:45', rules=rrules, timezone='junk' ) }}" ignore_errors: True register: results vars: @@ -230,7 +228,7 @@ - name: call rruleset with only exclude rules set_fact: - complex_rule: "{{ query(ruleset_plugin_name, '2022-04-30 10:30:45', rules=rrules ) }}" + complex_rule: "{{ lookup(ruleset_plugin_name, '2022-04-30 10:30:45', rules=rrules ) }}" ignore_errors: True register: results vars: @@ -251,7 +249,7 @@ - name: Every day except for Sundays set_fact: - complex_rule: "{{ query(ruleset_plugin_name, '2022-04-30 10:30:45', rules=rrules, timezone='UTC' ) }}" + complex_rule: "{{ lookup(ruleset_plugin_name, '2022-04-30 10:30:45', rules=rrules, timezone='UTC' ) }}" ignore_errors: True register: results vars: @@ -266,12 +264,12 @@ - assert: that: - results is success - - "['DTSTART;TZID=UTC:20220430T103045 RRULE:FREQ=DAILY;INTERVAL=1 EXRULE:FREQ=DAILY;BYDAY=SU;INTERVAL=1'] == complex_rule" + - "'DTSTART;TZID=UTC:20220430T103045 RRULE:FREQ=DAILY;INTERVAL=1 EXRULE:FREQ=DAILY;BYDAY=SU;INTERVAL=1' == complex_rule" - name: Every day except for April 30th set_fact: - complex_rule: "{{ query(ruleset_plugin_name, '2023-04-28 17:00:00', rules=rrules, timezone='UTC' ) }}" + complex_rule: "{{ lookup(ruleset_plugin_name, '2023-04-28 17:00:00', rules=rrules, timezone='UTC' ) }}" ignore_errors: True register: results vars: @@ -287,12 +285,12 @@ - assert: that: - results is success - - "['DTSTART;TZID=UTC:20230428T170000 RRULE:FREQ=DAILY;INTERVAL=1 EXRULE:FREQ=DAILY;BYMONTH=4;BYMONTHDAY=30;INTERVAL=1'] == complex_rule" + - "'DTSTART;TZID=UTC:20230428T170000 RRULE:FREQ=DAILY;INTERVAL=1 EXRULE:FREQ=DAILY;BYMONTH=4;BYMONTHDAY=30;INTERVAL=1' == complex_rule" - name: Every 5 minutes but not on Mondays from 5-7pm set_fact: - complex_rule: "{{ query(ruleset_plugin_name, '2022-04-30 10:30:45', rules=rrules, timezone='UTC' ) }}" + complex_rule: "{{ lookup(ruleset_plugin_name, '2022-04-30 10:30:45', rules=rrules, timezone='UTC' ) }}" ignore_errors: True register: results vars: @@ -310,12 +308,12 @@ - assert: that: - results is success - - "['DTSTART;TZID=UTC:20220430T103045 RRULE:FREQ=MINUTELY;INTERVAL=5 EXRULE:FREQ=MINUTELY;INTERVAL=5;BYDAY=MO;BYHOUR=17,18'] == complex_rule" + - "'DTSTART;TZID=UTC:20220430T103045 RRULE:FREQ=MINUTELY;INTERVAL=5 EXRULE:FREQ=MINUTELY;INTERVAL=5;BYDAY=MO;BYHOUR=17,18' == complex_rule" - name: Every 15 minutes Monday to Friday from 10:01am to 6:02pm (inclusive) set_fact: - complex_rule: "{{ query(ruleset_plugin_name, '2022-04-30 10:30:45', rules=rrules, timezone='UTC' ) }}" + complex_rule: "{{ lookup(ruleset_plugin_name, '2022-04-30 10:30:45', rules=rrules, timezone='UTC' ) }}" ignore_errors: True register: results vars: @@ -339,12 +337,12 @@ - assert: that: - results is success - - "['DTSTART;TZID=UTC:20220430T103045 RRULE:FREQ=MINUTELY;INTERVAL=15;BYDAY=MO,TU,WE,TH,FR;BYHOUR=10,11,12,13,14,15,16,17,18 EXRULE:FREQ=MINUTELY;BYDAY=MO,TU,WE,TH,FR;BYHOUR=18;BYMINUTE=3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59;INTERVAL=1'] == complex_rule" + - "'DTSTART;TZID=UTC:20220430T103045 RRULE:FREQ=MINUTELY;INTERVAL=15;BYDAY=MO,TU,WE,TH,FR;BYHOUR=10,11,12,13,14,15,16,17,18 EXRULE:FREQ=MINUTELY;BYDAY=MO,TU,WE,TH,FR;BYHOUR=18;BYMINUTE=3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59;INTERVAL=1' == complex_rule" - name: Any Saturday whose month day is between 12 and 18 set_fact: - complex_rule: "{{ query(ruleset_plugin_name, '2022-04-30 10:30:45', rules=rrules, timezone='UTC' ) }}" + complex_rule: "{{ lookup(ruleset_plugin_name, '2022-04-30 10:30:45', rules=rrules, timezone='UTC' ) }}" ignore_errors: True register: results vars: @@ -357,11 +355,11 @@ - assert: that: - results is success - - "['DTSTART;TZID=UTC:20220430T103045 RRULE:FREQ=MONTHLY;BYMONTHDAY=12,13,14,15,16,17,18;BYDAY=SA;INTERVAL=1'] == complex_rule" + - "'DTSTART;TZID=UTC:20220430T103045 RRULE:FREQ=MONTHLY;BYMONTHDAY=12,13,14,15,16,17,18;BYDAY=SA;INTERVAL=1' == complex_rule" - name: mondays, Tuesdays, and WEDNESDAY with case-insensitivity set_fact: - complex_rule: "{{ query(ruleset_plugin_name, '2022-04-30 10:30:45', rules=rrules, timezone='UTC' ) }}" + complex_rule: "{{ lookup(ruleset_plugin_name, '2022-04-30 10:30:45', rules=rrules, timezone='UTC' ) }}" ignore_errors: True register: results vars: @@ -373,4 +371,4 @@ - assert: that: - results is success - - "['DTSTART;TZID=UTC:20220430T103045 RRULE:FREQ=DAILY;BYDAY=MO,TU,WE;INTERVAL=1'] == complex_rule" + - "'DTSTART;TZID=UTC:20220430T103045 RRULE:FREQ=DAILY;BYDAY=MO,TU,WE;INTERVAL=1' == complex_rule" diff --git a/awx_collection/tests/integration/targets/schedule_rrule/tasks/main.yml b/awx_collection/tests/integration/targets/schedule_rrule/tasks/main.yml index a75005682679..7811d51663e4 100644 --- a/awx_collection/tests/integration/targets/schedule_rrule/tasks/main.yml +++ b/awx_collection/tests/integration/targets/schedule_rrule/tasks/main.yml @@ -9,7 +9,7 @@ - name: Test too many params (failure from validation of terms) ansible.builtin.debug: - msg: "{{ query(plugin_name | string, 'none', 'weekly', start_date='2020-4-16 03:45:07') }}" + msg: "{{ lookup(plugin_name | string, 'none', 'weekly', start_date='2020-4-16 03:45:07') }}" ignore_errors: true register: result @@ -20,7 +20,7 @@ - name: Test invalid frequency (failure from validation of term) ansible.builtin.debug: - msg: "{{ query(plugin_name, 'john', start_date='2020-4-16 03:45:07') }}" + msg: "{{ lookup(plugin_name, 'john', start_date='2020-4-16 03:45:07') }}" ignore_errors: true register: result @@ -31,7 +31,7 @@ - name: Test an invalid start date (generic failure case from get_rrule) ansible.builtin.debug: - msg: "{{ query(plugin_name, 'none', start_date='invalid') }}" + msg: "{{ lookup(plugin_name, 'none', start_date='invalid') }}" ignore_errors: true register: result @@ -42,9 +42,9 @@ - name: Test end_on as count (generic success case) ansible.builtin.debug: - msg: "{{ query(plugin_name, 'minute', start_date='2020-4-16 03:45:07', end_on='2') }}" + msg: "{{ lookup(plugin_name, 'minute', start_date='2020-4-16 03:45:07', end_on='2') }}" register: result - ansible.builtin.assert: that: - - "result.msg == ['DTSTART;TZID=America/New_York:20200416T034507 RRULE:FREQ=MINUTELY;COUNT=2;INTERVAL=1']" + - result.msg == 'DTSTART;TZID=America/New_York:20200416T034507 RRULE:FREQ=MINUTELY;COUNT=2;INTERVAL=1' diff --git a/awx_collection/tools/roles/template_galaxy/templates/README.md.j2 b/awx_collection/tools/roles/template_galaxy/templates/README.md.j2 index 8ffe9d33dffb..e7c232b26395 100644 --- a/awx_collection/tools/roles/template_galaxy/templates/README.md.j2 +++ b/awx_collection/tools/roles/template_galaxy/templates/README.md.j2 @@ -90,6 +90,7 @@ The following notes are changes that may require changes to playbooks: - The `notification_configuration` parameter of `tower_notification_template` has changed from a string to a dict. Please use the `lookup` plugin to read an existing file into a dict. - `tower_credential` no longer supports passing a file name to `ssh_key_data`. - The HipChat `notification_type` has been removed and can no longer be created using the `tower_notification_template` module. + - Lookup plugins now always reutrn a list, and if you want a scalar value use `lookup` as opposed to `query` {% if collection_package | lower() == "awx" %} ## Running Unit Tests