How to apply/run playbook target at a specific group of machines in the ini-style inventory

220 views
Skip to first unread message

James Ngo

unread,
Oct 16, 2021, 12:25:53 PM10/16/21
to Ansible Project
Hello everyone,
I am a pretty new face to Ansible. I can follow instruction pretty good however, I need your help with the following scenario.
I created an .INI style inventory file called "hosts", with basically categorize our devices/servers in different groups like below

+++++++++++++++++++
[Ubuntu]
192.168.100.105
192.168.100.106

[Windows]
192.168.100.200
192.168.100.201

[Mac]
192.168.100.300
192.168.100.301

++++++++++++++++++++++
This inventory file is saved in ~/ansible/inventory/hosts
Playbook file (called play1.yml) is saved in ~/ansible/plabooks/play1: check for updates

I can ping the devices in [Windows] group using this command:
$ ansible -i ./inventory/hosts Windows -m ping --user admin --ask-pass

Now, I try to check for updates for just the devices/machines in [Windows] group, using this command:
$ ansible-playbook ./playbooks/play1.yml --user admin --ask-pass --ask-become-pass -i ./inventory/hosts Windows

It returns error that it does not know what devices/machines that I'm targeting at. In another word, it does not recognize my flag ./inventory/hosts Windows

Could someone guide me how to make the proper reference to a specific group of the machines?

Thank you

Dick Visser

unread,
Oct 16, 2021, 12:59:38 PM10/16/21
to ansible...@googlegroups.com
Then the issue must in the playbook itself. 
What does that look like?

--
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 view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/66ff95de-e6ca-46fb-9718-8ddbe9eb89acn%40googlegroups.com.
--
Sent from a mobile device - please excuse the brevity, spelling and punctuation.

James Ngo

unread,
Oct 16, 2021, 1:27:07 PM10/16/21
to Ansible Project
Hi,

Right, it maybe the playbook itself. Anyway, the play1.yml is per below:

========================
- hosts: "*"
  become: yes
  tasks:
    - name: apt
      apt:
        update_cache: yes
        upgrade: 'yes'
=========================

If I run the play1.yml with the following command, without specify any group name, it works:
$ ansible-playbook ./playbooks/play1.yml --user admin --ask-pass --ask-become-pass -i ./inventory/hosts


Then it is OK!!!

Dick Visser

unread,
Oct 16, 2021, 1:37:54 PM10/16/21
to ansible...@googlegroups.com
That "*" is a bit unusual (to me at least).
Try:

hosts: all

And then see if the issue is still there


James Ngo

unread,
Oct 16, 2021, 1:56:29 PM10/16/21
to Ansible Project
I have changed to "host: all" per your suggestion, it unfortunately did not help...
It does not like the -i ./inventory/hosts Windows
But if I just do -i ./inventory/hosts (without the group "Windows"), it will work but it will do all the devices/machines instead of just a specific group (which I want to)
Thank you


James Ngo

unread,
Oct 16, 2021, 5:18:03 PM10/16/21
to Ansible Project
I actually figured it out, should use the -l

-i ./inventory/hosts -l Windows

Works like a charm!

Reply all
Reply to author
Forward
0 new messages