I started an Ubuntu EC2 the other day hoping to run Ansible on it and was surprised that Python was not installed. A requirement for Ansible to run on target machines is to have a modern version of Python.
You can just run sudo apt install python but this is not ideal if you need to install python on let’s say 200 Ubuntu Servers.
The raw module to the rescue
Before writing the playbook, you will need to make minor changes to how Ansible connects to remote hosts.
Create a new file in your current directory and call it
ansible.cfg. This file will override settings in the default
inventory = hosts
remote_user = ubuntu
# Use the below if you’re connecting for the first time
host_key_checking = False
# Location of your .pem you got from AWS
private_key_file = ~/.ssh/yourkey.pem
Now create a
22.214.171.124 # This is a sample IP address. Use your IP.
The playbook using the raw module
This playbook will install python on the target host Ubuntu EC2 server:
- hosts: ubuntu_server
- name: 'install python'
raw: 'sudo apt -y install python'