<p>Use the <a href="https://docs.ansible.com/ansible/latest/user_guide/intro_patterns.html?highlight=--limit" rel="nofollow noreferrer"><code>--limit</code></a> option to select a subset of hosts:</p>

<pre><code>ansible-playbook -i /path  test.yml --tags automation --limit host2
</code></pre>

<p>Its description from <a href="https://docs.ansible.com/ansible/latest/cli/ansible-playbook.html#cmdoption-ansible-playbook-l" rel="nofollow noreferrer">ansible-playbook documentation</a>:</p>

<blockquote>
  <p>further limit selected hosts to an additional pattern</p>
</blockquote>

CC BY-SA 4.0
2019-05-07T07:40:15.370Z
i found these too: `--limit 'standby,primary'` and `--limit 'standby:!host3'`
BlackCrystal
CC BY-SA 4.0
2019-05-07T07:16:40.530Z
2019-05-07T07:16:40.530Z
Michał Politowski
<p>I am new to Ansible and i have a question about limitting hosts in a host group at running commands.I have these host groups in my inventory:  </p>

<pre><code>[primary]  
host1  
host2  
[standby]  
host3  
host4  
</code></pre>

<p>i have thses configuration in my <code>.yml</code>:  </p>

<pre><code>  ---
  - hosts: primary
  roles:
     - automation  
</code></pre>

<p>for example i want to run this command <code>ansible -playbook -i /path  test.yml --tags automation</code> on <code>host2</code> only. what should i do?</p>

<ansible><linux><automation><centos>
how to run an Ansible command for specific number of hosts
BlackCrystal
# how to run an Ansible command for specific number of hosts

(Asked by: username_0 on 2019-05-07)

I am new to Ansible and i have a question about limitting hosts in a host group at running commands.I have these host groups in my inventory:  
[primary]  
host1  
host2  
[standby]  
host3  
host4  

i have thses configuration in my .yml:  
  ---
  - hosts: primary
  roles:
     - automation  

for example i want to run this command ansible -playbook -i /path  test.yml --tags automation on host2 only. what should i do?

**Tags:** ansible, linux, automation, centos


---

## 1 answers

### Answer by username_1 on 2019-05-07. Score: 2 | Accepted answer

Use the --limit option to select a subset of hosts:
ansible-playbook -i /path  test.yml --tags automation --limit host2

Its description from ansible-playbook documentation:

further limit selected hosts to an additional pattern

> **Comments:**
> **username_0**: i found these too: `--limit 'standby,primary'` and `--limit 'standby:!host3'`  

---

