Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,10 @@ configuration-management/.DS_Store
configuration-management/.DS_Store

conf.yaml

# Ansible
.ansible

# PR summaries (may contain sensitive info)
PR_SUMMARY.md
**/PR_SUMMARY.md
43 changes: 41 additions & 2 deletions configuration-management/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,44 @@
# Configuration Management

Sample applications regarding the configuration of Netdata Agents programmatically.
Sample applications regarding the configuration of Netdata Agents programmatically.

Examples: Hashicorp Consul, Ansible, etc.
## Ansible

### Ansible Quickstart

The [`ansible-quickstart`](ansible-quickstart/) directory contains a ready-to-use Ansible playbook for installing, configuring, and claiming Netdata agents to Netdata Cloud.

#### Usage

1. **Configure inventory**: Edit `ansible-quickstart/hosts` file with your target servers
2. **Set variables**: Update `ansible-quickstart/vars/main.yml` with your Netdata Cloud credentials
3. **Run playbook**: Execute the main playbook

```bash
cd ansible-quickstart
ansible-playbook -i hosts playbook.yml
```

#### Configuration

**Required Variables (vars/main.yml)**
- `claim_token`: Your Netdata Cloud claim token
- `claim_rooms`: Your Netdata Cloud room ID
- `claim_url`: Netdata Cloud URL (default: https://app.netdata.cloud)

**Optional Variables**
- `reclaim`: Force re-claiming of nodes (default: false)
- `dbengine_multihost_disk_space`: Database size in MiB (default: 2048)
- `web_mode`: Agent web server mode (default: none)
- `netdata_channel`: Installation channel - 'stable' or 'nightly' (default: stable)
- `netdata_auto_updates`: Enable automatic updates (default: false)

#### Tasks Performed

1. **Install**: Downloads and installs Netdata using the official kickstart script
2. **Configure**: Applies custom configuration template
3. **Claim**: Claims the node to Netdata Cloud (or re-claims if specified)

### Other Examples

Examples: Hashicorp Consul, etc.
4 changes: 3 additions & 1 deletion configuration-management/ansible-quickstart/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
See https://github.com/netdata/netdata/tree/master/packaging/installer/methods/ansible.md
# Netdata Ansible Quickstart

For complete usage instructions and configuration options, see the [Configuration Management README](../README.md#ansible).
23 changes: 23 additions & 0 deletions configuration-management/ansible-quickstart/playbook.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
- name: Install and configure Netdata
hosts: all
vars_files:
- vars/main.yml
become: true
become_method: sudo

tasks:
- name: Import installation tasks
ansible.builtin.import_tasks: tasks/install.yml

- name: Import configuration tasks
ansible.builtin.import_tasks: tasks/configure.yml

- name: Import claiming tasks
ansible.builtin.import_tasks: tasks/claim.yml

handlers:
- name: Restart Netdata
ansible.builtin.service:
name: netdata
state: restarted
51 changes: 8 additions & 43 deletions configuration-management/ansible-quickstart/tasks/claim.yml
Original file line number Diff line number Diff line change
@@ -1,45 +1,10 @@
---
- name: Claim the node to Netdata Cloud
hosts: all
vars_files:
- "../vars/main.yml"
# Claiming is now handled directly in the install.yml using kickstart script
# This file is kept for compatibility but may be removed in future versions

- name: Verify Netdata service is running
ansible.builtin.systemd:
name: netdata
state: started
enabled: true
become: true
become_method: sudo

tasks:
- name: Claim to Netdata Cloud
block:

- name: Claim to Netdata Cloud if not already
shell:
cmd: netdata-claim.sh -token={{ claim_token }} -rooms={{ claim_rooms }} -url={{ claim_url }}
creates: /var/lib/netdata/cloud.d/claimed_id
become: yes

when: reclaim == false

- name: Re-claim a node to Netdata Cloud
block:

- name: Ensure `uuidgen` is installed
stat:
path: /usr/bin/uuidgen
register: uuidgen_result

- name: Fail if `uuidgen` is not installed
fail:
msg: The system needs `uuidgen` installed to enable re-claiming.
when: uuidgen_result.stat.exists == false

- name: Reclaim the node with `-id=`
shell: netdata-claim.sh -token={{ claim_token }} -rooms={{ claim_rooms }} -url={{ claim_url }} -id=$(uuidgen)
when: uuidgen_result.stat.exists == true
notify: Restart Netdata
become: yes
when: reclaim == true

handlers:
- name: Restart Netdata
service:
name: netdata
state: restarted
29 changes: 8 additions & 21 deletions configuration-management/ansible-quickstart/tasks/configure.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,10 @@
---
- name: Configure Netdata
hosts: all
vars_files:
- "../vars/main.yml"
- name: Configure Netdata with template
ansible.builtin.template:
src: "{{ playbook_dir }}/templates/netdata.conf.j2"
dest: /etc/netdata/netdata.conf
owner: root
group: root
mode: '0755'
become: true
become_method: sudo

tasks:
- template:
src: ../templates/netdata.conf.j2
dest: /etc/netdata/netdata.conf
owner: root
group: root
mode: u=wrx,g=rx,o=r,+x
notify: Restart Netdata
become: true

handlers:
- name: Restart Netdata
service:
name: netdata
state: restarted
notify: Restart Netdata
64 changes: 47 additions & 17 deletions configuration-management/ansible-quickstart/tasks/install.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,52 @@
---
- name: Install Netdata
hosts: all
vars_files:
- "../vars/main.yml"
- name: Download the Netdata kickstart script
ansible.builtin.get_url:
url: https://get.netdata.cloud/kickstart.sh
dest: /tmp/netdata-kickstart.sh
mode: +x

- name: Check if Netdata is already installed
ansible.builtin.stat:
path: /usr/sbin/netdata
register: netdata_installed
when: reclaim

- name: Install and claim Netdata (new installation)
ansible.builtin.command: >
/tmp/netdata-kickstart.sh
{% if netdata_channel == 'stable' %}--stable-channel{% endif %}
{% if netdata_channel == 'nightly' %}--nightly-channel{% endif %}
--non-interactive
{% if not netdata_auto_updates %}--no-updates{% endif %}
--claim-token {{ claim_token }}
--claim-rooms {{ claim_rooms }}
--claim-url {{ claim_url }}
when: not reclaim or (reclaim and not netdata_installed.stat.exists)
changed_when: true
become: true
become_method: sudo

tasks:
- name: Download the installation script
get_url:
url: https://my-netdata.io/kickstart.sh
dest: ~/kickstart.sh
mode: +x
- name: Uninstall existing Netdata (for clean reclaim)
ansible.builtin.command: /tmp/netdata-kickstart.sh --uninstall --non-interactive
when: reclaim and netdata_installed.stat.exists
changed_when: true
become: true
failed_when: false

- name: Install Netdata
command: ~/kickstart.sh --dont-wait
- name: Fresh install and claim Netdata (after uninstall)
ansible.builtin.command: >
/tmp/netdata-kickstart.sh
{% if netdata_channel == 'stable' %}--stable-channel{% endif %}
{% if netdata_channel == 'nightly' %}--nightly-channel{% endif %}
--non-interactive
{% if not netdata_auto_updates %}--no-updates{% endif %}
--claim-token {{ claim_token }}
--claim-rooms {{ claim_rooms }}
--claim-url {{ claim_url }}
when: reclaim and netdata_installed.stat.exists
changed_when: true
become: true

- name: Cleanup installation script
file:
path: ~/kickstart.sh
state: absent
- name: Cleanup installation script
ansible.builtin.file:
path: /tmp/netdata-kickstart.sh
state: absent
9 changes: 6 additions & 3 deletions configuration-management/ansible-quickstart/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
---
# Tasks file for Netdata

- import_playbook: install.yml
- name: Import installation tasks
ansible.builtin.import_tasks: install.yml

- import_playbook: configure.yml
- name: Import configuration tasks
ansible.builtin.import_tasks: configure.yml

- import_playbook: claim.yml
- name: Import claiming tasks
ansible.builtin.import_tasks: claim.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Netdata configuration

[global]
{% if hostvars[inventory_hostname].hostname %}
hostname = {{ hostvars[inventory_hostname].hostname }}
{% if hostvars[inventory_hostname]['hostname'] is defined and hostvars[inventory_hostname]['hostname'] %}
hostname = {{ hostvars[inventory_hostname]['hostname'] }}
{% endif %}
dbengine multihost disk space = {{ dbengine_multihost_disk_space }}

Expand Down
11 changes: 9 additions & 2 deletions configuration-management/ansible-quickstart/vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,17 @@ reclaim: false
# engine. Value is in MiB. Read more:
# https://learn.netdata.cloud/docs/store/change-metrics-storage
dbengine_multihost_disk_space: 2048

# Set whether to run the Agent web server/dashboard/API, or disable them.
# Because we're connecting this node to Netdata Cloud and will view dashboards
# there, we'll set this to `none` to disable the local dashboard. Set to
# `static-threaded` if you want to keep it running. Read more:
# https://learn.netdata.cloud/docs/configure/secure-nodes
web_mode: none
web_mode: none

# Netdata installation channel: 'stable' or 'nightly' (default: stable)
# Read more: https://learn.netdata.cloud/docs/get-started
netdata_channel: stable

# Enable automatic updates: true or false (default: false for automation)
# When false, adds --no-updates flag to kickstart script
netdata_auto_updates: false