# How to play  a task for only one host spesificly in inventory list

**URL:** <https://forum.ansible.com/t/how-to-play-a-task-for-only-one-host-spesificly-in-inventory-list/31550>\
**Category:** Ansible Project\
**Created:** [October 27, 2019, 7:00am UTC](https://forum.ansible.com/t/how-to-play-a-task-for-only-one-host-spesificly-in-inventory-list/31550 "2019-10-27T07:00:06Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mahmut](https://avatars.discourse-cdn.com/v4/letter/m/278dde/32.png) [@Mahmut](https://forum.ansible.com/u/Mahmut)\
**Post date:** [October 27, 2019, 7:00am UTC](https://forum.ansible.com/t/how-to-play-a-task-for-only-one-host-spesificly-in-inventory-list/31550/1 "2019-10-27T07:00:06Z")

</div>

Hello,

I have a playbook and inventory list. I will run a task for only one host from inventory list. Is there any way to do this?

- hosts: eos\_switches  
connection: local

tasks:

- name: Gather Show Version Facts  
eos\_command:  
commands:

- ‘show version’  
register: showvers

- debug:  
var: showvers

- name: Create vlan  
eos\_vlan:  
vlan\_id: 4091  
name: CONNECTION-P2P  
state: present

- name: configure interface  
eos\_interface:  
name: ethernet1  
description: CONNECTION-P2P  
speed: 100full  
mtu: 1500

- name: Ensure Ethernet1 is a trunk port  
eos\_l2\_interface:  
name: Ethernet1  
mode: trunk  
native\_vlan: 1  
trunk\_allowed\_vlans: 4091

- name: Set ethernet1 IPv4 address  
eos\_l3\_interface:  
provider:  
host: eos\_switches[‘192.168.81.139’]  
transport: eapi  
use\_ssl: yes  
validate\_certs: no  
username: eapi  
password: icantellyou  
name: vlan4091  
ipv4: 192.168.0.1/30

- name: Set ethernet1 IPv4 address\_2  
eos\_l3\_interface:  
provider:  
host: eos\_switches[‘192.168.81.140’]  
transport: eapi  
use\_ssl: yes  
validate\_certs: no  
username: eapi  
password: icantellyou  
name: vlan4091  
ipv4: 192.168.0.2/30

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [October 27, 2019, 7:51am UTC](https://forum.ansible.com/t/how-to-play-a-task-for-only-one-host-spesificly-in-inventory-list/31550/2 "2019-10-27T07:51:03Z")

</div>

I guess eos\_switches is a group?  
Instead of using the group, just use the name of the switch

- hosts: my\_lonely\_switch

---

<div class="post-metadata">

**Author:** ![Mahmut](https://avatars.discourse-cdn.com/v4/letter/m/278dde/32.png) [@Mahmut](https://forum.ansible.com/u/Mahmut)\
**Post date:** [October 27, 2019, 7:55am UTC](https://forum.ansible.com/t/how-to-play-a-task-for-only-one-host-spesificly-in-inventory-list/31550/3 "2019-10-27T07:55:09Z")

</div>

Hi Kai,

Some tasks will play for all hosts that are in in my host file. But some tasks will play per host. For example, I am using IP assignment to hosts.

HOST A will take 192.168.0.1/24 and host B 192.168.0.2/24. So tasks should be run seperately for those hosts.

Should I create another playbook for per host? Or is there any way to send spesific task for spesific host in one playbook?

Windows 10 için [Posta](https://go.microsoft.com/fwlink/?LinkId=550986) ile gönderildi

**Kimden:** [Kai Stian Olstad](mailto:ansible-project+list@olstad.com)  
**Gönderilme:** 27 Ekim 2019 Pazar 10:51  
**Kime:** [ansible-project@googlegroups.com](mailto:ansible-project@googlegroups.com)  
**Konu:** Re: [ansible-project] How to play a task for only one hostspesificly in inventory list

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [October 27, 2019, 8:55am UTC](https://forum.ansible.com/t/how-to-play-a-task-for-only-one-host-spesificly-in-inventory-list/31550/4 "2019-10-27T08:55:40Z")

</div>

If everything is the same but only some parameters is different I would use the same playbook, and put the differences in variables.

Ansible has the possibility to have variables many places[1], inventory, host\_vars, group\_vars, play and so on.

So instead of hard coding the variables in the play/playbook use variable instead, and have different values in the variables for different switches.

[1] [https://docs.ansible.com/ansible/latest/user\_guide/playbooks\_variables.html](https://docs.ansible.com/ansible/latest/user_guide/playbooks_variables.html)

---

<div class="post-metadata">

**Author:** ![Mahmut](https://avatars.discourse-cdn.com/v4/letter/m/278dde/32.png) [@Mahmut](https://forum.ansible.com/u/Mahmut)\
**Post date:** [October 27, 2019, 9:25am UTC](https://forum.ansible.com/t/how-to-play-a-task-for-only-one-host-spesificly-in-inventory-list/31550/5 "2019-10-27T09:25:26Z")

</div>

thank you. But now I have another problem when I use eos\_bgp module.  
Could you please help me for this?

92.168.81.139\> EXEC /bin/sh -c ‘rm -f -r /root/.ansible/tmp/ansible-local-552878TrIHQ/ansible-tmp-1572167779.68-135610018810920/ \> /dev/null 2\>&1 && sleep 0’  
The full traceback is:  
File “/tmp/ansible\_eos\_bgp\_payload\_4vikljo8/ **main**.py”, line 386, in main  
result = module.edit\_config(config\_filter=‘| section bgp’)  
File “/tmp/ansible\_eos\_bgp\_payload\_4vikljo8/ansible\_eos\_bgp\_payload.zip/ansible/module\_utils/network/eos/providers/module.py”, line 56, in edit\_config  
current\_config = self.connection.get\_config(flags=config\_filter)  
File “/tmp/ansible\_eos\_bgp\_payload\_4vikljo8/ansible\_eos\_bgp\_payload.zip/ansible/module\_utils/connection.py”, line 186, in **rpc**  
raise ConnectionError(to\_text(msg, errors=‘surrogate\_then\_replace’), code=code)

fatal: [192.168.81.139]: FAILED! =\> {  
“changed”: false,  
“invocation”: {  
“module\_args”: {  
“config”: {  
“address\_family”: null,  
“bgp\_as”: 100,  
“log\_neighbor\_changes”: true,  
“neighbors”: [  
{  
“description”: null,  
“ebgp\_multihop”: null,  
“enabled”: null,  
“maximum\_prefix”: null,  
“neighbor”: “192.168.0.2”,  
“password”: null,  
“peer\_group”: null,  
“remote\_as”: 101,  
“remove\_private\_as”: null,  
“route\_reflector\_client”: null,  
“timers”: {  
“holdtime”: 360,  
“keepalive”: 300  
},  
“update\_source”: null  
}  
],  
“networks”: null,  
“redistribute”: null,  
“router\_id”: “10.0.0.1”  
},  
“operation”: “merge”  
}  
},  
“msg”: “Method not found”  
}

PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
192.168.81.139 : ok=8 changed=2 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0

[root@localhost ansible-tests]#

Kai Stian Olstad \<[ansible-project+list@olstad.com](mailto:ansible-project%2Blist@olstad.com)\>, 27 Eki 2019 Paz, 11:55 tarihinde şunu yazdı:

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [October 29, 2019, 9:11pm UTC](https://forum.ansible.com/t/how-to-play-a-task-for-only-one-host-spesificly-in-inventory-list/31550/6 "2019-10-29T21:11:47Z")

</div>

I'm sorry, but I can't help with that.  
Recommend you start a new thread so subject reflect your new issue, and when you do please provide more information than you did here.
