This creates a docker image of Ansible. The installation steps are taken from the Ansible documentation https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html using pipx. The container uses the latest version of python and ansible-core
docker build . -t ansible
docker run -it ansible
If you need to mount a virtual volume, to pass access to a file.pem for example, use a syntax like this:
docker run -it -v ~/my-local-configs/:/configs/ ansible
This uses the newrelic_install
ansible role from this source https://github.com/newrelic/ansible-install
Import the newrelic galaxy collections
ansible-galaxy collection install ansible.windows ansible.utils
ansible-galaxy install newrelic.newrelic_install
Create a hosts INI file to define the various instances to install and how to connect to them, for example:
1.2.3.1 ansible_connection=ssh ansible_user=ec2-user ansible_ssh_private_key_file=/path/to/file.pem
1.2.3.2 ansible_connection=ssh ansible_user=ec2-user ansible_ssh_private_key_file=/path/to/file.pem
1.2.3.3 ansible_connection=ssh ansible_user=ec2-user ansible_ssh_private_key_file=/path/to/file.pem
Create a playbook.yaml file such as this:
- name: Install New Relic Infra+Logs
hosts: all
roles:
- role: newrelic.newrelic_install
vars:
targets:
- infrastructure
- logs
tags:
foo: bar
foo2: bar2
environment:
NEW_RELIC_API_KEY: <NRAK-... API key>
NEW_RELIC_ACCOUNT_ID: <Account ID>
NEW_RELIC_REGION: <Region US or EU>
Then run the following command. Note this disables the known_hosts check. You can remove the variable ANSIBLE_HOST_KEY_CHECKING=false
if you manage the known hosts separately.
ANSIBLE_HOST_KEY_CHECKING=false ansible-playbook -i hosts playbook.yaml