diff --git a/inventory/host_vars/_example.com/secrets.example.yml b/inventory/host_vars/_example.com/secrets.example.yml index 47222ba67..4d833781f 100644 --- a/inventory/host_vars/_example.com/secrets.example.yml +++ b/inventory/host_vars/_example.com/secrets.example.yml @@ -75,8 +75,16 @@ smtp_password: #geocoder_service: mapbox #geocoder_timeout: 7 -# New relic settings -# see: https://one.eu.newrelic.com/admin-portal/, Administration > API keys to get the license key -# new_relic_agent_enabled: true -# new_relic_app_name: "Open Food Network" -# new_relic_license_key: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" +## New Relic settings +# +# See: https://one.eu.newrelic.com/admin-portal/ > API keys +# +# Infrastructure agent: +#new_relic_api_key: "NRAK-XXXXXXXXXXXXXXXXXXXXXXXXXXX" +#new_relic_account_id: "0000000" +#new_relic_region: "EU" +# +# Rails APM: +#new_relic_agent_enabled: true +#new_relic_app_name: "Open Food Network" +#new_relic_license_key: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" diff --git a/playbooks/provision.yml b/playbooks/provision.yml index 5e5727ff4..3036debc7 100644 --- a/playbooks/provision.yml +++ b/playbooks/provision.yml @@ -105,6 +105,11 @@ become: yes tags: logrotate + - role: newrelic + become: yes + when: new_relic_api_key is defined + tags: newrelic + tasks: - name: Fix Ruby # noqa 301 command: diff --git a/roles/newrelic/handlers/main.yml b/roles/newrelic/handlers/main.yml new file mode 100644 index 000000000..e2bca88e5 --- /dev/null +++ b/roles/newrelic/handlers/main.yml @@ -0,0 +1,4 @@ +- name: restart newrelic_infra + service: + name: "newrelic-infra.service" + state: restarted diff --git a/roles/newrelic/tasks/main.yml b/roles/newrelic/tasks/main.yml new file mode 100644 index 000000000..c81017593 --- /dev/null +++ b/roles/newrelic/tasks/main.yml @@ -0,0 +1,29 @@ +--- + +- name: Download installer + ansible.builtin.get_url: + url: "https://download.newrelic.com/install/newrelic-cli/scripts/install.sh" + dest: "/tmp/new-relic-install.sh" + mode: "777" + +- name: Install New Relic command + ansible.builtin.command: "/tmp/new-relic-install.sh" + args: + creates: /usr/local/bin/newrelic + +- name: Install New Relic agent + command: /usr/local/bin/newrelic install -y + environment: + NEW_RELIC_API_KEY: "{{ new_relic_api_key }}" + NEW_RELIC_ACCOUNT_ID: "{{ new_relic_account_id }}" + NEW_RELIC_REGION: "{{ new_relic_region }}" + args: + creates: /usr/bin/newrelic-infra + +- name: Use our standard names in dashboard + lineinfile: + name: "/etc/newrelic-infra.yml" + line: "display_name: {{ host_id }}" + regex: "^display_name:" + state: present + notify: restart newrelic_infra