〇インストール方法
1.下準備
~/.ansible.cfgに以下の内容を設定します
[ssh_connection]
pipelining=True
[defaults]
host_key_checking = False
2. インストール対象ホストのユーザやパスワードを環境に合わせてinventoryファイルに記入します
inventory例
[node-exporter]
192.168.1.106
[all:vars]
ansible_ssh_port=22
ansible_ssh_user=vagrant
ansible_ssh_pass=vagrant
ansible_sudo_pass=vagrant
3.inventory node-exporter-deb.ymlを準備し、以下のコマンドを実行します。
ansible-playbook -i inventory node-exporter-deb.yml
node-exporter-deb.yml
- hosts: node-exporter
vars:
- password: prometheus
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-amd64.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-amd64.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-amd64/node_exporter
become: true
- name: clean up
file:
state: absent
path: /opt/prometheus/node_exporter-0.16.0.linux-amd64.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-amd64
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
0 件のコメント:
コメントを投稿