CoreOS is awesome, so is Ansible. However, running Ansible tasks on CoreOS is a pain, mostly due to lack of Python, which is not there for a good reason. CoreOS toolbox is a small script that uses containers to let you bring in your favorite tools into CoreOS. This is small-sized alternative toolbox image built specifically for running Ansible tasks on CoreOS machines, it's based on Alpine Linux and has Python, pip and Ansible preinstalled, and under 70 MB in size unpacked.
This repository was created with hopes of possibility to easily execute ansible commands within toolbox with full access to CoreOS resources. The general idea is great, but fails in practice when you need to do anything outside pure Python, for example, control etcd or fleet, or systemd, or something else that lives on the host. You can provide access to many things by mounting executables and dependencies as volumes, but this starts to feel hacky very quickly and sometimes doesn't work.
My advice is to setup Python on the host if dealing with similar scenarios. Otherwise, using Python withing toolbox is a neat way to do stuff, highly recommended.
Toolbox setup and installation is covered in CoreOS documentation, in a nutshell, to make it the default toolbox image you must specify ianbytchek/coreos-ansible-toolbox
image in ~/.toolboxrc
parameters manually or via cloud-config.
TOOLBOX_DOCKER_IMAGE=ianbytchek/coreos-ansible-toolbox
TOOLBOX_USER=root
Vincent Ambo has a great article on provisioning CoreOS with Ansible. Besides configuring ~/.toolboxrc
you'll also need to create /opt/bin/python
and /opt/bin/pip
and set ansible_python_interpreter
inventory variable to /opt/bin/python
.
# Use --quiet option to prevent nspawn printing useless messages every time we call `python` and `pip`.
sudo mkdir --parents '/opt/bin'
sudo tee '/opt/bin/python' > /dev/null <<-'EOL'
#!/bin/bash
toolbox --quiet --bind=/home:/home python "$@"
EOL
sudo chmod +x '/opt/bin/python'
sudo tee '/opt/bin/pip' > /dev/null <<-'EOL'
#!/bin/bash
toolbox --quiet --bind=/home:/home pip "$@"
EOL
sudo chmod +x '/opt/bin/pip'