I’ve been going through Ansible training for work, and I want to be able to easily try out some of the playbooks and modules on my Windows 10 box. There’s lots of ways I could go about this, but for me the thing that makes the most sense is to leverage Docker for Windows (DfW) and the magic of containers to be able to get up and running quickly. In this post I will walk through what I did to get started, and why I landed on containers instead of another solution.
At my day job, we are working on building demos for our HPE Synergy system using Ansible for automation. Obviously, in order to run the demos I need something that can run Ansible playbooks and has access to the API endpoint for the OneView Composer that manages the Synergy frame. I’ve used Ansible before for some small projects and in my Deep Dive Terraform course on Pluralsight. In those cases, I was creating a Linux host and having it run the Ansible playbooks on itself, so I didn’t need a traditional controller node. In the case of OneView, I now need a controller node that can reach out to a system and configure it via API calls.
I am also going through Ansible training, and while Red Hat does provide a lab environment, I also want a local instance I can try things out on.
I reviewed my options for a local instance and here’s what I came up with:
- Run a VM locally on Hyper-V: I don’t really want to run a full-blown VM. Plus I would have to download an ISO for a Linux OS and go through the install. No thanks.
- Run a VM in AWS and install Ansible: This could potentially cost some small amount of money, and it also requires me to maintain a remote system, and make sure I have an internet connection whenever I want to try something out.
- Use the Azure Cloud Shell: I LUV the Azure Cloud Shell, like a lot. It comes with all kinds of goodies pre-installed, including Ansible. But again this assumes that I will have an internet connection, and it won’t have access to local resources in my work lab.
- Use a Vagrant Box: This one really appealed to me and I was about to start down this road. But I’ve also been trying to get more comfortable with containers, so if I’m going to use a Vagrantfile to customize a CentOS box, then I might as well use a container instead.
- Use Docker for Windows to run Ansible in a container: This was ultimately the winner for me. I already had DfW installed on my Win 10 laptop. I’m trying to get more into the world of containers. The container will have access to my work lab. And I can share the image with coworkers easily if they want to repeat the demo.
And so DfW FTW as it were!
If you’d like to do the same, first you need to install DfW. You will also need to install the Hyper-V and Containers features in Windows, which DfW will do for you if you haven’t already. Once DfW is installed, go ahead and clone my GitHub repo for this project. You can build the docker image using:
docker build -t centos7-ansible-oneview .
And then spin up a container using:
docker run -it centos7-ansible-oneview /bin/bash
If you happen to be trying to use this for your own OneView and Synergy install, then definitely take a look at the additional requirements HPE has listed on their GitHub repo for Ansible and Terraform. As I work through the demo process, I will try to update this post and the Dockerfile with additional configuration to make the process as seamless as possible.