Skip to content

ansible-playbook does permit you to specify inventory on the command line #2

Description

@larsks

In https://github.com/k4ml/importerror/blob/master/posts/ansible-playbook-specify-hosts-on-the-command-line.md, you say:

While we can specify what hosts to run the command through ansible command-line program, it's does not apply to ansible-playbook program. We always need to specify the hosts: attribute in our YAML playbook.

That is not in fact true. Consider this playbook, which simply runs the ping module:

- hosts: all
  tasks:
    - ping:

If we have this in playbook.yml we can run it on localhost like this:

ansible-playbook -i localhost, playbook.yml

Or on hosta.example.com like this:

ansible-playbook -i hosta.example.com, playbook.yml

That is in fact pretty much the same syntax as the ansible ad-hoc command.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions