Skip to content

Instantly share code, notes, and snippets.

@marshyon
Last active October 30, 2022 18:01
Show Gist options
  • Save marshyon/eb0644c0d290dc060fee13851d3fa5a1 to your computer and use it in GitHub Desktop.
Save marshyon/eb0644c0d290dc060fee13851d3fa5a1 to your computer and use it in GitHub Desktop.
running ansible from a container using docker

build the container image with

docker build -t ansible:0.0.1 .

run ansible ping command against hosts defined in an inventory file, noting that

  • the keys file needs to contain id_rsa file with appropriate permissions
  • a known_hosts file needs to be present in the keys folder
#!/usr/bin/env bash


docker run -it --rm \
	-v $(pwd)/keys:/root/.ssh \
	-v $(pwd)/k3s-ansible:/root/k3s-ansible \
	ansible:0.0.1 \
	ansible all -i /root/ansible/inventory/my-cluster/hosts.ini -m ping
FROM ubuntu:22.04
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && \
apt-get install -y ansible && \
mkdir /root/ansible
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment