Skip to content

Commit

Permalink
Use lookup for test failures, update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
AlanCoding committed Nov 11, 2024
1 parent ccd2f7b commit 020a76c
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 59 deletions.
27 changes: 3 additions & 24 deletions awx_collection/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion awx_collection/plugins/lookup/schedule_rrule.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = """
Expand Down
2 changes: 1 addition & 1 deletion awx_collection/plugins/lookup/schedule_rruleset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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"
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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'
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 020a76c

Please sign in to comment.