Minor Change for Standalone Plays

73 views
Skip to first unread message

Aaron Hunter

unread,
Feb 22, 2014, 8:25:46 AM2/22/14
to ansible...@googlegroups.com
I often want to create and share stand-alone, single plays (i.e., some_task.yml). Ansible makes it very easy to automate tedious admin tasks so I like to use it instead of old-school shell scripting. This works fine of course but there is one small friction point in the form of the inventory file. It would be cool if I could run a stand-alone play without an inventory file (the host is already in the play) just be typing 'ansible-playbook some_task.yml'

My goal is also to publish short howtos as Ansible plays. People could then just install Ansible, download the play and run it. No knowledge of Ansible configuration required. Low friction. A lot of sites offer howtos as a series of manual steps. Better that they provide Ansible plays instead.

One more thing, could you modify the 'unarchive' module to accept URLs in the 'src' parameter? I tried to pass a URL (http://file.com/file.tar.gz) but got an error.  It's a common task to download a tar.gz file from the web and then untar/unzip it.  Perhaps others would find that useful as well.

Thanks.



Walid

unread,
Feb 22, 2014, 8:29:08 AM2/22/14
to ansible...@googlegroups.com
wouldn't having  /etc/ansible/hosts satisfy your first requirement?


--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/40bc8c69-ee26-4ccc-b7af-04cd57e100dd%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Serge van Ginderachter

unread,
Feb 22, 2014, 8:30:48 AM2/22/14
to ansible...@googlegroups.com

On 22 February 2014 14:25, Aaron Hunter <aaron....@gmail.com> wrote:
I often want to create and share stand-alone, single plays (i.e., some_task.yml). Ansible makes it very easy to automate tedious admin tasks so I like to use it instead of old-school shell scripting. This works fine of course but there is one small friction point in the form of the inventory file. It would be cool if I could run a stand-alone play without an inventory file (the host is already in the play) just be typing 'ansible-playbook some_task.yml'

​That will never be possible with just as task file, bit given you have a minimal playbook containing

- hosts: all
  tasks:
  - name: some task
    action: ...

there is a trick to do just that;

   ansible-playbook all -i my.one.off.host.name,​ play.yml

Note the trailing comma at the end of the inventory.


Serge

Michael DeHaan

unread,
Feb 22, 2014, 8:56:06 AM2/22/14
to ansible...@googlegroups.com
The trailing comma is only needed if there is only one host, FWIW.   It's a hack and undocumented for a reason -- it might be supplanted by a different option later, maybe.

That being said, you are very well served for setting up an inventory file, as groups are a useful concept, and if you have to set variables, it's much easier than remembering them.   Group_vars and host_vars don't work in the ways you specified above, and various plays that depend on iterating across groups won't have that information.

I'd still strongly encourage everyone to set up inventory.


--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.

Aaron Hunter

unread,
Feb 22, 2014, 10:50:05 AM2/22/14
to ansible...@googlegroups.com
For the normal case of infrastructure CM the inventory files are definitely needed. For the case of a one-off Ansible play run locally they are not. I understand this may be an edge case and hence not worth supporting. Fair enough.  It's a small enhancement. I just wanted to avoid the unnecessary step of creating an inventory file in the case where one wasn't needed.

Michael DeHaan

unread,
Feb 22, 2014, 10:53:37 AM2/22/14
to ansible...@googlegroups.com
" For the case of a one-off Ansible play run locally they are not."

Unless you want to set the port, host, connection type, or any of that on a per host basis and not have to enter it in every time, or remember any variable about the host that you might use in a future one of play.




On Sat, Feb 22, 2014 at 10:50 AM, Aaron Hunter <aaron....@gmail.com> wrote:
For the normal case of infrastructure CM the inventory files are definitely needed. For the case of a one-off Ansible play run locally they are not. I understand this may be an edge case and hence not worth supporting. Fair enough.  It's a small enhancement. I just wanted to avoid the unnecessary step of creating an inventory file in the case where one wasn't needed.

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.

Adam Morris

unread,
Feb 22, 2014, 1:16:11 PM2/22/14
to ansible...@googlegroups.com


One more thing, could you modify the 'unarchive' module to accept URLs in the 'src' parameter? I tried to pass a URL (http://file.com/file.tar.gz) but got an error.  It's a common task to download a tar.gz file from the web and then untar/unzip it.  Perhaps others would find that useful as well.



It's a common task, but equally you can download it once and that way you know which version will be sent to the remotes.  If you're only running it on your local host then you can always use get_url to fetch the file to a known location and then unarchive to unpack it.  (assuming it's related to your standalone install you mentioned).  For a more complicated scenario you could have a role for the Ansible "server" that fetches all of the source files and then different roles that move them over and unarchive them.

I hope that this helps. 

Adam
Reply all
Reply to author
Forward
0 new messages