community.docker.docker_machine inventory – Docker Machine inventory source

Note

This inventory plugin is part of the community.docker collection (version 2.6.0).

You might already have this collection installed if you are using the ansible package. It is not included in ansible-core. To check whether it is installed, run ansible-galaxy collection list.

To install it, use: ansible-galaxy collection install community.docker.

To use it in a playbook, specify: community.docker.docker_machine.

Synopsis

  • Get inventory hosts from Docker Machine.

  • Uses a YAML configuration file that ends with docker_machine.(yml|yaml).

  • The plugin sets standard host variables ansible_host, ansible_port, ansible_user and ansible_ssh_private_key.

  • The plugin stores the Docker Machine ‘env’ output variables in dm_ prefixed host variables.

Requirements

The below requirements are needed on the local controller node that executes this inventory.

Parameters

Parameter

Comments

compose

dictionary

Create vars from jinja2 expressions.

Default: {}

daemon_env

string

Whether docker daemon connection environment variables should be fetched, and how to behave if they cannot be fetched.

With require and require-silently, fetch them and skip any host for which they cannot be fetched. A warning will be issued for any skipped host if the choice is require.

With optional and optional-silently, fetch them and not skip hosts for which they cannot be fetched. A warning will be issued for hosts where they cannot be fetched if the choice is optional.

With skip, do not attempt to fetch the docker daemon connection environment variables.

If fetched successfully, the variables will be prefixed with dm_ and stored as host variables.

Choices:

  • require ← (default)

  • require-silently

  • optional

  • optional-silently

  • skip

groups

dictionary

Add hosts to group based on Jinja2 conditionals.

Default: {}

keyed_groups

list / elements=dictionary

Add hosts to group based on the values of a variable.

Default: []

default_value

string

added in 2.12 of ansible.builtin

The default value when the host variable’s value is an empty string.

This option is mutually exclusive with trailing_separator.

key

string

The key from input dictionary used to generate groups

parent_group

string

parent group for keyed group

prefix

string

A keyed group name will start with this prefix

Default: “”

separator

string

separator used to build the keyed group name

Default: “_”

trailing_separator

boolean

added in 2.12 of ansible.builtin

Set this option to False to omit the separator after the host variable when the value is an empty string.

This option is mutually exclusive with default_value.

Choices:

  • no

  • yes ← (default)

leading_separator

boolean

added in 2.11 of ansible.builtin

Use in conjunction with keyed_groups.

By default, a keyed group that does not have a prefix or a separator provided will have a name that starts with an underscore.

This is because the default prefix is “” and the default separator is “_”.

Set this option to False to omit the leading underscore (or other separator) if no prefix is given.

If the group name is derived from a mapping the separator is still used to concatenate the items.

To not use a separator in the group name at all, set the separator for the keyed group to an empty string instead.

Choices:

  • no

  • yes ← (default)

plugin

string / required

token that ensures this is a source file for the docker_machine plugin.

Choices:

  • docker_machine

  • community.docker.docker_machine

running_required

boolean

When true, hosts which Docker Machine indicates are in a state other than running will be skipped.

Choices:

  • no

  • yes ← (default)

strict

boolean

If yes make invalid entries a fatal error, otherwise skip and continue.

Since it is possible to use facts in the expressions they might not always be available and we ignore those errors by default.

Choices:

  • no ← (default)

  • yes

use_extra_vars

boolean

added in 2.11 of ansible.builtin

Merge extra vars into the available variables for composition (highest precedence).

Choices:

  • no ← (default)

  • yes

Configuration:

  • INI entry:

    [inventory_plugins]
    use_extra_vars = no
    
  • Environment variable: ANSIBLE_INVENTORY_USE_EXTRA_VARS

verbose_output

boolean

When true, include all available nodes metadata (for exmaple Image, Region, Size) as a JSON object named docker_machine_node_attributes.

Choices:

  • no

  • yes ← (default)

Examples

# Minimal example
plugin: community.docker.docker_machine

# Example using constructed features to create a group per Docker Machine driver
# (https://docs.docker.com/machine/drivers/), for example:
#   $ docker-machine create --driver digitalocean ... mymachine
#   $ ansible-inventory -i ./path/to/docker-machine.yml --host=mymachine
#   {
#     ...
#     "digitalocean": {
#       "hosts": [
#           "mymachine"
#       ]
#     ...
#   }
strict: no
keyed_groups:
  - separator: ''
    key: docker_machine_node_attributes.DriverName

# Example grouping hosts by Digital Machine tag
strict: no
keyed_groups:
  - prefix: tag
    key: 'dm_tags'

# Example using compose to override the default SSH behaviour of asking the user to accept the remote host key
compose:
  ansible_ssh_common_args: '"-o StrictHostKeyChecking=accept-new"'

Authors

  • Ximon Eighteen (@ximon18)

Hint

Configuration entries for each entry type have a low to high priority order. For example, a variable that is lower in the list will override a variable that is higher up.