From 800c97b5e5148b4f6de212d193205dfc329626c0 Mon Sep 17 00:00:00 2001 From: Dale Grant Date: Wed, 22 Sep 2021 18:14:09 +1000 Subject: [PATCH] Allow use with multiple server Trellis --- README.md | 7 ++++++- defaults/main.yml | 4 +++- tasks/main.yml | 11 +++++++---- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 82967ae..7c33bf8 100644 --- a/README.md +++ b/README.md @@ -46,12 +46,13 @@ Install [New Relic PHP agent](https://docs.newrelic.com/docs/agents/php-agent) o ## Role Variables ```yaml -# group_vars//vault.yml +# group_vars//vault.yml or host_vars//vault.yml # This file should be encrypted. See: https://roots.io/trellis/docs/vault/ ########################################################################## # New Relic License Key ## See: https://docs.newrelic.com/docs/accounts-partnerships/accounts/account-setup/license-key +# vault_newrelic_license: false vault_newrelic_license: xxxxxxxxxxx # group_vars//main.yml @@ -105,6 +106,10 @@ Add this role to `requirements.yml`: Run `$ ansible-galaxy install -r requirements.yml` to install this new role. +## Multiple servers + +As an alternative to setting the license key for an environment under `group_vars` you can set it for a single server under `host_vars`. You can explicitly set `false` to skip a group or host, or omit the variable from the vault file. A warning will be shown when setup is skipped. + ## Common Errors ### `vault_newrelic_license` is not defined diff --git a/defaults/main.yml b/defaults/main.yml index 5017084..3317f59 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,7 +1,9 @@ newrelic_package_state: latest +newrelic_license: "{{ vault_newrelic_license | default(false) }}" + newrelic_config_default: - license: "{{ vault_newrelic_license }}" + license: "{{ newrelic_license }}" appname: "{{ wordpress_sites.keys() | first }} {{ env }}" framework: wordpress logfile: /var/log/newrelic/php_agent.log diff --git a/tasks/main.yml b/tasks/main.yml index 3433249..ef199af 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,8 +1,11 @@ --- -- name: Fail if vault_newrelic_license is not defined - fail: - msg: vault_newrelic_license is not defined - when: vault_newrelic_license is not defined +- name: Warn if vault_newrelic_license is not defined + debug: + msg: | + Note: Skipping New Relic tasks. vault_newrelic_license is not set. Make sure this is set in vault.yml. + when: newrelic_license == false - include: install.yml + when: newrelic_license != false - include: ini.yml + when: newrelic_license != false