Как в Ansible модулю set_facts передать путь до файла, который лежит на удалённом компьютере?
Есть setup.ini, который лежит в папке TEMP и из которого надо получить переменные. У меня не получается передать параметру file путь в виде переменной. Хардкорить не хочется, делал как написано тут.
- name: Set some fact about Autodesk product
when:
- ansible_os_family == 'Windows'
- ansible_env.PROCESSOR_ARCHITECTURE == 'AMD64'
vars:
autodesk_path_to_setup_ini_file: '{{ ansible_env.TMP }}\setup-{{ autodesk_product_directory }}.ini'
autodesk_product_directory: autocad
set_fact:
autodesk_adlm_version_fact: "{{ lookup('ini', 'ADLM_VERSION section=SETUP file={{ autodesk_path_to_setup_ini_file }} encoding=utf-16') }}"
delegate_to: "{{ inventory_hostname }}"
Ошибка:
fatal: [10.10.10.178]: FAILED! => {
"msg": "An unhandled exception occurred while running the lookup plugin 'ini'. Error was a <class 'ansible.errors.AnsibleParserError'>, original message: Invalid filename: 'None'"
}
ansible 2.9.13
Ответы (1 шт):
Автор решения: don Rumata
→ Ссылка
Я нашёл способ. Есть модуль для пошика под названием psini, который превращает ini в объект. Дальше мы экспортируем в json, json пихаем в факт и всё начинает работать.
Вот как-то так:
- name: Install PowerShell module PsIni 4 Windows
when: ansible_os_family == 'Windows'
become: yes
become_method: runas
become_flags: logon_type=new_credentials logon_flags=netcredentials_only
win_psmodule:
name: psini
state: present
allow_clobber: yes
- name: Get info from setup.ini
when:
- ansible_os_family == 'Windows'
- ansible_env.PROCESSOR_ARCHITECTURE == 'AMD64'
become: yes
become_method: runas
become_flags: logon_type=new_credentials logon_flags=netcredentials_only
vars:
current_version: 2020
autodesk_product_directory: autocad
win_shell: |
Import-Module -Name PsIni
# Т.к. тут пошик, то можно setup.ini не копировать, с сразу дёргать по сети.
$AUTODESK_SETUP_INI_FILE_CONTENT = Get-ChildItem \\10.10.10.10\autodesk\{{ current_version }}\{{ autodesk_product_directory }}\setup.ini | Get-IniContent
echo $AUTODESK_SETUP_INI_FILE_CONTENT | ConvertTo-Json -Compress
register: autodesk_setup_ini_file_content
changed_when: false
# https://gist.github.com/halberom/e276aed3e99ae7df143c
- set_fact:
autodesk_setup_ini_file_content_to_json_fact: "{{ autodesk_setup_ini_file_content.stdout | from_json }}"
- set_fact:
autodesk_product_version_fact: "{{ autodesk_setup_ini_file_content_to_json_fact.SETUP.ADLM_VERSION }}"