Chapter by chapter I provide my version of prerequisites and supplementary material, so that one can follow along with the examples in the Ansible for DevOps book.
Chapter 2 uses the Tart provider for Vagrant. Thus, a separate Vagrantfile is provided.
At the time of writing, the Tart provider did not support multiple machines. Thus, starting with chapter 3, the Vagrant stack uses the Docker provider instead. The stack is configured by a Vagrantfile, an ansible.cfg and a hosts.ini file in the each directory subdirectory.
The Dockerfiles located in this directory provide Ubuntu, Fedora and Rocky Linux servers with SSH access and systemd.
The key pair id_ecdsa* was generated with the following command line without a
password (-N ""):
ssh-keygen -N "" -f ./id_ecdsa -t ecdsa -b 521 -C vagrant@localhostIt is automatically registered in the Docker container as the SSH key for the
vagrant user and is used by Ansible.
The host key is also predefined, so it remains the same even after changes to the Dockerfile.
For this documentation I assume that you are in the chapter 3 directory.
Before the first start, I recommend building the Docker image. This makes Vagrant start faster.
docker build -t ansible-target -f Dockerfile.Fedora .Then start the stack:
vagrant upEnsure that the stack is running properly:
vagrant statusThe three containers app1, app2, and db1 should be shown with the status
running (docker).
docker psThe containers should be displayed with the status Up. The command that is
running corresponds to the systemd init process. Under Fedora, /usr/sbin/init
is shown, and under Ubuntu, /lib/systemd/systemd.
Next, the SSH host keys for the forwarded ports must be added to your own
~/.ssh/known_hosts file:
ssh -i ./ssh_user_key/id_ecdsa vagrant@localhost -p 2223 # app1
ssh -i ./ssh_user_key/id_ecdsa vagrant@localhost -p 2224 # app2
ssh -i ./ssh_user_key/id_ecdsa vagrant@localhost -p 2225 # db1After that, the host mapping can be verified in Ansible:
ansible multi -a "hostname"Expected output:
app2 | CHANGED | rc=0 >>
app2
app1 | CHANGED | rc=0 >>
app1
db1 | CHANGED | rc=0 >>
db1
Stop the stack:
vagrant haltDestroy the stack:
vagrant destroy -fThe -f flag skips the confirmation prompt before deletion.
This project uses code, documentation and ideas generated with the assistance of large language models.
J. Geerling, Ansible for DevOps, 2nd ed. Leanpub, 2023. Accessed: Apr. 20, 2025. [Online]. Available: https://www.ansiblefordevops.com/
J. Geerling and GitHub Contributors, “geerlingguy/ansible-for-devops: Ansible for DevOps examples.” Accessed: May 01, 2025. [Online]. Available: https://github.com/geerlingguy/ansible-for-devops