How to import/load env/ini file that is located in file on the Remote/Target server?

QUESTION: How can we load or import an env/ini file that is located in a file on the Remote/Target server?

GOAL:
We have an env/ini file on the remote/target server.
We want to read in that file and use the values as variables for the tasks on that machine.
( FYI: Our process does not allow for saving these variables in the Inventory - even though that would be nice. )

Here is an example of what our ini/env file looks like:

Path: /devops/properties/Admin.properties
username = FooAdmin
password = bar123XYZ
activate = no

(Basically property format or ini format without any sections)

ANSIBLE ENVIRONMENT:
We are running playbook jobs from Ansible Tower 2.5.10
Remote / target machines have Ansible 2.4.2.0 & Python 2.7.5
( FYI: We are probably 6months to 1 year away from updating to newer versions - even though that’d be nice too. )

Thanks in advance for any help.
-Chaz

FYI: I have tried with_ini – but it seems that maybe limited to the controlling/initiating server, and/or maybe the with_ini loop feature is not available in Ansible 2.4

Hello Chaz,

you could use fetch module first to get from remote to local, then use with_ini

But on the face of it it does look like a file that should be source controlled/with the ansible playbooks/roles etc

you can use fetch and make it a ‘local file’ or the slurp module, use a registered variable and a |base64decode filter on the content and then use another filter to parse the data into a usable structure

I like the idea of this suggestion.
Is local-facts-facts-d usable as Non-Root?
Can facts be loaded from the user’s $HOME/.ansible/ , like $HOME/.ansible/facts.d or something like that?
I see for windows there is fact_path does that work for Linux?

Regards,
-Chaz

Hi Chaz,

Hi Hugo,
I like your suggestion – is so close – and pretty elegant.
However - /etc/ansible/facts.d is owned by root.
Even though the INI/Property file you loaded was not owned by root,
Only root could have added **/etc/ansible/facts.d/**factfile.fact

Thanks for trying!

Let me know if you find out something similar that a non-root user can setup and use.

For now - I am brute forcing it.
I have found that the fewest strokes to get it done is like this:
shell: “cat myfile”
register: capture_myfile
Then parse the capture and set_facts.

I tried slurp and fetch but they all ended up really ugly, and un-readable for the next guy.

I am actually shocked that this is not a mainstream feature.
Like sourcing in an ENV file in a script.