diff --git a/.gitignore b/.gitignore index 6a4f0b6..326cb6a 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/configuration-management/README.md b/configuration-management/README.md index 33fe1e2..58fb4cf 100644 --- a/configuration-management/README.md +++ b/configuration-management/README.md @@ -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. \ No newline at end of file +## 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. \ No newline at end of file diff --git a/configuration-management/ansible-quickstart/README.md b/configuration-management/ansible-quickstart/README.md index 23179a0..688c1c9 100644 --- a/configuration-management/ansible-quickstart/README.md +++ b/configuration-management/ansible-quickstart/README.md @@ -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). diff --git a/configuration-management/ansible-quickstart/playbook.yml b/configuration-management/ansible-quickstart/playbook.yml new file mode 100644 index 0000000..ece5b03 --- /dev/null +++ b/configuration-management/ansible-quickstart/playbook.yml @@ -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 diff --git a/configuration-management/ansible-quickstart/tasks/claim.yml b/configuration-management/ansible-quickstart/tasks/claim.yml index 0726f75..522e2bf 100644 --- a/configuration-management/ansible-quickstart/tasks/claim.yml +++ b/configuration-management/ansible-quickstart/tasks/claim.yml @@ -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 diff --git a/configuration-management/ansible-quickstart/tasks/configure.yml b/configuration-management/ansible-quickstart/tasks/configure.yml index 9c263a4..61569a2 100644 --- a/configuration-management/ansible-quickstart/tasks/configure.yml +++ b/configuration-management/ansible-quickstart/tasks/configure.yml @@ -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 \ No newline at end of file + notify: Restart Netdata diff --git a/configuration-management/ansible-quickstart/tasks/install.yml b/configuration-management/ansible-quickstart/tasks/install.yml index 18aa90c..05399a6 100644 --- a/configuration-management/ansible-quickstart/tasks/install.yml +++ b/configuration-management/ansible-quickstart/tasks/install.yml @@ -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 \ No newline at end of file +- name: Cleanup installation script + ansible.builtin.file: + path: /tmp/netdata-kickstart.sh + state: absent diff --git a/configuration-management/ansible-quickstart/tasks/main.yml b/configuration-management/ansible-quickstart/tasks/main.yml index 46d7102..bfee734 100644 --- a/configuration-management/ansible-quickstart/tasks/main.yml +++ b/configuration-management/ansible-quickstart/tasks/main.yml @@ -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 \ No newline at end of file +- name: Import claiming tasks + ansible.builtin.import_tasks: claim.yml diff --git a/configuration-management/ansible-quickstart/templates/netdata.conf.j2 b/configuration-management/ansible-quickstart/templates/netdata.conf.j2 index 445652c..acb113f 100644 --- a/configuration-management/ansible-quickstart/templates/netdata.conf.j2 +++ b/configuration-management/ansible-quickstart/templates/netdata.conf.j2 @@ -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 }} diff --git a/configuration-management/ansible-quickstart/vars/main.yml b/configuration-management/ansible-quickstart/vars/main.yml index 781e9d6..02c38fe 100644 --- a/configuration-management/ansible-quickstart/vars/main.yml +++ b/configuration-management/ansible-quickstart/vars/main.yml @@ -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 \ No newline at end of file +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