Zim's Notes

Just work related notes.

Installing Ansible Using Cloud-init

Recently was playing with cloud-init a bit, and it seems like a great and consistent way of setting up Ansible VMs. Here’s an example of creating a virtual machine via Azure portal and installing Ansible at once.

What you need to do is to go to Guest Config tag and add appropriate cloud-config playbook:

Guest Config

In this example I am using following code:

1
2
3
4
5
6
7
#cloud-config
packages:
  - python-pip
runcmd:
  - sudo pip install ansible
  - sudo ansible-galaxy install azure.azure_preview_modules
  - sudo pip install -r ~/.ansible/roles/azure.azure_preview_modules/files/requirements-azure.txt

It can be even shorted if you don’t need Azure preview modules:

1
2
3
4
5
#cloud-config
packages:
  - python-pip
runcmd:
  - sudo pip install ansible[azure]