Method: all:!xxx
Current hosts file configuration:
1 [root@localhost playbooks]# cat ../hosts 2 [web] 192.168.100.100 3 4 [web1] 192.168.100.102
Case 1: Remove a host group from all
Playbook content:
1 [root@localhost playbooks]# cat ping1.yml 2 - hosts: all:!web1 3 remote_user: root 4 tasks: 5 - name: test connecion 6 ping:
Results of the:
1 [root@localhost playbooks]# ansible-playbook ping.yml 2 3 PLAY [all:!192.168.100.102] ************************************************************************************************************************************************************************************************************************************************** 4 5 TASK [Gathering Facts] ******************************************************************************************************************************************************************************************************************************************************* 6 ok: [192.168.100.100] 7 8 TASK [test connecion] ******************************************************************************************************************************************************************************************************************************************************** 9 ok: [192.168.100.100] 10 11 PLAY RECAP ******************************************************************************************************************************************************************************************************************************************************************* 12 13 14 192.168.100.100 : ok=2 changed=0 unreachable=0 failed=0
Case 2: Eliminate the machine with the specified IP from all
1 [root@localhost playbooks]# cat ping.yml 2 - hosts: all:!192.168.100.102 3 remote_user: root 4 tasks: 5 - name: test connecion 6 ping:
Results of the:
1 [root@localhost playbooks]# ansible-playbook ping1.yml 2 3 PLAY [all:!web1] ************************************************************************************************************************************************************************************************************************************************************* 4 5 TASK [Gathering Facts] ******************************************************************************************************************************************************************************************************************************************************* 6 ok: [192.168.100.100] 7 8 TASK [test connecion] ******************************************************************************************************************************************************************************************************************************************************** 9 ok: [192.168.100.100] 10 11 PLAY RECAP ******************************************************************************************************************************************************************************************************************************************************************* 12 13 14 192.168.100.100 : ok=2 changed=0 unreachable=0 failed=0