how to set a variable from an ini file in ansible?
Since the ini lookup plugin only reads files local to the controlling host, the remote file needs to be fetched locally before it can be read and set_fact has to be used to put its content into a variable, which results in the following:
- block:
  - name: &quot;Retrieve remote ini file&quot;
    fetch:
      src: /path_to/ini_file
      dest: /tmp/ansible
  - name: &quot;Read and store my value&quot;
    set_fact:
      my_variable: &quot;{{ lookup( 'ini', 'myParam section=mySection file=/tmp/ansible/{{ inventory_hostname }}/path_to/ini_file' ) }}&quot;

Then the parameter is available as variable and can be used further in the playbook
- debug:
    var: my_variable