# Using fetch in a role

**URL:** <https://forum.ansible.com/t/using-fetch-in-a-role/15351>\
**Category:** Ansible Project\
**Created:** [May 28, 2014, 10:43am UTC](https://forum.ansible.com/t/using-fetch-in-a-role/15351 "2014-05-28T10:43:20Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Joost\_Cassee](https://avatars.discourse-cdn.com/v4/letter/j/898d66/32.png) [@Joost\_Cassee](https://forum.ansible.com/u/Joost_Cassee)\
**Post date:** [May 28, 2014, 10:43am UTC](https://forum.ansible.com/t/using-fetch-in-a-role/15351/1 "2014-05-28T10:43:20Z")

</div>

Hi all,

I am using the fetch module in a role that redistributes ssh\_known\_hosts by:

1. creating a snippet on every host
2. fetching those snippets
3. redistributing the concatenation

I wanted to keep the snippets inside the files directory of the role, but the fetch module fetches does not use that directory as the basedir.

My two question:

1. Is this expected behavior? (I see how this makes sense.)
2. If so, can I find the role basedir somehow so I can put the snippets in the role files directory?

Regards,  
Joost

---

<div class="post-metadata">

**Author:** ![Joost\_Cassee](https://avatars.discourse-cdn.com/v4/letter/j/898d66/32.png) [@Joost\_Cassee](https://forum.ansible.com/u/Joost_Cassee)\
**Post date:** [May 28, 2014, 10:58am UTC](https://forum.ansible.com/t/using-fetch-in-a-role/15351/2 "2014-05-28T10:58:35Z")

</div>

By the way, in the mean time I hacked around the problem by creating a  
custom lookup plugin:

class LookupModule(object):

&nbsp;&nbsp;&nbsp;&nbsp;def \_\_init\_\_(self, basedir=None, \*\*kwargs):  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.basedir = basedir

&nbsp;&nbsp;&nbsp;&nbsp;def run(self, terms=None, inject=None, \*\*kwargs):  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return [self.basedir]

I'm not proud of myself. 🙂

Regards,  
Joost

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [May 28, 2014, 12:07pm UTC](https://forum.ansible.com/t/using-fetch-in-a-role/15351/3 "2014-05-28T12:07:42Z")

</div>

Well, fetch is used to gather files from a remote host and put them on the local one.

Usually filing up the roles directory would be a non-standard place to put things, and would probably result in data accidentally going into source control, and that content should drop outside of your playbook directly.

I’d suggest downloading to a specific path, but more so, that you probably shouldn’t be redistributing known hosts by trusting one of your nodes, as nodes should be by very nature untrustworthy, and something centrally managed.

My two cents anyway, unrelated to the above.

I think changing the path would break playbooks.

---

<div class="post-metadata">

**Author:** ![Joost\_Cassee](https://avatars.discourse-cdn.com/v4/letter/j/898d66/32.png) [@Joost\_Cassee](https://forum.ansible.com/u/Joost_Cassee)\
**Post date:** [May 28, 2014, 1:41pm UTC](https://forum.ansible.com/t/using-fetch-in-a-role/15351/4 "2014-05-28T13:41:40Z")

</div>

> Usually filing up the roles directory would be a non-standard place to put  
> things, and would probably result in data accidentally going into source  
> control, and that content should drop outside of your playbook directly.  
> [...]  
> I think changing the path would break playbooks.

Sure, I can see that.

> [...] you probably  
> shouldn't be redistributing known hosts by trusting one of your nodes, as  
> nodes should be by very nature untrustworthy, and something centrally  
> managed.

That is a good point. Are you suggesting creating the /etc/ssh\_host\_\*  
files on the Ansible host and pushing them out to the managed nodes?  
Would kind of make sense. Easy to do, too, with ssh-keygen.

Regards,  
Joost
