Skip to content

Install apm/php recipe should allow running as root  #1076

Open
@tcarreira

Description

Description

When installing apm/php with root, the logs show something like

This installation recipe for the New Relic PHP agent must be run under sudo.

Steps to Reproduce

Run ansible-playbook as root, with the playbook documented here:
https://github.com/newrelic/ansible-install?tab=readme-ov-file#getting-started

sudo su -
# ansible-playbook playbook.yaml
- name: Install New Relic
  hosts: localhost
  roles:
    - role: newrelic.newrelic_install
      vars:
        targets:
          - apm-php
        tags:
          foo: bar
  environment:
    NEW_RELIC_API_KEY: <API key>
    NEW_RELIC_ACCOUNT_ID: <Account ID>
    NEW_RELIC_REGION: <Region>

Expected Behavior

TASK [newrelic.newrelic_install : Report complete installs] ********************
ok: [localhost] => {
    "msg": {
        "node": "nodename",
        "status": "COMPLETE",
        "summary": [
            "  Installation Summary",
            "",
            "  ✔  PHP Agent  (installed)  ",
            "",
            "  View your data at the link below:",
            "  ⮕  https://onenr.io/xxxxxxxxxxx",
            "",
            "  --------------------"
        ]
    }
}

Relevant Logs / Console output

TASK [newrelic.newrelic_install : Report incomplete installs] ****************************
ok: [localhost] => {
    "msg": {
        "node": "nodename",
        "status": "INCOMPLETE",
        "summary": [
            "  Installation Summary",
            "",
            "  ⊘  PHP Agent  (unsupported)  ",
            "",
            "  Installation was successful overall, however, one or more installations could not be completed.",
            "  Follow the instructions at the URL below to complete the installation process. ",
            "",
            "  ⮕  https://onenr.io/xxxxxxxx",
            "",
            "  --------------------",
            "",
            "",
            "We encountered an issue during the installation: one or more selected recipes could not be installed.",
            "If this problem persists, visit the documentation and support page for additional help here at https://docs.newrelic.com/docs/infrastructure/install-infrastructure-agent/get-started/requirements-infrastructure-agent/"
        ]
    }
}

also, from .newrelic/newrelic-cli.log:

...
Finished matching recipe php-agent-installer to running processes, found 8 matches.
This installation recipe for the New Relic PHP agent must be run under sudo.
recipe php-agent-installer failed script evaluation exit status 3: This installation recipe for the New Relic PHP agent must be run under sudo.
ScriptEvaluation for recipe:php-agent-installer completed in 7ms with status:
...

Your Environment

  • Operating System and version: ubuntu 22.04
  • user: root
  • cloud-init on aws (user: root)

Additional context

This is caused by a specific test for SUDO_USER env variable instead of checking for root permissions:

if [ -z "$SUDO_USER" ]; then

Possible solution for this bug:

if running with root, inject SUDO_USER=root

Workaround for this on ansible is documented here: newrelic/ansible-install#82 (comment)

Other reports for this bug:

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions