Ansible + Nix 101

tool ops tip nix

published 2023-07-06 11:24

updated 2023-07-07 14:02


Since I use Nix to configure everything it's rare that I get a chance to play with other orchestration tools. Since these tools are very rarely used in combination with Nix, running them from NixOS can serve to be challenging. I'll show you some steps I took to get ansible working (non-reproducibly ugh) in Nix, and a basic rundown of how it works

Debug Printing

{{{yaml tasks:

- name: Show result
            msg: "{{ result.stdout_lines }}"


Dumping Facts

{{{yaml tasks:

  • name: Facts setup:
  • name: Dump delegate_to: localhost run_once: true copy: content: "{{ hostvars[inventory_hostname] | to_nice_json }}" dest: /tmp/setup-dump.json }}}

Using Tags

Add a tag to the specific task you want to run {{{yaml

- name: d_ocean | db | test for existing mongodb
  ansible.builtin.command: doctl db list -o json
  changed_when: false
  failed_when: false
  register: db_check
    - test


Then call the ansible playbook with --tags "test" included as a parameter passed to the binary