LoginSignup
1
0

More than 1 year has passed since last update.

AnsibleでNewRelic Infrastructure Agentを導入する

Posted at

前提

  • ホストはAWS EC2 (Amazon Linux2)
  • NewRelicでAPI Keyを発行済みである

playbookを作成

- hosts: ec2-instance
  become: yes
  environment:
    NEW_RELIC_ACCOUNT_ID: "{{ account_id }}"
    NEW_RELIC_API_KEY: "{{ license_key }}"
  tasks:
  - name: インストール実行シェルの取得
    ansible.builtin.uri:
      url: https://download.newrelic.com/install/newrelic-cli/scripts/install.sh
      return_content: yes
    register: nrinstall
  - name: インストール実行シェルの実行
    ansible.builtin.shell:
      cmd: /usr/local/bin/newrelic install
      stdin: nrinstall.content

上記のplaybookは、以下のコマンドを入力した時と同じ結果が得られるコードとなっている。

curl -Ls https://download.newrelic.com/install/newrelic-cli/scripts/install.sh | bash && sudo NEW_RELIC_API_KEY=NRAK-XXXXXXXXXX NEW_RELIC_ACCOUNT_ID=0000000 /usr/local/bin/newrelic install

ansible.builtin.uriでインストール実行用のシェルスクリプトを取得し、
registerで指定した変数(nrinstall)に取得したコンテンツを格納する。

ansible.builtin.shellのstdinで取得したコンテンツ(シェルスクリプト)を読み込んだ上で、cmdで指定したコマンドを実行する。

以上のような記述方法で、curlでスクリプトを取得 + 取得したコンテンツを読み込んだ上でコマンド実行といった、パイプさせた処理を行うことができる。

Ansible Galaxyを使う

Ansible Galaxyでnewrelic-infraをインストールするRoleがあるのでそっちを使うとはやい

ただし、動作環境によってはエラーが発生することもあるので、playbookを自作するのもアリ。

参考

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0