Skip to content

Commit

Permalink
Move parameter documentation from run() to RunnerConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
Shrews committed Nov 11, 2024
1 parent ba9f6b9 commit 3a9946f
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 89 deletions.
8 changes: 0 additions & 8 deletions docs/ansible_runner.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,6 @@ ansible_runner.runner module
:undoc-members:
:show-inheritance:

ansible_runner.runner\_config module
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. automodule:: ansible_runner.runner_config
:members:
:undoc-members:
:show-inheritance:

ansible_runner.utils module
^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand Down
4 changes: 2 additions & 2 deletions docs/porting_guides/porting_guide_v2.5.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ object. For example:
.. code-block:: python
import ansible_runner
config = ansible_runner.RunnerConfig('private_data_dir': '/tmp/demo', 'playbook': 'test.yml')
config = ansible_runner.RunnerConfig(private_data_dir='/tmp/demo', playbook='test.yml')
r = ansible_runner.interface.run(config=config)
The above is identical to the more familiar usage of the API:

.. code-block:: python
import ansible_runner
r = ansible_runner.interface.run('private_data_dir': '/tmp/demo', 'playbook': 'test.yml')
r = ansible_runner.interface.run(private_data_dir='/tmp/demo', playbook='test.yml')
54 changes: 51 additions & 3 deletions src/ansible_runner/config/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,57 @@ class BaseConfig:
"""The base configuration object.
This object has multiple initialization responsibilities, including:
- guaranteeing the 'private_data_dir' directory exists
- guaranteeing that 'ident' value is set
- setting the various work directory attributes based on 'private_data_dir'
- guaranteeing the ``private_data_dir`` directory exists
- guaranteeing that ``ident`` value is set
- setting the various work directory attributes based on ``private_data_dir``
:param str private_data_dir: The directory containing all runner metadata needed to invoke the runner
module. Output artifacts will also be stored here for later consumption.
:param str artifact_dir: The path to the directory where artifacts should live. This defaults to
``artifacts`` under ``private_data_dir``.
:param bool check_job_event_data: Check if job events data is completely generated. If event data is
not completely generated and if value is set to ``True`` it will raise an `AnsibleRunnerException` exception.
If set to ``False``, it log a debug message and continue execution. Default value is ``False``.
:param dict container_auth_data: Container registry authentication data containing ``host``, ``username``, and
``password`` entries.
:param str container_image: Container image to use when running an ansible task.
:param list container_options: List of container options to pass to execution engine.
:param list container_volume_mounts: List of bind mounts in the form 'host_dir:/container_dir`. Default to ``None``.
:param str container_workdir: The working directory within the container.
:param dict envvars: Environment variables to be used when running Ansible. Environment variables will also be
read from ``env/envvars`` in ``private_data_dir``.
:param str fact_cache: A string that will be used as the name for the subdirectory of the fact cache in
artifacts directory. This is only used for ``jsonfile`` type fact caches.
:param str fact_cache_type: A string of the type of fact cache to use. Defaults to ``jsonfile``.
:param str host_cwd: The host current working directory to be mounted within the container (if enabled) and will be
the work directory within container.
:param str ident: The run identifier for this invocation of Runner. Will be used to create and name
the artifact directory holding the results of the invocation.
:param bool json_mode: Store event data in place of stdout on the console and in the stdout file.
:param int keepalive_seconds: Use within the streaming Worker object to inject a keepalive event.
:param dict passwords: A dictionary containing password prompt patterns and response values used when processing
output from Ansible. Passwords will also be read from ``env/passwords`` in ``private_data_dir``.
:param bool process_isolation: Enable process isolation, using either a container engine (e.g. podman) or a
sandbox (e.g. bwrap).
:param str process_isolation_executable: Process isolation executable or container engine used to isolate
execution. (default: podman)
:param str project_dir: The path to the playbook content. Defaults to ``project`` within ``private_data_dir``.
:param bool quiet: Disable all output.
:param int rotate_artifacts: Keep at most n artifact directories. Disable with a value of ``0`` (the default).
:param dict settings: A dictionary containing settings values for the ``ansible-runner`` runtime environment.
These will also be read from ``env/settings`` in ``private_data_dir``.
:param str ssh_key: The ssh private key passed to ``ssh-agent`` as part of the ansible-playbook run.
:param bool suppress_env_files: Disable the writing of files into the ``env`` which may store sensitive information.
:param int timeout: The timeout value, in seconds, that will be passed to either ``pexpect`` of ``subprocess``
invocation (based on ``runner_mode`` selected) while executing command. It the timeout is triggered it will
force cancel the execution.
:param Callable event_handler: An optional callback that will be invoked any time an event is received by Runner itself.
Return ``True`` to keep the event
:param Callable cancel_callback: An optional callback that can inform runner to cancel (returning ``True``) or not
(returning ``False``).
:param Callable finished_callback: An optional callback that will be invoked at shutdown after process cleanup.
:param Callable status_handler: An optional callback that will be invoked any time the status changes (e.g...started, running, failed, successful, timeout)
:param Callable artifacts_handler: An optional callback that will be invoked at the end of the run to deal with the artifacts from the run.
"""

# This MUST be the first field we define to handle the use case where a RunnerConfig object
Expand Down
49 changes: 45 additions & 4 deletions src/ansible_runner/config/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,11 @@ class ExecutionMode():

@dataclass
class RunnerConfig(BaseConfig):
"""
A ``Runner`` configuration object that's meant to encapsulate the configuration used by the
"""A ``Runner`` configuration object that's meant to encapsulate the configuration used by the
:py:mod:`ansible_runner.runner.Runner` object to launch and manage the invocation of ``ansible``
and ``ansible-playbook``
Typically this object is initialized for you when using the standard ``run`` interfaces in :py:mod:`ansible_runner.interface`
Typically, this object is initialized for you when using the standard ``run`` interfaces in :py:mod:`ansible_runner.interface`
but can be used to construct the ``Runner`` configuration to be invoked elsewhere. It can also be overridden to provide different
functionality to the Runner object.
Expand All @@ -65,6 +64,48 @@ class RunnerConfig(BaseConfig):
>>> r = Runner(config=rc)
>>> r.run()
This class inherites all the initialization parameters of the `BaseConfig` parent class, plus:
:param BinaryIO _input: An optional file or file-like object for use as input in a streaming pipeline.
:param BinaryIO _output: An optional file or file-like object for use as output in a streaming pipeline.
:param str binary: Path to an alternative ansible command.
:param str cmdline: Command line options passed to Ansible read from ``env/cmdline`` in ``private_data_dir``
:param str directory_isolation_base_path: An optional path will be used as the base path to create a temp directory.
The project contents will be copied to this location which will then be used as the working directory during
playbook execution.
:param dict extravars: Extra variables to be passed to Ansible at runtime using ``-e``. Extra vars will also be
read from ``env/extravars`` in ``private_data_dir``.
:param int forks: Control Ansible parallel concurrency.
:param str host_pattern: The host pattern to match when running in ad-hoc mode.
:param str or dict or list inventory: Overrides the inventory directory/file (supplied at ``private_data_dir/inventory``) with
a specific host or list of hosts. This can take the form of:
- Path to the inventory file in the ``private_data_dir/inventory`` directory or
an absolute path to the inventory file
- Native python dict supporting the YAML/json inventory structure
- A text INI formatted string
- A list of inventory sources, or an empty list to disable passing inventory
:param str limit: Matches ansible's ``--limit`` parameter to further constrain the inventory to be used.
:param str module: The module that will be invoked in ad-hoc mode by runner when executing Ansible.
:param str module_args: The module arguments that will be supplied to ad-hoc mode.
:param bool omit_event_data: Omits extra ansible event data from event payload (stdout and event still included).
:param bool only_failed_event_data: Omits extra ansible event data unless it's a failed event (stdout and event still included).
:param bool only_transmit_kwargs: If ``True``, the streaming Transmitter process will only send job arguments.
:param str or dict or list playbook: The playbook (either a list or dictionary of plays, or as a path relative to
``private_data_dir/project``) that will be invoked by runner when executing Ansible.
:param str or list process_isolation_hide_paths: A path or list of paths on the system that should be hidden from the playbook run.
:param str or list process_isolation_ro_paths: A path or list of paths on the system that should be exposed to the playbook run as read-only.
:param str or list process_isolation_show_paths: A path or list of paths on the system that should be exposed to the playbook run.
:param str process_isolation_path: Path that an isolated playbook run will use for staging. (default: ``/tmp``)
:param str role: Name of the role to execute.
:param bool role_skip_facts: If ``True``, ``gather_facts`` will be set to ``False`` for execution of the namedgit ``role``.
:param str or list roles_path: Directory or list of directories to assign to ``ANSIBLE_ROLES_PATH``.
:param dict role_vars: Variables and their values to use with the named ``role``.
:param str skip_tags: Value to pass to the ``--skip-tags`` option of ``ansible-playbook``.
:param bool suppress_ansible_output: If ``True``, Ansible output will not appear to stdout.
:param bool suppress_output_file: If ``True``, Ansible output will not be written to a file in the artifacts directory.
:param str tags: Value to pass to the ``--tags`` option of ``ansible-playbook``.
:param int verbosity: Control the verbosity level of ansible-playbook.
"""

_input: BinaryIO | None = field(metadata={MetaValues.TRANSMIT: False}, default=None)
Expand Down Expand Up @@ -205,7 +246,7 @@ def prepare(self):
- prepare_command
It's also responsible for wrapping the command with the proper ssh agent invocation
and setting early ANSIBLE_ environment variables.
and setting early ``ANSIBLE_`` environment variables.
"""
# ansible_path = find_executable('ansible')
# if ansible_path is None or not os.access(ansible_path, os.X_OK):
Expand Down
Loading

0 comments on commit 3a9946f

Please sign in to comment.