- Actions decorated with
@AnsibleAction.run_method
now support Ansible'sdelegate_to
feature out-of-the-box. That is,run_method
constructs theiransible_api.jinja
out of the Ansible vars fetched fromhostvars
by thedelegate_to
YAML field. For the (supposedly rare) case where the task want to peek at or use the “undelegated” variables, they are accessible throughansible_api.undelegated.jinja
. - New method
.lookup()
forAnsibleActions
instances
- When calling
run_action
, Ansible variables that require setting up a new connection object (such asansible_connection
,ansible_user
) etc. (conservatively and) automatically cause a new connection to be created. It follows that themake_connection
andmake_shell
APIs are obsolete. - Introduce API to reify the Jinja machinery (accessible as the
.jinja
field ofAnsibleActions
instances) - Make exception messages (in particular, when using
.jinja.expand()
easier to debug - Introduce the first unit tests!!
- Fix the case of
delegate_to:
tasks calling action plugins that in turn, pass a customconnection
object torun_action
- Introduce
ansible_api.has_var()
method - Add
defaults
andoverrides
parameters torun_action()
method; fixvars
parameter of same in some cases - Ability to pass supplemental parameters to
ansible_api.run_action()
through theSubaction
class
Subactions
constructor no longer acceptstask_vars
as an argumentshell
may be used in aquery
subaction under the same caveats ascommand
- When an action (such as
ansible.builtin.copy
) shadows a module (i.e. the core of an AnsiballZ) with the same name, we want to run the former rather than the latter. Previous versions did the incorrect thing, i.e. the other way around. - Ability to pass
defaults
toansible_api.expand_var()
, which is basically the opposite ofoverrides
priority-wise (i.e. values indefaults
“underride” the user-set variables)
... and also I guess it was time for an 1.0 release.
with AnsibleCheckMode(...).bypassed
is no longer supported, because it no longer works (... since 2019).- As a replacement,
run_action()
now has abypass_check_mode
optional parameter, which theSubaction()
class sets on subaction invocations that credibly have no effect (i.e.stat
andcommand
, and then only when called with.query()
)
- Drop support for Python 2. Version 0.3.1 is the last version that supports Python 2.
- Provide
ansible_api.expand_var()
to encapsulate the Jinja business (a.k.a.templar
in the Ansible source code) - Tasks written on top of
epfl_si.actions.plugins.module_utils.ansible_api
may now observe variables (using the new optional argumenttask_vars
to the decoratedrun()
method), and change them before passing them toansible_api.run_action()
- Likewise, tasks may now create connections with customized Ansible variables by calling the
ansible_api.make_connection()
method and/or theansible_api.make_shell()
method, which the former invokes indirectly.
In 0.3.0, we forgout about run_postcondition()
also being helpful to call from an AnsiballZ context. It now accepts both an AnsibleCheckMode
instance and a plain old Boolean as its second argument.
- The
ansible_collections.epfl_si.actions.plugins.module_utils.ansible_api
andansible_collections.epfl_si.actions.plugins.module_utils.postconditions
modules now support being imported as part of an AnsiballZ package (i.e., from alibrary
module that gets sent over the wire to the remote Python interpreter)
- Various documentation and
galaxy.yml
improvements, dead code removal
Deprecations / API changes:
- The
update_result
parameter toSubaction(...).change
is deprecated; instead, one should set theSubaction(...).result
object field to an Ansible result dict, that will be updated both by.query
and.change
- The
Subaction
constructor now takes anAnsibleActions
API helper (but it still accepts.run()
-style arguments as well for backwards compatibility)
The grace period for these deprecations will end when version 1.0.0 is released. Please update your code with the new APIs.
New features:
- New
ansible_collections.epfl_si.actions.plugins.module_utils.ansible_api
module, featuring theAnsibleActions
class (mentioned above); an@AnsibleActions.run_method
decorator; and theAnsibleResults
“pure static” class. When used together, these classes and decorator abstract away the unpleasant details of the Ansible architecture (or lack thereof) into more palatable (and sustainable) APIs, even for consumer code that doesn't want to use theSubaction
class. - New
ansible_collections.epfl_si.actions.plugins.module_utils.postcondition
module, letting you write Ansible action modules whose behavior is split into postcondition (how to know if there is anything to do in the first place) and enforcement (how to actually do it). Using thePostcondition
abstract base class, one can write useful and correct (w.r.t. “colors” and--check
support) Ansible action modules with a lot less pre-requisite knowledge about the Ansible return dict or the rest of the Ansible API. Subaction(...).query
andSubaction(...).change
both take a newfailed_when=
optional parameter
Bugfixes:
- When passing (obsolete, see above)
update_result
parameter to.change()
, also update it if it is falsy (empty)