NetBSD-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Ansible recipes for NetBSD



Benny Siegert writes:
> Hi!
>

Hello Benny!

> I have some NetBSD systems which are set up in a certain way for running 
> some services. In the interest of the "cattle, not pets" SRE adage, I 
> would like to have a script to stand up a fully configured machine, based 
> on a fresh NetBSD installation.
>
> I was thinking about using Ansible for this. However, I read that it 
> requires some stuff to be on the target, like a Python interpreter.
>
> How do people usually solve this? It sounds like a problem others must 
> have solved already. A "raw" recipe to set up pkgin and install Python, 
> maybe?
>
> Anyone have examples for copy-and-pasting?
> [...]

Yes, ansible.builtin.raw can be used to bootstrap it if the machine is
accessible via SSH (and/or possible other connection plugins).

Attached you can find a bootstrap.yml playbook that I use in order to
have all the requirements to then use Ansible as usual.
---
- name: Bootstrap servers
  hosts: all
  become: true
  become_method: ansible.builtin.su

  gather_facts: false
  vars:
    pkg_path:
      'https://cdn.netbsd.org/pub/pkgsrc/packages/NetBSD/x86_64/11.0_2026Q3/All'

  tasks:
    - name: Bootstrap NetBSD without Python
      ansible.builtin.raw: |
        set -e
        export PKG_PATH="{{ pkg_path }}"
        /usr/sbin/pkg_add -v pkg_alternatives pkgin python313 sudo
      register: output
      changed_when: >-
        output.stdout |
        regex_search('^Package .* registered in', multiline=True)
    - name: Permit wheel group to use sudo without password
      ansible.builtin.raw: |
        set -e
        if [ ! -f /usr/pkg/etc/sudoers.d/00-wheel ]; then
          echo '%wheel ALL=(ALL:ALL) NOPASSWD: ALL' |
          tee /usr/pkg/etc/sudoers.d/00-wheel
        fi
      register: output
      changed_when: >-
        output.stdout |
        regex_search('^%wheel')


Home | Main Index | Thread Index | Old Index