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

**URL:** <https://forum.ansible.com/t/how-to-import-load-env-ini-file-that-is-located-in-file-on-the-remote-target-server/29416>\
**Category:** Ansible Project\
**Created:** [January 10, 2019, 5:00pm UTC](https://forum.ansible.com/t/how-to-import-load-env-ini-file-that-is-located-in-file-on-the-remote-target-server/29416 "2019-01-10T17:00:25Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chaz\_E](https://avatars.discourse-cdn.com/v4/letter/c/e9bcb4/32.png) [@Chaz\_E](https://forum.ansible.com/u/Chaz_E)\
**Post date:** [January 10, 2019, 5:00pm UTC](https://forum.ansible.com/t/how-to-import-load-env-ini-file-that-is-located-in-file-on-the-remote-target-server/29416/1 "2019-01-10T17:00:25Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Chaz\_E](https://avatars.discourse-cdn.com/v4/letter/c/e9bcb4/32.png) [@Chaz\_E](https://forum.ansible.com/u/Chaz_E)\
**Post date:** [January 10, 2019, 7:10pm UTC](https://forum.ansible.com/t/how-to-import-load-env-ini-file-that-is-located-in-file-on-the-remote-target-server/29416/2 "2019-01-10T19:10:30Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![hugonz](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/hugonz/32/503_2.png) [@hugonz](https://forum.ansible.com/u/hugonz)\
**Post date:** [January 10, 2019, 8:56pm UTC](https://forum.ansible.com/t/how-to-import-load-env-ini-file-that-is-located-in-file-on-the-remote-target-server/29416/3 "2019-01-10T20:56:20Z")

</div>

Hello Chaz,

---

<div class="post-metadata">

**Author:** ![goforawalktwice](https://avatars.discourse-cdn.com/v4/letter/g/c5a1d2/32.png) [@goforawalktwice](https://forum.ansible.com/u/goforawalktwice)\
**Post date:** [January 10, 2019, 9:26pm UTC](https://forum.ansible.com/t/how-to-import-load-env-ini-file-that-is-located-in-file-on-the-remote-target-server/29416/4 "2019-01-10T21:26:28Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [January 11, 2019, 9:52pm UTC](https://forum.ansible.com/t/how-to-import-load-env-ini-file-that-is-located-in-file-on-the-remote-target-server/29416/5 "2019-01-11T21:52:07Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Chaz\_E](https://avatars.discourse-cdn.com/v4/letter/c/e9bcb4/32.png) [@Chaz\_E](https://forum.ansible.com/u/Chaz_E)\
**Post date:** [January 14, 2019, 5:02pm UTC](https://forum.ansible.com/t/how-to-import-load-env-ini-file-that-is-located-in-file-on-the-remote-target-server/29416/6 "2019-01-14T17:02:20Z")

</div>

I like the idea of this suggestion.  
Is [local-facts-facts-d](https://docs.ansible.com/ansible/latest/user_guide/playbooks_variables.html#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

---

<div class="post-metadata">

**Author:** ![hugonz](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/hugonz/32/503_2.png) [@hugonz](https://forum.ansible.com/u/hugonz)\
**Post date:** [January 14, 2019, 7:01pm UTC](https://forum.ansible.com/t/how-to-import-load-env-ini-file-that-is-located-in-file-on-the-remote-target-server/29416/7 "2019-01-14T19:01:21Z")

</div>

Hi Chaz,

---

<div class="post-metadata">

**Author:** ![Chaz\_E](https://avatars.discourse-cdn.com/v4/letter/c/e9bcb4/32.png) [@Chaz\_E](https://forum.ansible.com/u/Chaz_E)\
**Post date:** [February 2, 2019, 12:29am UTC](https://forum.ansible.com/t/how-to-import-load-env-ini-file-that-is-located-in-file-on-the-remote-target-server/29416/8 "2019-02-02T00:29:49Z")

</div>

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.
