〇インストール方法
1.下準備
~/.ansible.cfgに以下の内容を設定します
[ssh_connection]
pipelining=True
[defaults]
host_key_checking = False
2. Prometheus Node Exporterをインストール対象のユーザやパスワードを環境に合わせてinventoryファイルに記入します
inventory例
[node-exporter]
192.168.1.16
[all:vars]
ansible_ssh_port=22
ansible_ssh_user=pi
ansible_ssh_pass=raspberry
ansible_sudo_pass=raspberry
3.inventory node-exporter-deb.ymlを準備し、以下のコマンドを実行します。
archパラメータをRaspberry Pi 3系ならarmv7、Raspberry Pi 1系ならarmv6を指定します
ansible-playbook -i inventory node-exporter.yml
node-exporter.yml
- hosts: node-exporter
vars:
- password: prometheus
- arch: armv7
tasks:
- name: create prometheus group
group:
name: prometheus
become: true
- name: create prometheus user
user:
name: prometheus
group: prometheus
password: "{{ password | password_hash('sha512') }}"
become: true
- name: create prometheus directory
file:
path: /opt/prometheus
state: directory
owner: prometheus
become: true
- name: download prometheus node exporter
get_url:
url: https://github.com/prometheus/node_exporter/releases/download/v0.16.0/node_exporter-0.16.0.linux-{{ arch }}.tar.gz
dest: /opt/prometheus/
become: true
become_user: prometheus
- name: extract prometheus node exporter
unarchive:
remote_src: yes
src: /opt/prometheus/node_exporter-0.16.0.linux-{{ arch }}.tar.gz
dest: /opt/prometheus/
become: true
become_user: prometheus
- name: symlink
file:
path: /bin/node_exporter
state: link
src: /opt/prometheus/node_exporter-0.16.0.linux-{{ arch }}/node_exporter
become: true
- name: clean up
file:
state: absent
path: /opt/prometheus/node_exporter-0.16.0.linux-{{ arch }}.tar.gz
become: yes
become_user: prometheus
- name: setup systemd
blockinfile:
dest: /etc/systemd/system/node-exporter.service
create: yes
block: |
[Unit]
Description=Prometheus Node Exporter
Requires=network.target
[Service]
Restart=always
WorkingDirectory=/opt/prometheus/node_exporter-0.16.0.linux-{{ arch }}
ExecStart=/bin/node_exporter
ExecReload=/bin/kill -HUP $MAINPID
[Install]
WantedBy=multi-user.target
become: true
- name: enable and start node-exporter
systemd:
daemon_reload: yes
enabled: yes
state: started
name: node-exporter.service
become: true
○関連情報
・Ansibleに関する他の記事はこちらを参照してください。
0 件のコメント:
コメントを投稿