Ansible eine Datei über SSH erstellen?

1 Antwort

Klar, da du die Datei auf einem Windows System erstellen möchtest musst du beachten das die normalen Collections bzw. Module nicht gehen werden.

Das Modul win_file Modul Sollte das Äquivalent zu dem Linux file Modul sein.https://docs.ansible.com/ansible/latest/collections/ansible/windows/win_file_module.html

Beispiel:

- name: Touch a file (creates if not present, updates modification time if present)
  ansible.windows.win_file:
    path: C:\Temp\foo.conf
    state: touch

- name: Remove a file, if present
  ansible.windows.win_file:
    path: C:\Temp\foo.conf
    state: absent

- name: Create directory structure
  ansible.windows.win_file:
    path: C:\Temp\folder\subfolder
    state: directory

- name: Remove directory structure
  ansible.windows.win_file:
    path: C:\Temp
    state: absent

Um direkt in die Datei schon während der Erstellung was zu schreiben kannst du wieder wie in den Linux Modulen das win_copy Modul verwenden mit dem content Parameter:

https://docs.ansible.com/ansible/latest/collections/ansible/windows/win_copy_module.html

- name: Set the contents of a file
  ansible.windows.win_copy:
    content: abc123
    dest: C:\Temp\foo.txt

Um mehrere Maschinen zu konfugireren muss man sich an einem Punkt die Frage stellen ob Ansible im Kontext zu Windows die richtige Wahl ist. Ansible ist optimal für Linux, allerdings öfters pain in the ass für Windows.

Woher ich das weiß:Berufserfahrung – Ausgebildeter System Engineer (FISI)