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.
In https://github.com/k4ml/importerror/blob/master/posts/ansible-playbook-specify-hosts-on-the-command-line.md, you say:
That is not in fact true. Consider this playbook, which simply runs the
pingmodule:If we have this in
playbook.ymlwe can run it onlocalhostlike this:Or on
hosta.example.comlike this:That is in fact pretty much the same syntax as the
ansiblead-hoc command.