Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transform function options #292

Merged

Conversation

optiz0r
Copy link
Contributor

@optiz0r optiz0r commented Dec 24, 2018

Adds support, documentation and tests for a new transform_function_options inventory configuration option.

Fixes #290

@coveralls
Copy link

coveralls commented Dec 24, 2018

Pull Request Test Coverage Report for Build 1094

  • 5 of 5 (100.0%) changed or added relevant lines in 4 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.01%) to 92.217%

Totals Coverage Status
Change from base Build 1086: 0.01%
Covered Lines: 1410
Relevant Lines: 1529

💛 - Coveralls

For transform functions to be reusable, it may be useful to be able
to pass additional parameters other than the inventory host object.
A typical use case is to pass in sensitive configuration data from
a separate secret management tool to the inventory data.

This change adds an additional `transform_function_options` parameter
to the `InventoryConfig`.

The transform_function_options` must be a dictionary with string keys
which are also valid python identifiers. The contents of this dict
will be passed to the transform function as `kwargs`.

Example:

```yaml
---
inventory:
  transform_function: __main__.transform_inventory
  transform_function_options:
    password: "supersecret"
```

```python
def transform_inventory(host, password, **kwargs):
  """ Example transform function which adds the password argument to
  each host data
  """
  host.data['password'] = password
```

Add docs and tests for transform_function_options

Fixes 290
@optiz0r optiz0r changed the title [WIP] Transform function options Transform function options Dec 24, 2018
@dbarrosop
Copy link
Contributor

Awesome!

@dbarrosop dbarrosop merged commit 9bed66f into nornir-automation:develop Dec 28, 2018
@optiz0r optiz0r deleted the transform_function_options branch December 28, 2018 11:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants