community.docker.current_container_facts module – Return facts about whether the module runs in a container

Note

This module is part of the community.docker collection (version 3.4.7).

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.current_container_facts.

New in community.docker 1.1.0

Synopsis

  • Return facts about whether the module runs in a Docker or podman container.

  • This module attempts a best-effort detection. There might be special cases where it does not work; if you encounter one, please file an issue.

Attributes

Attribute

Support

Description

check_mode

Support: full

This action does not modify state.

Can run in check_mode and return changed status prediction without modifying target.

diff_mode

Support: N/A

This action does not modify state.

Will return details on what has changed (or possibly needs changing in check_mode), when in diff mode.

facts

Support: full

Action returns an ansible_facts dictionary that will update existing host facts.

Examples

- name: Get facts on current container
  community.docker.current_container_facts:

- name: Print information on current container when running in a container
  ansible.builtin.debug:
    msg: "Container ID is {{ ansible_module_container_id }}"
  when: ansible_module_running_in_container

Returned Facts

Facts returned by this module are added/updated in the hostvars host facts and can be referenced by name just like any other host fact. They do not need to be registered in order to use them.

Key

Description

ansible_module_container_id

string

The detected container ID.

Contains an empty string if no container was detected.

Returned: always

ansible_module_container_type

string

The detected container environment.

Contains an empty string if no container was detected, or a non-empty string identifying the container environment.

docker indicates that the module ran inside a regular Docker container.

azure_pipelines indicates that the module ran on Azure Pipelines. This seems to no longer be reported.

github_actions indicates that the module ran inside a Docker container on GitHub Actions. It is supported since community.docker 2.4.0.

podman indicates that the module ran inside a regular Podman container. It is supported since community.docker 3.3.0.

Returned: always

Can only return:

  • ""

  • "docker"

  • "azure_pipelines"

  • "github_actions"

  • "podman"

ansible_module_running_in_container

boolean

Whether the module was able to detect that it runs in a container or not.

Returned: always

Authors

  • Felix Fontein (@felixfontein)