# Ansible Lab Setup

**URL:** <https://forum.ansible.com/t/ansible-lab-setup/4819>\
**Category:** Get Help\
**Tags:** windows, ssh, config, vmware, ubuntu\
**Created:** [April 8, 2024, 3:28pm UTC](https://forum.ansible.com/t/ansible-lab-setup/4819 "2024-04-08T15:28:36Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon99813807](https://avatars.discourse-cdn.com/v4/letter/a/ba8739/32.png) [@anon99813807](https://forum.ansible.com/u/anon99813807)\
**Post date:** [April 8, 2024, 3:28pm UTC](https://forum.ansible.com/t/ansible-lab-setup/4819/1 "2024-04-08T15:28:36Z")

</div>

Hello

I am trying to setup a home lab to support an Ansible course I am taking on Udemy. I am following the procedures from the instructor, who seems to not support his course anymore via Q&A. I am struggling with the ssh part to get a ping to the target VM’s. New to both Ansible and Ubuntu and always seem to struggle with keys in linux configs.

Here is my setup:

Windows 11 computer using VMware Workstation for the VM’s. The VM’s are Ubuntu VM’s. VM’s as of now are:

Control3 (where ansible is)

User is ansible on both control3 and db02

The course has an ansible directory in **/home/ansible** directory which I have.

There is also a **.ssh** directory there with the key files and **authorized\_hosts** file

db02 (for a target system, will do more when I get ping to work)

Running **ansible –list-hosts all** does give me the list of hosts so that seems fine.

I am able to ssh into both control and db02 from my Windows 11 computer

There were procedures in the course to generate **ssh-keygen -t rsa** then to past the contents of the public file to an authorized\_hosts file on I am assuming the control computer. I have done that with also doing generate **ssh-keygen -t ecdsa**

From the control3 I then run **ansible -m ping db02** (right now just one host for the target until I get that to work) I get the following:

The authenticity of host ‘db02 (192.168.42.141)’ can’t be established.

ECDSA key fingerprint is 5b:ae:e0:a7:9c:08:85:0c:ec:60:e2:77:e6:d0:f3:67.

Are you sure you want to continue connecting (yes/no)? no

**db02 | UNREACHABLE! =\> {**

**“changed”: false,**

**“msg”: “Failed to connect to the host via ssh: Host key verification failed.”,**

**“unreachable”: true**

**}**

I am entering no right now as in the past when I hit yes it still didn’t work.

What am I doing wrong here?

Thanks.

---

<div class="post-metadata">

**Author:** ![Denney-tech](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/denney-tech/32/1556_2.png) [@Denney-tech](https://forum.ansible.com/u/Denney-tech)\
**Post date:** [April 8, 2024, 3:45pm UTC](https://forum.ansible.com/t/ansible-lab-setup/4819/2 "2024-04-08T15:45:11Z")

</div>

2 things.

1. You need to generate your ssh private/public key pair on control3, and add the public key to `authorized_keys` on each host that is _remote_ to your ansible control node. (db02)
2. Your specific error message is telling you that control3 doesn’t know db02’s ssh _host key_ and asking if you want to continue anyways. This is an ssh message, not an Ansible one, but can generally be ignored in lab environments. You’ll need to disable strict host key checking for ssh. This is easy enough to do in your ansible.cfg:

```ini
[defaults]
host_key_checking = false

```

---

<div class="post-metadata">

**Author:** ![anon99813807](https://avatars.discourse-cdn.com/v4/letter/a/ba8739/32.png) [@anon99813807](https://forum.ansible.com/u/anon99813807)\
**Post date:** [April 8, 2024, 5:08pm UTC](https://forum.ansible.com/t/ansible-lab-setup/4819/3 "2024-04-08T17:08:30Z")

</div>

Thanks. I added the host\_key\_checking = false to the ansible.cfg file and retried but still get error:

ansible@control3:/etc/ansible$ sudo ansible -m ping db02  
db02 | UNREACHABLE! =\> {  
“changed”: false,  
“msg”: “Failed to connect to the host via ssh: Permission denied (publickey,password).”,  
“unreachable”: true  
}

I did a ssh to db02 from control3 and that worked per below:  
ansible@control3:/etc/ansible$ ssh [ansible@192.168.42.141](mailto:ansible@192.168.42.141)  
Welcome to Ubuntu 14.04.6 LTS (GNU/Linux 4.4.0-142-generic x86\_64)

- Documentation:

System information as of Mon Apr 8 13:02:27 EDT 2024

System load: 0.0 Memory usage: 2% Processes: 177  
Usage of /: 20.9% of 5.78GB Swap usage: 0% Users logged in: 0

Graph this data and manage this system at:  
[https://landscape.canonical.com/](https://landscape.canonical.com/)

40 packages can be updated.  
30 updates are security updates.

New release ‘16.04.7 LTS’ available.  
Run ‘do-release-upgrade’ to upgrade to it.

Your Hardware Enablement Stack (HWE) is supported until April 2019.  
Last login: Mon Apr 8 12:54:03 2024 from control3  
ansible@db02:~$

---

<div class="post-metadata">

**Author:** ![Denney-tech](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/denney-tech/32/1556_2.png) [@Denney-tech](https://forum.ansible.com/u/Denney-tech)\
**Post date:** [April 8, 2024, 5:19pm UTC](https://forum.ansible.com/t/ansible-lab-setup/4819/4 "2024-04-08T17:19:09Z")

</div>

You should pretty much never `sudo ansible`. This changed your authentication context to root@control3 and without specifying any user, ansible will try to connect to root@db02 instead of the expected ansible@db02.

If you specified `-u/--user ansible`, it would probably still fail because ansible will be trying to use root@control3’s ssh keys instead of ansible@control3’s.

---

<div class="post-metadata">

**Author:** ![anon99813807](https://avatars.discourse-cdn.com/v4/letter/a/ba8739/32.png) [@anon99813807](https://forum.ansible.com/u/anon99813807)\
**Post date:** [April 8, 2024, 6:29pm UTC](https://forum.ansible.com/t/ansible-lab-setup/4819/5 "2024-04-08T18:29:31Z")

</div>

Thanks for the help.

I wondered about that. Part of the problem is I am confused on how the instructor setup and on what computers.

So when I run the command with out sudo I get:

db02 | FAILED! =\> {  
“msg”: “Cannot write to ControlPath /home/ansible/.ansible/cp”

There is a /home/ansible/.ansible/cp with these properties:

drwx------ 4 ansible ansible 4096 Apr 8 10:29 ./  
drwxr-xr-x 6 ansible ansible 4096 Apr 8 14:26 …/  
drwx------ 2 root root 4096 Apr 8 10:29 cp/  
drwx------ 2 ansible ansible 4096 Apr 8 14:26 tmp/

Where should my ansible directories be?

---

<div class="post-metadata">

**Author:** ![Denney-tech](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/denney-tech/32/1556_2.png) [@Denney-tech](https://forum.ansible.com/u/Denney-tech)\
**Post date:** [April 8, 2024, 7:08pm UTC](https://forum.ansible.com/t/ansible-lab-setup/4819/6 "2024-04-08T19:08:54Z")

</div>

That might be because cp is owned by root. `sudo chown -R ansible:ansible /home/ansible`

---

<div class="post-metadata">

**Author:** ![anon99813807](https://avatars.discourse-cdn.com/v4/letter/a/ba8739/32.png) [@anon99813807](https://forum.ansible.com/u/anon99813807)\
**Post date:** [April 8, 2024, 9:06pm UTC](https://forum.ansible.com/t/ansible-lab-setup/4819/7 "2024-04-08T21:06:30Z")

</div>

> [@Denney-tech](#):
>
> sudo chown -R ansible:ansible /home/ansible

YES!! I think that was it as far as the ping goes. Did a couple of others steps but I think that got me to good pings!

**ansible@control3:~$ ansible -m ping all**  
**control3 | SUCCESS =\> {**  
\*\* “ansible\_facts”: {\*\*  
\*\* “discovered\_interpreter\_python”: “/usr/bin/python”\*\*  
\*\* },\*\*  
\*\* “changed”: false,\*\*  
\*\* “ping”: “pong”\*\*  
**}**  
**web03 | SUCCESS =\> {**  
\*\* “ansible\_facts”: {\*\*  
\*\* “discovered\_interpreter\_python”: “/usr/bin/python”\*\*  
\*\* },\*\*  
\*\* “changed”: false,\*\*  
\*\* “ping”: “pong”\*\*  
**}**  
**db02 | SUCCESS =\> {**  
\*\* “ansible\_facts”: {\*\*  
\*\* “discovered\_interpreter\_python”: “/usr/bin/python”\*\*  
\*\* },\*\*  
\*\* “changed”: false,\*\*  
\*\* “ping”: “pong”\*\*

Now the command  
ansible@control3:~$ ansible -m command -a “hostname”  
returns which I assume is good:

**control3 | CHANGED | rc=0 \>\>**  
**control3**  
**web03 | CHANGED | rc=0 \>\>**  
**web03**  
**db02 | CHANGED | rc=0 \>\>**  
**db02**

On I go. Thanks for the help, very much appreciated.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [May 8, 2024, 9:07pm UTC](https://forum.ansible.com/t/ansible-lab-setup/4819/8 "2024-05-08T21:07:02Z")

</div>

Closed on May 8, 2024, 9:07pm UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
