I’m new to Ansible Automation and hopefully this is a simple fix-
Running Ansible Tower 2.4.4 on Windows Server 2012 R2.
I’m using the ios_command and ios_config modules.
I have a group called “XYZ” that contains hosts “1.1.1.1” and “2.2.2.2”. I want each task in the playbook to only attempt SSH to a specific host within the group.
Here’s the problem:
-The playbook will attempt to SSH to all hosts in the group by default on the first task. It will succeed on the first host specified with vars, but fail on every host after, even if I’m passing through the creds correctly.
-I need to set “connection”: to “local” for the ios_command, and ios_config modules to work. However if I try to use the “delegate_to” command, it fails because it wants to SSH but sees the connection as local.
Is there any way to limit the playbook connections to a specific host within each task? I don’t want to create a separate playbook for each host, and I don’t want to create a separate group for each host within Ansible Tower.
Sample config:
- name: XYZ SSH Test
hosts: XYZ
connection: local
gather_facts: false
vars:
1Switch:
host: “1.1.1.1”
username: “{{1user}}”
password: “{{1pass}}”
timeout: 60
2Switch:
host: “2.2.2.2”
username: “{{2user}}”
password: “{{2pass}}”
timeout: 60
tasks:
#get an interface on 1.1.1.1 - name: Get 1.1.1.1 interface status
run_once: true
delegate_to: 1.1.1.1
ios_command:
commands: show interface gi1/0/1
provider: “{{ 1Switch }}”
register: gi1_0_1
#get an interface on 2.2.2.2 - name: Get 2.2.2.2 interface status
run_once: true
delegate_to: 2.2.2.2
ios_command:
commands: show interface Gig 2/0/2
provider: “{{ 2Switch }}”
register: gi2_0_2