Skip to content

Commit

Permalink
ansible: write vars to file to avoid argument list too long
Browse files Browse the repository at this point in the history
  • Loading branch information
mkg20001 committed Feb 7, 2024
1 parent 2f13d19 commit 8dd0e2c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion ansible/module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ with lib;
};
};

config.ansible = mkIf (config.ansible-src != null && config.ansible-src != "") (builtins.fromJSON config.ansible-src);
config.ansible = mkIf (config.ansible-src != null && config.ansible-src != "") (builtins.fromJSON (builtins.readFile config.ansible-src));
}
15 changes: 14 additions & 1 deletion roles/nixos_rebuild/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,23 @@
#- debug:
# msg: "{{ exported_vars }}"

- name: Create temporary file for ansible variables
tempfile:
state: file
suffix: .json
register: ansible_json_vars
delegate_to: localhost

- name: Write variables to file
ansible.builtin.template:
src: templates/json.j2
dest: "{{ ansible_json_vars.path }}"
delegate_to: localhost

- block:
- name: Deploy "{{ flake_url }}" to "{{ target_host }}"
ansible.builtin.shell: |
env ANSIBLE_JSON={{ exported_vars | to_json | quote }} {{ nix_wrapper }} nix run nixpkgs#nixos-rebuild -- --flake "{{ flake_dir }}#{{ flake_target }}" "switch" --impure --target-host "{{ target_host }}" --show-trace
env ANSIBLE_JSON={{ ansible_json_vars.path | quote }} {{ nix_wrapper }} nix run nixpkgs#nixos-rebuild -- --flake "{{ flake_dir }}#{{ flake_target }}" "switch" --impure --target-host "{{ target_host }}" --show-trace
delegate_to: localhost
register: nixos_rebuild
rescue:
Expand Down
1 change: 1 addition & 0 deletions roles/nixos_rebuild/templates/json.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{ exported_vars | to_json }}

0 comments on commit 8dd0e2c

Please sign in to comment.