Minor Change for Standalone Plays

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.

wouldn’t having /etc/ansible/hosts satisfy your first requirement?

​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

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.

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.

" 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.

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