Ensure that the necessary Ansible playbook, basic_checks.yml, is available.
Run the following command: ```ansible-playbook basic_checks.yml
##### Expected:
The playbook should execute without any errors and successfully gather facts for basic system checks.
##### Research:
During the execution of the playbook, the following error occurred:
TASK [Gathering Facts]
fatal: [docker_container]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: ssh: connect to host localhost port 2222: Connection refused", "unreachable": true}
The error message indicates that the playbook is unable to connect to the host via SSH, resulting in an unreachable state. It seems there is an issue with the SSH connection to the ```docker_container``` host.
##### Additional Notes:
I used the following command to check the status of the SSH service on my macOS system: ```launchctl list | grep ssh``` and it outputs:
```28857 0 com.openssh.ssh-agent```.
Based on the output, it seems that the ```com.openssh.ssh-agent``` service is running on my macOS system. Since the SSH agent service is running, the issue might not be related to SSH service availability on my macOS machine.
##### Reproduction:
1. Clone the pricer repository.
2. Ensure that the necessary Ansible playbook, basic_checks.yml, is available.
3. Run the following command: ```ansible-playbook basic_checks.yml
```
##### Expected:
The playbook should execute without any errors and successfully gather facts for basic system checks.
##### Research:
During the execution of the playbook, the following error occurred:
```
TASK [Gathering Facts]
fatal: [docker_container]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: ssh: connect to host localhost port 2222: Connection refused", "unreachable": true}
```
The error message indicates that the playbook is unable to connect to the host via SSH, resulting in an unreachable state. It seems there is an issue with the SSH connection to the ```docker_container``` host.
##### Additional Notes:
I used the following command to check the status of the SSH service on my macOS system: ```launchctl list | grep ssh``` and it outputs:
```28857 0 com.openssh.ssh-agent```.
Based on the output, it seems that the ```com.openssh.ssh-agent``` service is running on my macOS system. Since the SSH agent service is running, the issue might not be related to SSH service availability on my macOS machine.
The issue here is that although your MacOS system is listening on port 22 (SSH), Ansible needs to connect to the docker container, which is available via port 2222, as per this line here:
(We have to use this method because there aren't any network tools in the container by default.)
I think the container isn't really being started, so you should check by doing this:
ansible -C -m community.docker.docker_container -a "name=pricer image=dev state=present" localhost
Note that the arguments are in YAML "flow style" for readability, because otherwise you'd have to split the command up into multiple lines. Flow style arguments are exactly equivalent to their normal versions in the playbook, so e.g.
-m module_name -a "key1=value key2=value"
is the same as
module_name:
key1: value
key2: value
The issue here is that although your MacOS system is listening on port 22 (SSH), Ansible needs to connect to the docker container, which is available via port 2222, as per this line here:
https://gogs.gtsplab.com:5432/SVIG/pricer/src/main/basic_checks.yml#L39
What needs to happen is that ansible needs to connect to the container port (2222), which is really managed by docker, not your host sshd.
You can see what programs are listening on what ports on your Mac by using `lsof`:
```
$ lsof +c 0 -i TCP:2222
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
com.docker.backend 22663 j 562u IPv6 0xbe03ad2e22b626d9 0t0 TCP *:rockwell-csp2 (LISTEN)
```
(The `+c 0` argument will print the entire process name, instead of an abbreviation.)
If the port is being forwarded by docker, then you can ask docker where it's forwarding it to:
```
$ docker port pricer
22/tcp -> 0.0.0.0:2222
```
If that's working, then you need to ask the container what the problem is:
```
docker exec -it pricer /bin/bash
\# cat /proc/net/tcp
sl local_address rem_address st tx_queue rx_queue tr tm->when retrnsmt uid timeout inode
0: 00000000:0016 00000000:0000 0A 00000000:00000000 00:00000000 00000000 0 0 828399 1 0000000000000000 100 0 0 10 0
```
(We have to use this method because there aren't any network tools in the container by default.)
I think the container isn't really being started, so you should check by doing this:
```
ansible -C -m community.docker.docker_container -a "name=pricer image=dev state=present" localhost
```
Note that the arguments are in YAML "flow style" for readability, because otherwise you'd have to split the command up into multiple lines. Flow style arguments are exactly equivalent to their normal versions in the playbook, so e.g.
`-m module_name -a "key1=value key2=value"`
is the same as
```
module_name:
key1: value
key2: value
```
Looks like docker isn't forwarding the port, so you'll have to recreate the container from the dev image you built, and set up port forwarding correctly. The playbook should do this automatically.
Looks like docker isn't forwarding the port, so you'll have to recreate the container from the `dev` image you built, and set up port forwarding correctly. The playbook should do this automatically.
The lack of output from "docker port pricer" tells me that the port still isn't being forwarded from your MacOS localhost:2222 -> Container ssh:22, so you'll have to fix that.
Running the ansible module like you did might work, but you're running it in check mode (-C), so remove that.
The lack of output from "docker port pricer" tells me that the port still isn't being forwarded from your MacOS localhost:2222 -> Container ssh:22, so you'll have to fix that.
Running the ansible module like you did might work, but you're running it in check mode (`-C`), so remove that.
PLAY [Prepare wsl distribution to run snapd] *******************************************************************************
TASK [Gathering Facts] *****************************************************************************************************
[WARNING]: Platform darwin on host commander is using the discovered Python interpreter at
/Library/Frameworks/Python.framework/Versions/3.11/bin/python3.11, but future installation of another Python interpreter
could change the meaning of that path. See https://docs.ansible.com/ansible-
core/2.15/reference_appendices/interpreter_discovery.html for more information.
ok: [commander]
TASK [Install Docker] ******************************************************************************************************
skipping: [commander]
TASK [Start Docker service] ************************************************************************************************
skipping: [commander]
PLAY [Start Docker for Desktop] ********************************************************************************************
TASK [Start Docker for Desktop on MacOS] ***********************************************************************************
changed: [commander]
TASK [Install requests module] *********************************************************************************************
ok: [commander]
TASK [Start the pricer container normally] *********************************************************************************
ok: [commander]
TASK [Debug container Config.Hostname] *************************************************************************************
ok: [commander] => {
"container.Config.Hostname": "VARIABLE IS NOT DEFINED!"
}
PLAY [Basic system checks] *************************************************************************************************
TASK [Gathering Facts] *****************************************************************************************************
fatal: [docker_container]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: root@localhost: Permission denied (publickey).", "unreachable": true}
PLAY RECAP *****************************************************************************************************************
commander : ok=5 changed=1 unreachable=0 failed=0 skipped=2 rescued=0 ignored=0
docker_container : ok=0 changed=0 unreachable=1 failed=0 skipped=0 rescued=0 ignored=0
(base) sloetjeswong@Sloetjess-Air pricer % ansible-playbook basic_checks.yml
```
PLAY [Prepare wsl distribution to run snapd] *******************************************************************************
TASK [Gathering Facts] *****************************************************************************************************
[WARNING]: Platform darwin on host commander is using the discovered Python interpreter at
/Library/Frameworks/Python.framework/Versions/3.11/bin/python3.11, but future installation of another Python interpreter
could change the meaning of that path. See https://docs.ansible.com/ansible-
core/2.15/reference_appendices/interpreter_discovery.html for more information.
ok: [commander]
TASK [Install Docker] ******************************************************************************************************
skipping: [commander]
TASK [Start Docker service] ************************************************************************************************
skipping: [commander]
PLAY [Start Docker for Desktop] ********************************************************************************************
TASK [Start Docker for Desktop on MacOS] ***********************************************************************************
changed: [commander]
TASK [Install requests module] *********************************************************************************************
ok: [commander]
TASK [Start the pricer container normally] *********************************************************************************
ok: [commander]
TASK [Debug container Config.Hostname] *************************************************************************************
ok: [commander] => {
"container.Config.Hostname": "VARIABLE IS NOT DEFINED!"
}
PLAY [Basic system checks] *************************************************************************************************
TASK [Gathering Facts] *****************************************************************************************************
fatal: [docker_container]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: root@localhost: Permission denied (publickey).", "unreachable": true}
PLAY RECAP *****************************************************************************************************************
commander : ok=5 changed=1 unreachable=0 failed=0 skipped=2 rescued=0 ignored=0
docker_container : ok=0 changed=0 unreachable=1 failed=0 skipped=0 rescued=0 ignored=0
```
Output: ssh: connect to host localhost port 22: Connection refused
The error shows that the SSH service is not listening on port 22 on localhost, or there is no route to that port. Possible reasons causes and actions taken:
SSH service is not running: I tried the command sudo systemsetup -setremotelogin on to reconnect.
Output: setremotelogin: Turning Remote Login on or off requires Full Disk Access privileges.
SSH is listening on a different port: I tried command ssh -i ~/.ssh/id_rsa -p 22 root@localhost. Output:ssh: connect to host localhost port 22: Connection refused. Command: ssh -i ~/.ssh/id_rsa -p 2222 root@localhost. Output: root@localhost: Permission denied (publickey).
Check if root login is allowed: I checked the SSH configuration file on the server (/etc/ssh/sshd_config) and looked for the line that says PermitRootLogin. It says PermitRootLogin prohibit-password, which allows root login only with key authentication.
Since I'm getting Permission denied (publickey) when trying to connect to the server as root, that means SSH isn't accepting my private key (I checked the fingerprints of my private and public keys. They are indeed corresponding and in pairs, which is weird since I seem to go through all the possible causes).
`(base) sloetjeswong@Sloetjess-Air pricer % ssh -i ~/.ssh/id_rsa root@localhost`
Output:
`ssh: connect to host localhost port 22: Connection refused`
The error shows that the SSH service is not listening on port 22 on localhost, or there is no route to that port. Possible reasons causes and actions taken:
1. SSH service is not running: I tried the command `sudo systemsetup -setremotelogin on` to reconnect.
Output: `setremotelogin: Turning Remote Login on or off requires Full Disk Access privileges.`
2. SSH is listening on a different port: I tried command `ssh -i ~/.ssh/id_rsa -p 22 root@localhost`. Output:`ssh: connect to host localhost port 22: Connection refused`. Command: `ssh -i ~/.ssh/id_rsa -p 2222 root@localhost`. Output: `root@localhost: Permission denied (publickey)`.
3. Check if root login is allowed: I checked the SSH configuration file on the server (`/etc/ssh/sshd_config`) and looked for the line that says `PermitRootLogin`. It says `PermitRootLogin prohibit-password`, which allows root login only with key authentication.
4. Since I'm getting `Permission denied (publickey)` when trying to connect to the server as root, that means SSH isn't accepting my private key (I checked the fingerprints of my private and public keys. They are indeed corresponding and in pairs, which is weird since I seem to go through all the possible causes).
Might be the problem with Mac OS setting. I changed the "Sharing > Remote Login" and its list of authorized users. Changed it to "All Users". But the playbook still reports the same error at the same place.
Might be the problem with Mac OS setting. I changed the "Sharing > Remote Login" and its list of authorized users. Changed it to "All Users". But the playbook still reports the same error at the same place.
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Reproduction:
TASK [Gathering Facts]
fatal: [docker_container]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: ssh: connect to host localhost port 2222: Connection refused", "unreachable": true}
The issue here is that although your MacOS system is listening on port 22 (SSH), Ansible needs to connect to the docker container, which is available via port 2222, as per this line here:
https://gogs.gtsplab.com:5432/SVIG/pricer/src/main/basic_checks.yml#L39
What needs to happen is that ansible needs to connect to the container port (2222), which is really managed by docker, not your host sshd.
You can see what programs are listening on what ports on your Mac by using
lsof:(The
+c 0argument will print the entire process name, instead of an abbreviation.)If the port is being forwarded by docker, then you can ask docker where it's forwarding it to:
If that's working, then you need to ask the container what the problem is:
(We have to use this method because there aren't any network tools in the container by default.)
I think the container isn't really being started, so you should check by doing this:
Note that the arguments are in YAML "flow style" for readability, because otherwise you'd have to split the command up into multiple lines. Flow style arguments are exactly equivalent to their normal versions in the playbook, so e.g.
-m module_name -a "key1=value key2=value"is the same as
Actions Taken:
Outputs nothing on this command.
Still outputs nothing on this command.
Output:
Looks like docker isn't forwarding the port, so you'll have to recreate the container from the
devimage you built, and set up port forwarding correctly. The playbook should do this automatically.Output:
The lack of output from "docker port pricer" tells me that the port still isn't being forwarded from your MacOS localhost:2222 -> Container ssh:22, so you'll have to fix that.
Running the ansible module like you did might work, but you're running it in check mode (
-C), so remove that.(base) sloetjeswong@Sloetjess-Air pricer % ansible -m community.docker.docker_container -a "name=pricer image=dev state=present" localhost
localhost | SUCCESS => {
"changed": false,
"container": {
"AppArmorProfile": "",
"Args": [],
"Config": {
"AttachStderr": true,
"AttachStdin": false,
"AttachStdout": true,
"Cmd": [
"/lib/systemd/systemd"
],
"Domainname": "",
"Entrypoint": null,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
],
"ExposedPorts": {
"22/tcp": {},
"9515/tcp": {}
},
"Hostname": "dd18ab24e295",
"Image": "dev",
"Labels": {
"org.opencontainers.image.ref.name": "ubuntu",
"org.opencontainers.image.version": "22.04"
},
"OnBuild": null,
"OpenStdin": false,
"StdinOnce": false,
"Tty": false,
"User": "",
"Volumes": null,
"WorkingDir": ""
},
"Created": "2023-06-14T20:15:35.116849013Z",
"Driver": "overlay2",
"ExecIDs": null,
"GraphDriver": {
"Data": {
"LowerDir": "/var/lib/docker/overlay2/764a18508263611b418c4a6adc124c5e59693aeaa6539f807e68bd1eba3c5b18-init/diff:/var/lib/docker/overlay2/xif49umsfizi30mhm6svnrz8q/diff:/var/lib/docker/overlay2/5p0vlsajnh0gglohv95wn3nlq/diff:/var/lib/docker/overlay2/juodxxoz5ovczg0rk94k1ggwv/diff:/var/lib/docker/overlay2/4q3dsjwboijg1gh3ggvuhk8oc/diff:/var/lib/docker/overlay2/4ll8tmkh95dnuegkyjhn1hv1e/diff:/var/lib/docker/overlay2/lthckazc34p71t2xdatswr0r8/diff:/var/lib/docker/overlay2/i0kseythiu523pp4c0wu0eojk/diff:/var/lib/docker/overlay2/q2c0v23vezuik0cawjvoomcpr/diff:/var/lib/docker/overlay2/obeq2a1o7m6tokb5w4b6vjshp/diff:/var/lib/docker/overlay2/18ac73700ca0a74ae6f629447534fa49105bc7bac90860bcb2b1eabbf2fc3434/diff",
"MergedDir": "/var/lib/docker/overlay2/764a18508263611b418c4a6adc124c5e59693aeaa6539f807e68bd1eba3c5b18/merged",
"UpperDir": "/var/lib/docker/overlay2/764a18508263611b418c4a6adc124c5e59693aeaa6539f807e68bd1eba3c5b18/diff",
"WorkDir": "/var/lib/docker/overlay2/764a18508263611b418c4a6adc124c5e59693aeaa6539f807e68bd1eba3c5b18/work"
},
"Name": "overlay2"
},
"HostConfig": {
"AutoRemove": false,
"Binds": [
"/sys/fs/cgroup:/sys/fs/cgroup:ro"
],
"BlkioDeviceReadBps": null,
"BlkioDeviceReadIOps": null,
"BlkioDeviceWriteBps": null,
"BlkioDeviceWriteIOps": null,
"BlkioWeight": 0,
"BlkioWeightDevice": null,
"CapAdd": null,
"CapDrop": null,
"Cgroup": "",
"CgroupParent": "",
"CgroupnsMode": "private",
"ConsoleSize": [
0,
0
],
"ContainerIDFile": "",
"CpuCount": 0,
"CpuPercent": 0,
"CpuPeriod": 0,
"CpuQuota": 0,
"CpuRealtimePeriod": 0,
"CpuRealtimeRuntime": 0,
"CpuShares": 0,
"CpusetCpus": "",
"CpusetMems": "",
"DeviceCgroupRules": null,
"DeviceRequests": null,
"Devices": null,
"Dns": null,
"DnsOptions": null,
"DnsSearch": null,
"ExtraHosts": null,
"GroupAdd": null,
"IOMaximumBandwidth": 0,
"IOMaximumIOps": 0,
"IpcMode": "private",
"Isolation": "",
"Links": null,
"LogConfig": {
"Config": {},
"Type": "json-file"
},
"MaskedPaths": null,
"Memory": 0,
"MemoryReservation": 0,
"MemorySwap": 0,
"MemorySwappiness": null,
"NanoCpus": 0,
"NetworkMode": "default",
"OomKillDisable": null,
"OomScoreAdj": 0,
"PidMode": "",
"PidsLimit": null,
"PortBindings": {
"22/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "2222"
}
],
"9515/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "9515"
}
]
},
"Privileged": true,
"PublishAllPorts": false,
"ReadonlyPaths": null,
"ReadonlyRootfs": false,
"RestartPolicy": {
"MaximumRetryCount": 0,
"Name": "always"
},
"Runtime": "runc",
"SecurityOpt": [
"label=disable"
],
"ShmSize": 67108864,
"UTSMode": "",
"Ulimits": null,
"UsernsMode": "",
"VolumeDriver": "",
"VolumesFrom": null
},
"HostnamePath": "/var/lib/docker/containers/dd18ab24e29582ff42bbd96c6a354b3d42f7b67f9f8bd25f3d1aa0c28aadf4be/hostname",
"HostsPath": "/var/lib/docker/containers/dd18ab24e29582ff42bbd96c6a354b3d42f7b67f9f8bd25f3d1aa0c28aadf4be/hosts",
"Id": "dd18ab24e29582ff42bbd96c6a354b3d42f7b67f9f8bd25f3d1aa0c28aadf4be",
"Image": "sha256:31c4d6255e321d5c744551b664bfa55c88aa27c423de8b1e6362c180e8c57b10",
"LogPath": "/var/lib/docker/containers/dd18ab24e29582ff42bbd96c6a354b3d42f7b67f9f8bd25f3d1aa0c28aadf4be/dd18ab24e29582ff42bbd96c6a354b3d42f7b67f9f8bd25f3d1aa0c28aadf4be-json.log",
"MountLabel": "",
"Mounts": [
{
"Destination": "/sys/fs/cgroup",
"Mode": "ro",
"Propagation": "rprivate",
"RW": false,
"Source": "/sys/fs/cgroup",
"Type": "bind"
}
],
"Name": "/pricer",
"NetworkSettings": {
"Bridge": "",
"EndpointID": "",
"Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"HairpinMode": false,
"IPAddress": "",
"IPPrefixLen": 0,
"IPv6Gateway": "",
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"MacAddress": "",
"Networks": {
"bridge": {
"Aliases": null,
"DriverOpts": null,
"EndpointID": "",
"Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAMConfig": null,
"IPAddress": "",
"IPPrefixLen": 0,
"IPv6Gateway": "",
"Links": null,
"MacAddress": "",
"NetworkID": "0c354d56d3f1d7ad20b09de0dc5e246e834a6a4d5c412fd7f357268cbbd82bc8"
}
},
"Ports": {},
"SandboxID": "7aaf182b585f378d3bc139ad8f10b8c825d3c818022208d02e79ea81edd5d1a8",
"SandboxKey": "/var/run/docker/netns/7aaf182b585f",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null
},
"Path": "/lib/systemd/systemd",
"Platform": "linux",
"ProcessLabel": "",
"ResolvConfPath": "/var/lib/docker/containers/dd18ab24e29582ff42bbd96c6a354b3d42f7b67f9f8bd25f3d1aa0c28aadf4be/resolv.conf",
"RestartCount": 1198,
"State": {
"Dead": false,
"Error": "driver failed programming external connectivity on endpoint pricer (5c75420a3bd716055de90339353ab3ca59041ca31d37ac92e4b1be55396c296c): Bind for 0.0.0.0:2222 failed: port is already allocated",
"ExitCode": 255,
"FinishedAt": "2023-06-15T21:17:04.895601381Z",
"OOMKilled": false,
"Paused": false,
"Pid": 0,
"Restarting": false,
"Running": false,
"StartedAt": "2023-06-15T21:17:04.878106839Z",
"Status": "exited"
}
}
}
(base) sloetjeswong@Sloetjess-Air pricer % ansible-playbook basic_checks.yml
How about using
ssh-addto add the key?(base) sloetjeswong@Sloetjess-Air pricer % ssh -i ~/.ssh/id_rsa root@localhostOutput:
ssh: connect to host localhost port 22: Connection refusedThe error shows that the SSH service is not listening on port 22 on localhost, or there is no route to that port. Possible reasons causes and actions taken:
sudo systemsetup -setremotelogin onto reconnect.Output:
setremotelogin: Turning Remote Login on or off requires Full Disk Access privileges.ssh -i ~/.ssh/id_rsa -p 22 root@localhost. Output:ssh: connect to host localhost port 22: Connection refused. Command:ssh -i ~/.ssh/id_rsa -p 2222 root@localhost. Output:root@localhost: Permission denied (publickey)./etc/ssh/sshd_config) and looked for the line that saysPermitRootLogin. It saysPermitRootLogin prohibit-password, which allows root login only with key authentication.Permission denied (publickey)when trying to connect to the server as root, that means SSH isn't accepting my private key (I checked the fingerprints of my private and public keys. They are indeed corresponding and in pairs, which is weird since I seem to go through all the possible causes).Might be the problem with Mac OS setting. I changed the "Sharing > Remote Login" and its list of authorized users. Changed it to "All Users". But the playbook still reports the same error at the same place.
Checked the listening ports using:
sudo lsof -i -n -P | grep LISTENand got this output: