How to specify multiple groups in ansible playbook.

33 views
Skip to first unread message

ameya agashe

unread,
Nov 27, 2018, 1:38:24 AM11/27/18
to ansible...@googlegroups.com
Hello,

I'm wondering how to specify multiple groups in a Ansible playbook??

I followed the correct syntax but it reports error "skipping: no hosts matched"

Playbook code is as below:

- name: Install IIS on the newly provisioned Azure Windows Web Servers
  hosts: webserver
  gather_facts: yes
  tasks:
  - name: Install IIS (Web-Server and Web-Common-Http)
    win_feature:
      name:
      - Web-Server
      - Web-Common-Http
      state: present

  - name: Install IIS Web-Server with sub features and management tools
    win_feature:
      name: Web-Server
      state: present
      include_sub_features: True
      include_management_tools: True
    register: feature_install

  - name: Print variable
    debug:
      var: feature_install

  - name: reboot if installing Web-Server feature requires it
    win_reboot:
    when: feature_install.reboot_required

- name: Install .Net Framework 3.5 on AOS and Web Servers
  hosts: webserver:&aosserver
  gather_facts: yes
  tasks:
  - name: Install .Net Framework 3.5
    win_feature:
      name: NET-Framework-Features
      include_sub_features: True
      state: present
    register: dotnet35_install

  - name: Print variable
    debug:
      var: dontnet35_install

  - name: reboot if installing Web-Server feature requires it
    win_reboot:
    when: dotnet35_install.reboot_required


- name: Install .Net Framework 4.5 on AOS and Web Servers
  hosts: webserver:&aosserver
  gather_facts: yes
  tasks:
  - name: Install .Net Framework 4.5
    win_feature:
      name: NET-Framework-45-Features
      include_sub_features: True
      state: present
    register: dotnet45_install

  - name: Print variable
    debug:
      var: dontnet45_install
  - name: reboot if installing Web-Server feature requires it
    win_reboot:
    when: dotnet45_install.reboot_required


When I run, the first part of webserver works well, but for aosserver I get the below error

TASK [reboot if installing Web-Server feature requires it] ***************************************************************************************************************
task path: /media/sf_C_DRIVE/OnlyOnMyPC/ansible/playbooks.V4/apply-iis.yml:24
skipping: [10.100.3.11] => {
    "changed": false,
    "skip_reason": "Conditional result was False"
}
skipping: [10.100.3.12] => {
    "changed": false,
    "skip_reason": "Conditional result was False"
}
META: ran handlers
META: ran handlers

PLAY [Install .Net Framework 3.5 on AOS and Web Servers] *****************************************************************************************************************
skipping: no hosts matched

PLAY [Install .Net Framework 4.5 on AOS and Web Servers] *****************************************************************************************************************
skipping: no hosts matched

PLAY RECAP ***************************************************************************************************************************************************************
10.100.3.11                : ok=4    changed=0    unreachable=0    failed=0
10.100.3.12                : ok=4    changed=0    unreachable=0    failed=0


My inventory file is like below

cat inventory/hosts
[aosserver]
10.100.3.4
10.100.3.6

[webserver]
10.100.3.11
10.100.3.12

Wondering what I am doing wrong here?

Kindly assist

Thank you very much.

Kind Regards,
Ameya Agashe

Bharath Kumar

unread,
Nov 27, 2018, 11:17:52 PM11/27/18
to Ansible Project
One way to achieve the result is modifying your hosts file as below, could help.

[aosserver]
10.100.3.4
10.100.3.6


[webserver]
10.100.3.11
10.100.3.12

[webaos:children]
aosserver
webserver



and, use webaos in the target group/hosts. 

Michael Mullay

unread,
Nov 27, 2018, 11:50:41 PM11/27/18
to ansible...@googlegroups.com
You can also just comma-separate a list of groups like:

hosts: aosserver,webserver


--
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/5c57c9d6-5029-49aa-8daa-2cf217b0a908%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

ameya agashe

unread,
Nov 28, 2018, 12:09:09 AM11/28/18
to ansible...@googlegroups.com
Many thanks to you both! Much appreciated. It's working now.

Kind Regards,
Ameya Agashe

Reply all
Reply to author
Forward
0 new messages