Ansible in Windows Ubuntu

Hi Rene… In the ansible, you showed us to inventory but where exactly we need to create in ubuntu… I am using a EVE-NG for network topology and windows ubuntu for ansible but facing issue. I can directly access to the device but not able to do it via ansible. Can you share that steps.

HI Shriram,

IN ansible you have to configure host file, which is located in “/etc/ansible/hosts” by default as shown in the attached screen capture.

Once you are in this directory open the hosts file using any text editor, here you can provide the devices. If you have an dns server or you have configured /etc/hosts file you can mention hostnames of devices or else you can simply mention ip address in the hosts file. Attaching screen capture for your reference.

As you can see I use a DNS server to resolve names to IP hence I used host names i.e SW1 and R1, but you can simply mention IP addresses instead. It doesn’t matter.

Alternatively you can specify non default path by using " -i "

Regards,
Teja

1 Like

Hello Teja

Thanks for sharing your solution, your contribution is appreciated!

Laz

1 Like

Hi Thanks for sharing information. I donot have dns server but when I tried to declare
in host file as below: I am not able to use R1 as Ping or any other utility.
[routers]

192.168.1.11 R1
192.168.1.12 R2

-> Even When I tried to run below code i am getting error
ansible all -i 192.168.1.11, -c network_cli -u admin -k -m ios_facts -e ansible_network_os=ios

192.168.1.11 | UNREACHABLE! => {
“changed”: false,
“msg”: “Authentication or permission failure. In some cases, you may have been able to authenticate and did not have permissions on the target directory. Consider changing the remote tmp path in ansible.cfg to a path rooted in “/tmp”. Failed command was: ( umask 77 && mkdir -p “echo /home/nakul/.ansible/tmp/ansible-local-850tkbma0g/ansible-tmp-1594901487.109081-204798059538934” && echo ansible-tmp-1594901487.109081-204798059538934=”echo /home/nakul/.ansible/tmp/ansible-local-850tkbma0g/ansible-tmp-1594901487.109081-204798059538934" ), exited with result 1, stdout output: ansible-tmp-1594901487.109081-204798059538934=/home/nakul/.ansible/tmp/ansible-local-850tkbma0g/ansible-tmp-1594901487.109081-204798059538934\n",
“unreachable”: true
}

Even if I put sudo before the command it gives warning of not having paramiko installed…and I have paramiko installed in my ubuntu.

paramiko 2.7.1
pip 20.0.2
pyasn1 0.4.2
pyasn1-modules 0.2.1

HI Shriram,

I am using the following topology, I am attaching my router and switch config file for your reference.
SW1.txt (3.8 KB) R1.txt (3.8 KB)

nothing fancy in configuration of R1 and SW1 just some basic routing, NAT and SSH on both devices.

Once I have configured the router and switch I tried to login using normal ssh, attaching the screen capture to check connectivity as we know ansible using ssh as transport mechanism if we are not able to login in to devices with ssh neither will ansible, so make sure you are able to login first.

next as mentioned in previous answer I have changed the connection type to “local” and ran the ad-hoc command as shown in the below screen capture, It ran just fine. See below for reference.

the command i ran: ansible SW1, -c local -u teja --ask-pass -m ios_facts -e gather_subset=all

let me give you a breakdown of ad-hoc command:

“ansible” invoking ansible
“SW1” letting know the ansible that I am going run this ad-hoc command against SW1
“-c local” I am running this to execute the command on controller rather than on remote device( Ansible modules are nothing but python scripts).
"-u " defining user name (same as used to login in to cisco device)
“–ask-pass” prompts to key in ssh password while ansible controller tries to connect on remote device
“-m ios_facts” module name
“-e gather_subset=all” arguement

Although ad-hoc commands are handy dandy I would recommend you to use playbooks instead. I have written a playbook which accomplishes similar task,

You dont really need to mention username and password in the playbook it can be mentioned in host_vars or group_vars file or alternatively you can use ansible vaults or pubkey authentication method to make sure your password is not visible to anyone else.

Let me know if this works. In ansible.cfg file pls set host key checking=False

Regards,
Teja

1 Like