Skip to content

Instantly share code, notes, and snippets.

@mdfranz
Created January 5, 2025 17:27
Show Gist options
  • Save mdfranz/54278944ac6371312c0f10017490d331 to your computer and use it in GitHub Desktop.
Save mdfranz/54278944ac6371312c0f10017490d331 to your computer and use it in GitHub Desktop.
Janky Ansible Vector install

base.yaml

---
- hosts: all 
  tasks:
    - name: Set authorized key taken from file
      authorized_key:
        user: "{{ansible_user_id}}"
        state: present
        key: "{{ lookup('file', '/home/mfranz/.ssh/id_rsa.pub') }}"
    - name: Copy vector installation script 
      ansible.builtin.copy:
        src: vector-install.sh
        dest: /tmp
        mode: '0755'
    - name: Install vector with easy script
      ansible.builtin.shell: /tmp/vector-install.sh
    - name: Install packages  
      ansible.builtin.package:
        name:
          - mosh
          - vector
        state: latest
      become: true
    - name: Copy vector configuration
      ansible.builtin.copy:
        src: vector.yaml
        dest: /etc/vector/vector.yaml
      become: true
    - name: Restart vector
      ansible.builtin.service:
        name: vector
        state: restarted
      become: true

Used ansible-playbook vector-update.yml -i inventory -l pi -u pi -vv --ask-become-pass or ansible-playbook base.yml -i inventory -l clickhouse-pn50 -u ubuntu -k --step -vvv

@bdmorin
Copy link

bdmorin commented Jan 5, 2025

---
- name: Install and configure Vector Observability
  hosts: all
  become: true
  vars:
    vector_user: "{{ ansible_user_id }}"
    vector_config_src: vector.yaml
    vector_config_dest: /etc/vector/vector.yaml
    vector_install_script: /tmp/vector-install.sh
    required_packages:
      - mosh
      - vector
  tasks:
    - name: Ensure the user has the authorized key
      authorized_key:
        user: "{{ vector_user }}"
        state: present
        key: "{{ lookup('file', '/home/{{ vector_user }}/.ssh/id_rsa.pub') }}"

    - name: Copy Vector installation script
      copy:
        src: vector-install.sh
        dest: "{{ vector_install_script }}"
        mode: '0755'

    - name: Install Vector using the installation script
      shell: "{{ vector_install_script }}"
      args:
        creates: /usr/bin/vector  # Prevents re-execution if already installed

    - name: Install required packages
      package:
        name: "{{ required_packages }}"
        state: latest

    - name: Deploy Vector configuration
      copy:
        src: "{{ vector_config_src }}"
        dest: "{{ vector_config_dest }}"
        owner: root
        group: root
        mode: '0644'
      notify: Restart Vector

  handlers:
    - name: Restart Vector
      service:
        name: vector
        state: restarted

Break it up and make it resuable?
- ansible-playbook -i inventory.ini vector-setup.yml
- ansible-galaxy init vector

lots you can do here.

I don't know if your mastodon post was seeking input, if not, ignore!

@mdfranz
Copy link
Author

mdfranz commented Jan 5, 2025 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment