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

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

I guess eos_switches is a group?
Instead of using the group, just use the name of the switch

- hosts: my_lonely_switch

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 ile gönderildi

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

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

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>, 27 Eki 2019 Paz, 11:55 tarihinde şunu yazdı:

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.