# Appending text to file, download remote file and creating a module

**URL:** <https://forum.ansible.com/t/appending-text-to-file-download-remote-file-and-creating-a-module/11479>\
**Category:** Ansible Project\
**Created:** [May 1, 2012, 6:09pm UTC](https://forum.ansible.com/t/appending-text-to-file-download-remote-file-and-creating-a-module/11479 "2012-05-01T18:09:23Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Harm\_Aarts](https://avatars.discourse-cdn.com/v4/letter/h/a5b964/32.png) [@Harm\_Aarts](https://forum.ansible.com/u/Harm_Aarts)\
**Post date:** [May 1, 2012, 6:09pm UTC](https://forum.ansible.com/t/appending-text-to-file-download-remote-file-and-creating-a-module/11479/1 "2012-05-01T18:09:23Z")

</div>

Dear list,

First off; awesome work on Ansible. It’s a breath of fresh air after using Chef/Cdist/Puppet.

I do have a couple of questions.  
What would be the idiomatic way to append some text to a remote file (for example append some host to /etc/munin/munin.conf)?  
And how can I download a file hosted on a remote server? For example we are running a Riak cluster, the .deb is hosted on the developer’s website and we used to grab that with Chef directly to installation.  
When I failed downloading a file with the ‘fetch’ module I started looking into writing my own module. I’m proficient with Ruby but when I used Chef I needed to bootstrap an entire Ruby install on the remote machine. Is that still necessary with Ansible. I don’t think so but how, then, does it work?

With kind regards,  
Harm

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [May 1, 2012, 7:08pm UTC](https://forum.ansible.com/t/appending-text-to-file-download-remote-file-and-creating-a-module/11479/2 "2012-05-01T19:08:35Z")

</div>

> Dear list,
> 
> First off; awesome work on Ansible. It’s a breath of fresh air after using Chef/Cdist/Puppet.
> 
> I do have a couple of questions.  
> What would be the idiomatic way to append some text to a remote file (for example append some host to /etc/munin/munin.conf)?

I wouldn’t do this, as this is very unreliable and can easily break. Configuration should be centrally managed – You want to push down a template declaring exactly what munin.conf should be.

> And how can I download a file hosted on a remote server? For example we are running a Riak cluster, the .deb is hosted on the developer’s website and we used to grab that with Chef directly to installation.  
> When I failed downloading a file with the ‘fetch’ module I started looking into writing my own module. I’m proficient with Ruby but when I used Chef I needed to bootstrap an entire Ruby install on the remote machine. Is that still necessary with Ansible. I don’t think so but how, then, does it work?

Fetch grabs files from other ansible hosts. If you want to grab stuff from a “developer’s website”, it’s really dangerous to keep downloading it every time you deploy (site might not be up, content may not be consistent) … and abusive of that user’s bandwidth. Download it locally, and put it in a repo. Use ansible to configure the deb repo, etc. You could push files out, but it really makes sense to use your distro’s package manager.

---

<div class="post-metadata">

**Author:** ![Harm\_Aarts](https://avatars.discourse-cdn.com/v4/letter/h/a5b964/32.png) [@Harm\_Aarts](https://forum.ansible.com/u/Harm_Aarts)\
**Post date:** [May 1, 2012, 7:18pm UTC](https://forum.ansible.com/t/appending-text-to-file-download-remote-file-and-creating-a-module/11479/3 "2012-05-01T19:18:59Z")

</div>

> > Dear list,
> > 
> > First off; awesome work on Ansible. It’s a breath of fresh air after using Chef/Cdist/Puppet.
> > 
> > I do have a couple of questions.  
> > What would be the idiomatic way to append some text to a remote file (for example append some host to /etc/munin/munin.conf)?
> 
> I wouldn’t do this, as this is very unreliable and can easily break. Configuration should be centrally managed – You want to push down a template declaring exactly what munin.conf should be.

Fair enough, still feels a bit off but that might just be the Chef rubbing off.

> 

> > And how can I download a file hosted on a remote server? For example we are running a Riak cluster, the .deb is hosted on the developer’s website and we used to grab that with Chef directly to installation.  
> > When I failed downloading a file with the ‘fetch’ module I started looking into writing my own module. I’m proficient with Ruby but when I used Chef I needed to bootstrap an entire Ruby install on the remote machine. Is that still necessary with Ansible. I don’t think so but how, then, does it work?
> 
> Fetch grabs files from other ansible hosts. If you want to grab stuff from a “developer’s website”, it’s really dangerous to keep downloading it every time you deploy (site might not be up, content may not be consistent) … and abusive of that user’s bandwidth. Download it locally, and put it in a repo. Use ansible to configure the deb repo, etc. You could push files out, but it really makes sense to use your distro’s package manager.

This deb is not in a particular (apt) repo. Downloading it every time is only once ever 2 weeks or so.

But how does a Ruby module work? Does the remote need to have Ruby installed?

Thanks!

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [May 1, 2012, 7:22pm UTC](https://forum.ansible.com/t/appending-text-to-file-download-remote-file-and-creating-a-module/11479/4 "2012-05-01T19:22:38Z")

</div>

> > > Dear list,
> > > 
> > > First off; awesome work on Ansible. It’s a breath of fresh air after using Chef/Cdist/Puppet.
> > > 
> > > I do have a couple of questions.  
> > > What would be the idiomatic way to append some text to a remote file (for example append some host to /etc/munin/munin.conf)?
> > 
> > I wouldn’t do this, as this is very unreliable and can easily break. Configuration should be centrally managed – You want to push down a template declaring exactly what munin.conf should be.
> 
> Fair enough, still feels a bit off but that might just be the Chef rubbing off.

what you are talking about is older than that.

cfengine: AppendIfNoSuchLine  
puppet: append\_if\_no\_such\_line

IMHO, it’s still a really bad thing to do as you have no idea what configuration is really on your remote systems.

> > Fetch grabs files from other ansible hosts. If you want to grab stuff from a “developer’s website”, it’s really dangerous to keep downloading it every time you deploy (site might not be up, content may not be consistent) … and abusive of that user’s bandwidth. Download it locally, and put it in a repo. Use ansible to configure the deb repo, etc. You could push files out, but it really makes sense to use your distro’s package manager.
> 
> This deb is not in a particular (apt) repo. Downloading it every time is only once ever 2 weeks or so.

It is not Ansible’s job to interact with systems other than the ones you own.

> But how does a Ruby module work? Does the remote need to have Ruby installed?

Are you talking about ohai and facter? Yes, they require ruby. This is why ansible has it’s own facts now – so they aren’t required anymore.

Thanks!

---

<div class="post-metadata">

**Author:** ![Harm\_Aarts](https://avatars.discourse-cdn.com/v4/letter/h/a5b964/32.png) [@Harm\_Aarts](https://forum.ansible.com/u/Harm_Aarts)\
**Post date:** [May 1, 2012, 7:27pm UTC](https://forum.ansible.com/t/appending-text-to-file-download-remote-file-and-creating-a-module/11479/5 "2012-05-01T19:27:14Z")

</div>

> > > > Dear list,
> > > > 
> > > > First off; awesome work on Ansible. It’s a breath of fresh air after using Chef/Cdist/Puppet.
> > > > 
> > > > I do have a couple of questions.  
> > > > What would be the idiomatic way to append some text to a remote file (for example append some host to /etc/munin/munin.conf)?
> > > 
> > > I wouldn’t do this, as this is very unreliable and can easily break. Configuration should be centrally managed – You want to push down a template declaring exactly what munin.conf should be.
> > 
> > Fair enough, still feels a bit off but that might just be the Chef rubbing off.
> 
> what you are talking about is older than that.
> 
> cfengine: AppendIfNoSuchLine  
> puppet: append\_if\_no\_such\_line
> 
> IMHO, it’s still a really bad thing to do as you have no idea what configuration is really on your remote systems.

I like it!

> > > Fetch grabs files from other ansible hosts. If you want to grab stuff from a “developer’s website”, it’s really dangerous to keep downloading it every time you deploy (site might not be up, content may not be consistent) … and abusive of that user’s bandwidth. Download it locally, and put it in a repo. Use ansible to configure the deb repo, etc. You could push files out, but it really makes sense to use your distro’s package manager.
> > 
> > This deb is not in a particular (apt) repo. Downloading it every time is only once ever 2 weeks or so.
> 
> It is not Ansible’s job to interact with systems other than the ones you own.
> 
> > But how does a Ruby module work? Does the remote need to have Ruby installed?
> 
> Are you talking about ohai and facter? Yes, they require ruby. This is why ansible has it’s own facts now – so they aren’t required anymore.

No, I’m talking about some yet-to-be-made Ansible module like ‘yum’. If that hypothetical module is written in Ruby, the remote needs to have Ruby in order to use it right?

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [May 1, 2012, 7:52pm UTC](https://forum.ansible.com/t/appending-text-to-file-download-remote-file-and-creating-a-module/11479/6 "2012-05-01T19:52:57Z")

</div>

> I like it!

Sure, no problem.

You’re free to write a module for it, it’s just not going to ship in Ansible core. You could even write it in Ruby like below 🙂

> > Are you talking about ohai and facter? Yes, they require ruby. This is why ansible has it’s own facts now – so they aren’t required anymore.
> 
> No, I’m talking about some yet-to-be-made Ansible module like ‘yum’. If that hypothetical module is written in Ruby, the remote needs to have Ruby in order to use it right?

A module that needs Ruby will need Ruby, yes!

Imagine the technology involved to get around that 🙂

---

<div class="post-metadata">

**Author:** ![Art\_Zemon](https://avatars.discourse-cdn.com/v4/letter/a/3da27b/32.png) [@Art\_Zemon](https://forum.ansible.com/u/Art_Zemon)\
**Post date:** [May 1, 2012, 8:44pm UTC](https://forum.ansible.com/t/appending-text-to-file-download-remote-file-and-creating-a-module/11479/7 "2012-05-01T20:44:38Z")

</div>

Harm,

I will be writing a module which will assure that a particular line  
appears in a file. This is not "append to file" but might serve you. The  
semantics will be like the current ansible "template" module but applied  
to one line within a file instead of a whole file: declare what you want  
and get idempotent behavior.

&nbsp;&nbsp;&nbsp;&nbsp;-- Art Z.

---

<div class="post-metadata">

**Author:** ![Harm\_Aarts](https://avatars.discourse-cdn.com/v4/letter/h/a5b964/32.png) [@Harm\_Aarts](https://forum.ansible.com/u/Harm_Aarts)\
**Post date:** [May 1, 2012, 9:28pm UTC](https://forum.ansible.com/t/appending-text-to-file-download-remote-file-and-creating-a-module/11479/8 "2012-05-01T21:28:02Z")

</div>

> > I like it!
> 
> Sure, no problem.
> 
> You’re free to write a module for it, it’s just not going to ship in Ansible core. You could even write it in Ruby like below 🙂
> 
> > > Are you talking about ohai and facter? Yes, they require ruby. This is why ansible has it’s own facts now – so they aren’t required anymore.
> > 
> > No, I’m talking about some yet-to-be-made Ansible module like ‘yum’. If that hypothetical module is written in Ruby, the remote needs to have Ruby in order to use it right?
> 
> A module that needs Ruby will need Ruby, yes!
> 
> Imagine the technology involved to get around that 🙂

Hehehe. Would this also mean that Ansible needs Python installed on the remote system?

---

<div class="post-metadata">

**Author:** ![Harm\_Aarts](https://avatars.discourse-cdn.com/v4/letter/h/a5b964/32.png) [@Harm\_Aarts](https://forum.ansible.com/u/Harm_Aarts)\
**Post date:** [May 1, 2012, 9:29pm UTC](https://forum.ansible.com/t/appending-text-to-file-download-remote-file-and-creating-a-module/11479/9 "2012-05-01T21:29:41Z")

</div>

Very interesting. I’ll keep a close eye on the ansible-contrib repo (as soon as it appears).

---

<div class="post-metadata">

**Author:** ![Cosmin\_Luta](https://avatars.discourse-cdn.com/v4/letter/c/8e8cbc/32.png) [@Cosmin\_Luta](https://forum.ansible.com/u/Cosmin_Luta)\
**Post date:** [May 9, 2012, 11:52am UTC](https://forum.ansible.com/t/appending-text-to-file-download-remote-file-and-creating-a-module/11479/10 "2012-05-09T11:52:34Z")

</div>

Is there any code for this module? I’ve written a prototype for a similar one, not knowing that you were already doing this.
