This is a very rudimentary implementation of an an ansible script to install prometheus on your server and add service discovery
- Create a iam role and give it readonly access
- Create a ec2 instance with ubuntu on your aws account (ensure its has a security group with ports 22,9100,9090,9093 open and also attach a keypair to your instance)
- Add the ip address of your account to the inventory.txt file
- Add the access key and secret key of your iam role to the setup-service-discovery echo command ensure you dont mess with the spacing(VERY IMPORTANT).
- depending on your aws region you can also change it from the setup-service-discovery echo command
- Assuming your pem file from the keypair and inventory files are present in the current directory Finally run the command
ansible-playbook main.yml -i inventory --private-key prometheus.pem
This script is based on this tutorial https://codewizardly.com/prometheus-on-aws-ec2-part1/