Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mefengl/ansible-docker-compose
A "hello world" example of using Ansible with Docker Compose.
https://github.com/mefengl/ansible-docker-compose
Last synced: 8 days ago
JSON representation
A "hello world" example of using Ansible with Docker Compose.
- Host: GitHub
- URL: https://github.com/mefengl/ansible-docker-compose
- Owner: mefengl
- Created: 2023-08-31T08:12:45.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2023-09-01T06:26:12.000Z (about 1 year ago)
- Last Synced: 2024-10-16T21:12:31.522Z (22 days ago)
- Language: Dockerfile
- Size: 2.93 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Ansible-Docker-Compose Example
This repository contains a simple example that demonstrates how to set up an Ansible control node and a managed node using Docker Compose. The Ansible control node runs a "Hello, World!" playbook on the managed node.
## Prerequisites
- Docker
- Docker Compose## Quick Start
### Clone the Repository
Clone this repository to your local machine.
```bash
git clone https://github.com/mefengl/ansible-docker-compose.git
```Navigate to the project directory.
```bash
cd ansible-docker-compose
```### Build and Run Docker Containers
Run the following commands to build and start the Docker containers.
```bash
docker-compose build
docker-compose up -d
```### Get Managed Node IP
Run this command to get the IP address of the managed node.
```bash
docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $(docker ps -q --filter "name=ansible_managed")
```Note down the IP address for the next step.
### Run Ansible Playbook
1. Connect to the Ansible control node:
```bash
docker exec -it $(docker ps -q --filter "name=ansible_control") /bin/bash
```2. Create an inventory file (`hosts.ini`) with the IP address obtained in the previous step and specify the local connection plugin:
```bash
echo -e "[managed]\n ansible_connection=local" | tee hosts.ini
```Replace `` with the actual IP address.
3. Run the Ansible playbook:
```bash
ansible-playbook -i hosts.ini /ansible/hello-world.yml -u root
```## Expected Output
You should see the "Hello, World!" message output from the Ansible playbook, indicating it ran successfully on the managed node.