# Ansible in Windows Ubuntu

**URL:** <https://forum.networklessons.com/t/ansible-in-windows-ubuntu/11781>\
**Category:** Network Automation\
**Created:** [July 15, 2020, 1:45pm UTC](https://forum.networklessons.com/t/ansible-in-windows-ubuntu/11781 "2020-07-15T13:45:39Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![shriramtrimal19](https://cdn-forum.networklessons.com/letter_avatar_proxy/v4/letter/s/e68b1a/32.png) [@shriramtrimal19](https://forum.networklessons.com/u/shriramtrimal19)\
**Post date:** [July 15, 2020, 1:45pm UTC](https://forum.networklessons.com/t/ansible-in-windows-ubuntu/11781/1 "2020-07-15T13:45:39Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![anchadharaniteja](https://cdn-forum.networklessons.com/letter_avatar_proxy/v4/letter/a/977dab/32.png) [@anchadharaniteja](https://forum.networklessons.com/u/anchadharaniteja)\
**Post date:** [July 15, 2020, 6:38pm UTC](https://forum.networklessons.com/t/ansible-in-windows-ubuntu/11781/2 "2020-07-15T18:38:20Z")

</div>

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.

 ![Screenshot from 2020-07-16 02-34-45](https://cdn-forum.networklessons.com/uploads/default/original/2X/4/49307e998e1a4cfd9d84ae180028cf0f650b9b82.png)

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.

 ![Screenshot from 2020-07-16 02-41-18](https://cdn-forum.networklessons.com/uploads/default/original/2X/5/53e274b0a0ead2d910ed67f826864f34601e8ffd.png)

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

---

<div class="post-metadata">

**Author:** ![lagapidis](https://cdn-forum.networklessons.com/user_avatar/forum.networklessons.com/lagapidis/32/4949_2.png) [@lagapidis](https://forum.networklessons.com/u/lagapidis)\
**Post date:** [July 16, 2020, 5:10am UTC](https://forum.networklessons.com/t/ansible-in-windows-ubuntu/11781/3 "2020-07-16T05:10:47Z")

</div>

Hello Teja

Thanks for sharing your solution, your contribution is appreciated!

Laz

---

<div class="post-metadata">

**Author:** ![shriramtrimal19](https://cdn-forum.networklessons.com/letter_avatar_proxy/v4/letter/s/e68b1a/32.png) [@shriramtrimal19](https://forum.networklessons.com/u/shriramtrimal19)\
**Post date:** [July 16, 2020, 12:16pm UTC](https://forum.networklessons.com/t/ansible-in-windows-ubuntu/11781/4 "2020-07-16T12:16:33Z")

</div>

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`

```auto
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.

 ![image](https://cdn-forum.networklessons.com/uploads/default/original/2X/0/08241734bfaa9c16e10720897f2354773d2b7b55.png)

```auto
paramiko 2.7.1
pip 20.0.2
pyasn1 0.4.2
pyasn1-modules 0.2.1

```

---

<div class="post-metadata">

**Author:** ![anchadharaniteja](https://cdn-forum.networklessons.com/letter_avatar_proxy/v4/letter/a/977dab/32.png) [@anchadharaniteja](https://forum.networklessons.com/u/anchadharaniteja)\
**Post date:** [July 16, 2020, 1:39pm UTC](https://forum.networklessons.com/t/ansible-in-windows-ubuntu/11781/6 "2020-07-16T13:39:29Z")

</div>

HI Shriram,

 ![Screenshot from 2020-07-16 21-19-05](https://cdn-forum.networklessons.com/uploads/default/original/2X/d/d5fbef927bab4741cbfaaf042dd6db30a8a52943.png)

I am using the following topology, I am attaching my router and switch config file for your reference.  
[SW1.txt](https://forum.networklessons.com/uploads/short-url/lv5z6KwV1oA23WrNSPHiGsE6BNS.txt) (3.8 KB) [R1.txt](https://forum.networklessons.com/uploads/short-url/jRpeCytUM6CT86To78BBqCEMBXE.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.

 ![Screenshot from 2020-07-16 21-08-07](https://cdn-forum.networklessons.com/uploads/default/original/2X/8/824013146a0a9db69c0f418411fab261382c0746.png) ![Screenshot from 2020-07-16 21-07-20](https://cdn-forum.networklessons.com/uploads/default/original/2X/e/e4023c02897528847d1a0d13f7bf01344b8c79f9.png)

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.

 ![Screenshot from 2020-07-16 21-17-17](https://cdn-forum.networklessons.com/uploads/default/original/2X/e/ec2221fa6139e97d54eb2db245f1afb4c8f08038.png)

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,

 ![Screenshot from 2020-07-16 21-14-19](https://cdn-forum.networklessons.com/uploads/default/original/2X/c/cbdf9f5b7bb5eb1de21f259fe094703ae8a0eb4e.png)

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

---

<div class="post-metadata">

**Author:** ![Giovanni](https://cdn-forum.networklessons.com/letter_avatar_proxy/v4/letter/g/7ea924/32.png) [@Giovanni](https://forum.networklessons.com/u/Giovanni)\
**Post date:** [March 23, 2022, 9:50pm UTC](https://forum.networklessons.com/t/ansible-in-windows-ubuntu/11781/7 "2022-03-23T21:50:33Z")

</div>

Is possible to use ansible to ping hosts only without ssh ?

Yes, I found the answer of my question.

```auto
ansible all -e ansible_connection=local -m command -a 'ping {{inventory_hostname}} -c 4'

```

---

<div class="post-metadata">

**Author:** ![lagapidis](https://cdn-forum.networklessons.com/user_avatar/forum.networklessons.com/lagapidis/32/4949_2.png) [@lagapidis](https://forum.networklessons.com/u/lagapidis)\
**Post date:** [March 25, 2022, 6:02am UTC](https://forum.networklessons.com/t/ansible-in-windows-ubuntu/11781/8 "2022-03-25T06:02:22Z")

</div>

Hello Giovanni

The most common implementation uses Ansible over a secure SSH connection. However, it is possible to connect using other methods, including Telnet and even SNMP. This can be done by choosing the appropriate connection plugin. More information about connection plugins can be found at this Ansible documentation link:

> **[Connection plugins — Ansible Community Documentation](https://docs.ansible.com/ansible/latest/plugins/connection.html)**

I hope this has been helpful!

Laz
