# How do we run playbook for only host is added more

**URL:** <https://forum.ansible.com/t/how-do-we-run-playbook-for-only-host-is-added-more/2390>\
**Category:** Get Help\
**Created:** [November 15, 2023, 3:15am UTC](https://forum.ansible.com/t/how-do-we-run-playbook-for-only-host-is-added-more/2390 "2023-11-15T03:15:34Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![lanhnguyen](https://avatars.discourse-cdn.com/v4/letter/l/5fc32e/32.png) [@lanhnguyen](https://forum.ansible.com/u/lanhnguyen)\
**Post date:** [November 15, 2023, 3:15am UTC](https://forum.ansible.com/t/how-do-we-run-playbook-for-only-host-is-added-more/2390/1 "2023-11-15T03:15:34Z")

</div>

I added 2 hostname in groupname of inventory file.  
For example  
[db]  
10.0.1.1  
10.0.1.2  
and I run playbook file already into these two hosts.  
Now I want to add more host (10.0.1.3) into db group and run playbook file for this new host.  
Are there any ways that I can run playbook file for only 10.0.1.3 without comment out 10.0.1.1 and 10.0.1.2 because they are installed already.

---

<div class="post-metadata">

**Author:** ![jrglynn2](https://avatars.discourse-cdn.com/v4/letter/j/94ad74/32.png) [@jrglynn2](https://forum.ansible.com/u/jrglynn2)\
**Post date:** [November 15, 2023, 6:33am UTC](https://forum.ansible.com/t/how-do-we-run-playbook-for-only-host-is-added-more/2390/2 "2023-11-15T06:33:41Z")

</div>

The beauty of Ansible is that it’s idempotent - meaning if you run the playbooks more than once, it will see that that changes are already there, and not repeat the work. You just have to be sure that your playbooks are designed correctly.

---

<div class="post-metadata">

**Author:** ![lanhnguyen](https://avatars.discourse-cdn.com/v4/letter/l/5fc32e/32.png) [@lanhnguyen](https://forum.ansible.com/u/lanhnguyen)\
**Post date:** [November 15, 2023, 6:40am UTC](https://forum.ansible.com/t/how-do-we-run-playbook-for-only-host-is-added-more/2390/3 "2023-11-15T06:40:25Z")

</div>

Thank for your explanation so much. So in my case, after add more host (10.0.1.3) it only install packages that designed in playbook on 10.0.1.3 only, right?

---

<div class="post-metadata">

**Author:** ![ptn](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/ptn/32/481_2.png) [@ptn](https://forum.ansible.com/u/ptn)\
**Post date:** [November 15, 2023, 7:13am UTC](https://forum.ansible.com/t/how-do-we-run-playbook-for-only-host-is-added-more/2390/4 "2023-11-15T07:13:52Z")

</div>

Hi,

To target specific hosts, you could either adjust `hosts` key on your play block (from your playbook), or use `—limit` (`-l` for short) flag on `ansible-playbook` command line.

---

<div class="post-metadata">

**Author:** ![ptn](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/ptn/32/481_2.png) [@ptn](https://forum.ansible.com/u/ptn)\
**Post date:** [November 15, 2023, 7:18am UTC](https://forum.ansible.com/t/how-do-we-run-playbook-for-only-host-is-added-more/2390/5 "2023-11-15T07:18:46Z")

</div>

Depends on the modules you used and / or how you wrote your playbooks / roles; most modules are idempotent, as suggested above, but it’s not always the case. Sometimes you have to add your own logic on top to prevent tasks to trigger a change.

---

<div class="post-metadata">

**Author:** ![dawid.grygrzc](https://avatars.discourse-cdn.com/v4/letter/d/59ef9b/32.png) [@dawid.grygrzc](https://forum.ansible.com/u/dawid.grygrzc)\
**Post date:** [November 15, 2023, 8:29am UTC](https://forum.ansible.com/t/how-do-we-run-playbook-for-only-host-is-added-more/2390/6 "2023-11-15T08:29:40Z")

</div>

Hi,  
In normal playbooks you can just use ‘–limit’ option like @ptn said.  
In AWX you have to go to: Templates\>Launch\> Other prompts and fill ‘Limit’ section.

---

<div class="post-metadata">

**Author:** ![lanhnguyen](https://avatars.discourse-cdn.com/v4/letter/l/5fc32e/32.png) [@lanhnguyen](https://forum.ansible.com/u/lanhnguyen)\
**Post date:** [November 17, 2023, 6:06am UTC](https://forum.ansible.com/t/how-do-we-run-playbook-for-only-host-is-added-more/2390/7 "2023-11-17T06:06:55Z")

</div>

> [@ptn](#):
>
> Depends on the modules you used and / or how you wrote your playbooks / roles; most modules are idempotent, as suggested above, but it’s not always the case.

Could you tell me which case?

---

<div class="post-metadata">

**Author:** ![lanhnguyen](https://avatars.discourse-cdn.com/v4/letter/l/5fc32e/32.png) [@lanhnguyen](https://forum.ansible.com/u/lanhnguyen)\
**Post date:** [November 17, 2023, 6:07am UTC](https://forum.ansible.com/t/how-do-we-run-playbook-for-only-host-is-added-more/2390/8 "2023-11-17T06:07:34Z")

</div>

> [@ptn](#):
>
> Sometimes you have to add your own logic on top to prevent tasks to trigger a change.

Could you tell me more detail and example what we add?

---

<div class="post-metadata">

**Author:** ![jrglynn2](https://avatars.discourse-cdn.com/v4/letter/j/94ad74/32.png) [@jrglynn2](https://forum.ansible.com/u/jrglynn2)\
**Post date:** [November 17, 2023, 2:21pm UTC](https://forum.ansible.com/t/how-do-we-run-playbook-for-only-host-is-added-more/2390/9 "2023-11-17T14:21:07Z")

</div>

This is entirely dependent on what you are doing in the playbook or individual tasks. The best to do is to test - run your playbook against a test server multiple times, and if it changes things multiple times, then add tasks/code that run checks first, and use conditionals on when to run tasks.

---

<div class="post-metadata">

**Author:** ![ptn](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/ptn/32/481_2.png) [@ptn](https://forum.ansible.com/u/ptn)\
**Post date:** [November 20, 2023, 5:36pm UTC](https://forum.ansible.com/t/how-do-we-run-playbook-for-only-host-is-added-more/2390/10 "2023-11-20T17:36:58Z")

</div>

As hinted by @jrglynn2 , it depends. I wont give you a full list, but here is an example; [amazon.aws.ec2\_instance module’s `count` parameter](https://docs.ansible.com/ansible/latest/collections/ansible/netcommon/network_cli_connection.html) makes it that your task will always spawn more instances, thus making it not idempotent. Using [exact\_count](https://docs.ansible.com/ansible/latest/collections/amazon/aws/ec2_instance_module.html#parameter-exact_count) instead will.

As for your second inquiry, again, not a complete list, but you can use mechanisms like `when:` keyword, some specific jinja filters, or even run a task undoing what you did with `changed_when: false` to that end. If that doesn’t click, ping me and I’ll write an example playbook to show you.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [December 20, 2023, 5:37pm UTC](https://forum.ansible.com/t/how-do-we-run-playbook-for-only-host-is-added-more/2390/11 "2023-12-20T17:37:22Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
