How to play with a specific group using Ansible Playbook

Possible version: 2.1.0

My file name:

[PM]
asma.example.com ansible_connection=ssh

[ND]
malliswar.example.com ansible_connection=ssh

[CM]
asma.example.com ansible_connection=ssh
malliswar.example.com ansible_connection=ssh

And playbook:

- hosts: PM:ND:CM
   remote_user: root
   tasks:
    {some thing}

- hosts: PM
   remote_user: root
   tasks:
    {some thing}

 - hosts: ND
   remote_user: root
   tasks:
    {some thing}

- hosts: CM
   remote_user: root
   tasks:
    {some thing}

And I run the playbook with the following command:

ansible-playbook --limit 'PM' akana-installation.yml

But still the playbook plays all hosts, that means

Play 'PM:ND:CM'
Play 'PM'
Play 'ND'
Play 'CM'

all games are playing. Please help me solve this problem.

What I need: During the execution of the playbook, I will give the name of the group that only the group should play , so please let me know if there is another way.

+4
source share
3 answers

The original question: the -limit option does not work

ansible-playbook --limit 'PM' akana-installation.yml, , PM.
asma.example.com.
, , , .
:

[PM]
asma.example.com ansible_connection=ssh

[ND]

[CM]
asma.example.com ansible_connection=ssh

, asma.example.com.
:

Play 'PM:ND:CM'
[asma.example.com]
Play 'PM'
[asma.example.com]
Play 'ND'
skipping: no hosts matched
Play 'CM'
[asma.example.com]
+3

:

mkdir playbooks

, . playbooks/pm.yml:

- hosts: PM
  remote_user: root
  tasks:
  {some thing}

all.yml

- hosts: PM:ND:CM
  remote_user: root
  tasks:
  {some thing}

- include: playbooks/pm.yml
- include: playbooks/nd.yml
- include: playbooks/cm.yml    

, :

ansible-playbook all.yml

:

ansible-playbook playbooks/pm.yml

ansible-playbook playbooks/nd.yml
+1

. , , .

:
"ND" ( ) . , . Gist:

:
, , TAGS. ( , ), .

:

...
- hosts: PM
  remote_user: root
  tags: pmtag
  tasks:
    {some thing}

playbook , .

ansible-playbook --limit 'PM' akana-installation.yml --tags pmtag

, PM pmtag.

0

All Articles