Collection version 1.3.0
- Docker Run Ansible Playbook Ubuntu
- Docker Run Ansible Playbook From Python
- Docker Install Ansible Playbook
- Docker Run Ansible Playbook Commands
Ansible Playbooks and Ad Hoc Commands. Ad hoc commands can run a single, simple task against a set of targeted hosts as a one-time command. The real power of Ansible, however, is in learning how to use playbooks to run multiple, complex tasks against a set of targeted hosts in an easily repeatable manner.
Plugin Index¶
- This role also uses Ansible tags. Run your playbook with the -list-tasks flag for more information. This playbook uses Kitchen for CI and local testing. Ruby; Bundler; Docker; Make; Running the tests. Ensure you have checked out this repository to elasticsearch, not ansible-elasticsearch.
- Ansible AWX is free and open source version Red Hat Ansible Tower. It provides a Graphical user interface, Rest API and Ansible task engine. In this article we will through some lights on the basic usage of Ansible AWX GUI and how we can run and schedule Ansible Playbooks using this tool.
These are the plugins in the community.docker collection
Connection Plugins¶
docker – Run tasks in docker containers
docker_api – Run tasks in docker containers
Inventory Plugins¶
docker_containers – Ansible dynamic inventory plugin for Docker containers.
docker_machine – Docker Machine inventory source
docker_swarm – Ansible dynamic inventory plugin for Docker swarm nodes.
Modules¶
current_container_facts – Return facts about whether the module runs in a Docker container
docker_compose – Manage multi-container Docker applications with Docker Compose.
docker_config – Manage docker configs.
docker_container – manage docker containers
docker_container_info – Retrieves facts about docker container
docker_host_info – Retrieves facts about docker host and lists of objects of the services.
docker_image – Manage docker images.
docker_image_info – Inspect docker images
docker_image_load – Load docker image(s) from archives
docker_login – Log into a Docker registry.
docker_network – Manage Docker networks
docker_network_info – Retrieves facts about docker network
docker_node – Manage Docker Swarm node
docker_node_info – Retrieves facts about docker swarm node from Swarm Manager
docker_plugin – Manage Docker plugins
docker_prune – Allows to prune various docker objects
docker_secret – Manage docker secrets.
docker_stack – docker stack module
docker_stack_info – Return information on a docker stack
docker_stack_task_info – Return information of the tasks on a docker stack
docker_swarm – Manage Swarm cluster
docker_swarm_info – Retrieves facts about Docker Swarm cluster.
docker_swarm_service – docker swarm service
docker_swarm_service_info – Retrieves information about docker services from a Swarm Manager
docker_volume – Manage Docker volumes
docker_volume_info – Retrieve facts about Docker volumes
See also
List of collections with docs hosted here.
The community.docker collection offers several modules and plugins for orchestrating Docker containers and Docker Swarm.
Most of the modules and plugins in community.docker require the Docker SDK for Python. The SDK needs to be installed on the machines where the modules and plugins are executed, and for the Python version(s) with which the modules and plugins are executed. You can use the community.general.python_requirements_info module to make sure that the Docker SDK for Python is installed on the correct machine and for the Python version used by Ansible.
Note that plugins (inventory plugins and connection plugins) are always executed in the context of Ansible itself. If you use a plugin that requires the Docker SDK for Python, you need to install it on the machine running ansible
or ansible-playbook
and for the same Python interpreter used by Ansible. To see which Python is used, run ansible--version
.
You can install the Docker SDK for Python for Python 2.7 or Python 3 as follows:
For Python 2.6, you need a version before 2.0. For these versions, the SDK was called docker-py
, so you need to install it as follows:
Please install only one of docker
or docker-py
. Installing both will result in a broken installation. If this happens, Ansible will detect it and inform you about it. If that happens, you must uninstall both and reinstall the correct version.
If in doubt, always install docker
and never docker-py
.
You can connect to a local or remote API using parameters passed to each task or by setting environment variables. The order of precedence is command line parameters and then environment variables. If neither a command line option nor an environment variable is found, Ansible uses the default value provided under Parameters.
Parameters¶
Most plugins and modules can be configured by the following parameters:
The URL or Unix socket path used to connect to the Docker API. Defaults to unix://var/run/docker.sock
. To connect to a remote host, provide the TCP connection string (for example: tcp://192.0.2.23:2376
). If TLS is used to encrypt the connection to the API, then the module will automatically replace ‘tcp’ in the connection URL with ‘https’.
The version of the Docker API running on the Docker Host. Defaults to the latest version of the API supported by the Docker SDK for Python installed.
The maximum amount of time in seconds to wait on a response from the API. Defaults to 60 seconds.
Secure the connection to the API by using TLS without verifying the authenticity of the Docker host server. Defaults to false
.
Secure the connection to the API by using TLS and verifying the authenticity of the Docker host server. Default is false
.
Use a CA certificate when performing server verification by providing the path to a CA certificate file.
Path to the client’s TLS certificate file.
Path to the client’s TLS key file.
When verifying the authenticity of the Docker Host server, provide the expected name of the server. Defaults to localhost
.
Provide a valid SSL version number. The default value is determined by the Docker SDK for Python.
Environment variables¶
You can also control how the plugins and modules connect to the Docker API by setting the following environment variables.
For plugins, they have to be set for the environment Ansible itself runs in. For modules, they have to be set for the environment the modules are executed in. For modules running on remote machines, the environment variables have to be set on that machine for the user used to execute the modules with.
The URL or Unix socket path used to connect to the Docker API.
The version of the Docker API running on the Docker Host. Defaults to the latest version of the API supportedby docker-py.
The maximum amount of time in seconds to wait on a response from the API.
Path to the directory containing the client certificate, client key and CA certificate.
Provide a valid SSL version number.
Secure the connection to the API by using TLS without verifying the authenticity of the Docker Host.
Secure the connection to the API by using TLS and verify the authenticity of the Docker Host.
For working with a plain Docker daemon, that is without Swarm, there are connection plugins, an inventory plugin, and several modules available:
The community.docker.docker connection plugin uses the Docker CLI utility to connect to Docker containers and execute modules in them. It essentially wraps dockerexec
and dockercp
. This connection plugin is supported by the ansible.posix.synchronize module.
The community.docker.docker_api connection plugin talks directly to the Docker daemon to connect to Docker containers and execute modules in them.
The community.docker.docker_containers inventory plugin allows you to dynamically add Docker containers from a Docker Daemon to your Ansible inventory. See Working with dynamic inventory for details on dynamic inventories.
The docker inventory script is deprecated. Please use the inventory plugin instead. The inventory plugin has several compatibility options. If you need to collect Docker containers from multiple Docker daemons, you need to add every Docker daemon as an individual inventory source.
The community.docker.docker_host_info module allows you to retrieve information on a Docker daemon, such as all containers, images, volumes, networks and so on.
The community.docker.docker_login module allows you to log in and out of a remote registry, such as Docker Hub or a private registry. It provides similar functionality to the dockerlogin
and dockerlogout
CLI commands.
The community.docker.docker_prune module allows you to prune no longer needed containers, images, volumes and so on. It provides similar functionality to the dockerprune
CLI command.
The community.docker.docker_image module provides full control over images, including: build, pull, push, tag and remove.
The community.docker.docker_image_info module allows you to list and inspect images.
The community.docker.docker_network module provides full control over Docker networks.
The community.docker.docker_network_info module allows you to inspect Docker networks.
The community.docker.docker_volume_info module provides full control over Docker volumes.
The community.docker.docker_volume module allows you to inspect Docker volumes.
The community.docker.docker_container module manages the container lifecycle by providing the ability to create, update, stop, start and destroy a Docker container.
The community.docker.docker_container_info module allows you to inspect a Docker container.
The community.docker.docker_compose moduleallows you to use your existing Docker compose files to orchestrate containers on a single Docker daemon or on Swarm.Supports compose versions 1 and 2.
Next to Docker SDK for Python, you need to install docker-compose on the remote machines to use the module.
The community.docker.docker_machine inventory plugin allows you to dynamically add Docker Machine hosts to your Ansible inventory.
The community.docker.docker_stack module module allows you to control Docker stacks. Information on stacks can be retrieved by the community.docker.docker_stack_info module, and information on stack tasks can be retrieved by the community.docker.docker_stack_task_info module.
The community.docker collection provides multiple plugins and modules for managing Docker Swarms.
Swarm management¶
One inventory plugin and several modules are provided to manage Docker Swarms:
Docker Run Ansible Playbook Ubuntu
The community.docker.docker_swarm inventory plugin allows you to dynamically add all Docker Swarm nodes to your Ansible inventory.
The community.docker.docker_swarm module allows you to globally configure Docker Swarm manager nodes to join and leave swarms, and to change the Docker Swarm configuration.
The community.docker.docker_swarm_info module allows you to retrieve information on Docker Swarm.
The community.docker.docker_node module allows you to manage Docker Swarm nodes.
The community.docker.docker_node_info module allows you to retrieve information on Docker Swarm nodes.
Configuration management¶
The community.docker collection offers modules to manage Docker Swarm configurations and secrets:
Docker Run Ansible Playbook From Python
Docker Install Ansible Playbook
The community.docker.docker_config module allows you to create and modify Docker Swarm configs.
The community.docker.docker_secret module allows you to create and modify Docker Swarm secrets.
Swarm services¶
Docker Swarm services can be created and updated with the community.docker.docker_swarm_service module, and information on them can be queried by the community.docker.docker_swarm_service_info module.
Docker Run Ansible Playbook Commands
Still using Dockerfile to build images? Check out ansible-bender, and start building images from your Ansible playbooks.
Use Ansible Operator to launch your docker-compose file on OpenShift. Go from an app on your laptop to a fully scalable app in the cloud with Kubernetes in just a few moments.