I am quite new to SSH servers and Ansible so this might be a dumb question.
Tried to run an Ansible playbook whilst accessing the server with a private key using the bash command below.
ansible-playbook dbserv.yml -i hosts --limit local-servers --private-key=(where I put the private key)
However, I am getting this error:
fatal: [xxx]: FAILED! => {
"changed": false,
"failed": true,
"invocation": {
"module_name": "setup"
},
"module_stderr": "Shared connection to xxx closed.\r\n",
"module_stdout": "/bin/sh: 1: /usr/bin/python2.7: not found\r\n",
"msg": "MODULE FAILURE" }
I have Python installed on my computer so I do not understand why I am getting this error.
OS environment:
Ubuntu 16.04.1
The error message you get is:
/usr/bin/python2.7: not found
Ansible requires the target machine to have Python installed in order to work properly (see Managed node requirements).
The most likely reason is that your target is Ubuntu 16.04 which does not come with Python 2 installed. In this case you need to install it or try the experimental support for Python 3.
If Python 2.7 is installed in a different directory, you can add a host variable, for example in your inventory file (assuming the hostname is xxx as in your question`):
xxx ansible_python_interpreter=/path/to/python2.7
To run modules with Python 3 (experimental), set:
xxx ansible_python_interpreter=/usr/bin/python3
Note: Ansible by default looks for /usr/bin/python, so it's likely that your playbook, inventory file, or ansible.cfg already contain settings for /usr/bin/python2.7 which does not exist on the target machine.
Related
This might seem a little confusing, but I have a server I want to SSH into but the password is kinda long and complex, I understand for security I shouldn't save my password in plain text but for my convenience, I'm not too worried. Regardless, I'm trying to make it so I can just start up a Linux distro in WSL that automatically connects me to my SSH server and logs in but I'm having trouble. My settings.json block looks kinda like:
{
"guid": "{46ca431a-3a87-5fb3-83cd-11ececc031d2}",
"hidden": false,
"name": "SSH",
"source": "Windows.Terminal.Wsl",
"commandline": "/usr/bin/sshpass -p 'password' ssh -o StrictHostKeyChecking=no user#host"
},
then when I start that distro I get:
[error 0x80070002 when launching `/usr/bin/sshpass -p 'password' ssh -o StrictHostKeyChecking=no user#host']
Is there another way to do this? And yes I have sshpass installed on literally all my distros just to be 100% sure. I googled around for an sshpass Windows version but can't find it. I've also tried just using sshpass instead of /usr/bin/sshpass but it doesn't work either.
As far as I know error 0x80070002 is a file not found error, but I don't know where the command isn't being found. Does the "commandline" setting get loaded before even the Linux Kernel? Is there a way to launch the command AFTER Linux initializes?
Like the picture below, you should add the fingerprint to the .ssh/known_hosts file first.
Then add sshpass command line to the Window Termial settings.
From inventory.yml:
myhost:
ansible_host: myhost # actually it was ansible_ssh_host (see my answer)
ansible_user: myuser # actually it was ansible_ssh_user (see my answer)
ansible_pass: mypass # actually it was ansible_ssh_pass (see my answer)
So far, Ansible worked fine. I could also ssh myuser#myhost.
Then, I changed the ssh port from default 22 to 23 and edited the inventory.yml:
myhost:
ansible_host: myhost
ansible_user: myuser
ansible_pass: mypass # THE PROBLEM! Must be ansible_ssh_pass. (see my answer)
ansible_port: 23
As expected, I can ssh myuser#myhost -p 23, but Ansible gives the error:
fatal: [staging]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: myuser#myhost: Permission denied (publickey,password).", "unreachable": true}
What could be causing the error?
The solution is quite unexpected and slightly embarrassing:
While changing the SSH port, I also read this:
Ansible 2.0 has deprecated the “ssh” from ansible_ssh_user,
ansible_ssh_host, and ansible_ssh_port to become ansible_user,
ansible_host, and ansible_port.
I edited inventory.yml a bit too eagerly, as I also changed ansible_ssh_pass to ansible_pass. Hence: missing password -> permission denied.
So, my question had been phrased in a wrong way. I have updated it accordingly.
The variable for password is ansible_password. See documentation here to create your inventory.yml properly.
Notice that you should never store your password in plain text, but use a vault in stead.
In my case, where key based ssh is only allowed, ansible ping was failing with -
"msg": "Failed to connect to the host via ssh: Permission denied (publickey).",
The inventory file had entry for ansible_user=$user. Removing entry from inventory file helped.
My environment :
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 16.04.7 LTS
Release: 16.04
Codename: xenial
$ ansible --version
ansible 2.9.27
config file = /etc/ansible/ansible.cfg
configured module search path = [u'/home/USER_NAME/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python2.7/dist-packages/ansible
executable location = /usr/bin/ansible
python version = 2.7.12 (default, Mar 1 2021, 11:38:31) [GCC 5.4.0 20160609]
I'm trying to use the Remote-SSH extension to edit files on a Linux server from my Windows 10 development machine. Normally, I log into the server using VNC and edit files locally OR I use WinSCP to pull the files to my development machine and copy them back over when done. The Remote-SSH extension seems to be the answer to this inefficiency.
I can SSH just fine using Putty or using Git Bash, but Remote-SSH fails to connect. There's some hints in the error message, but I'm not sure how to interpret them.
Here is my SSH config file (redacted) and the error I receive (redacted):
Config:
Host xxx.yy.gov
HostName xxx.yy.gov
User myusername
Error Message:
[08:44:36.981] remote-ssh#0.47.2
[08:44:36.981] win32 x64
[08:44:36.983] SSH Resolver called for "ssh-remote+xxx.yy.gov", attempt 1
[08:44:36.983] SSH Resolver called for host: xxx.yy.gov
[08:44:36.983] Setting up SSH remote "xxx.yy.gov"
[08:44:37.030] Using commit id "[some-string-of-numbers]" and quality "stable" for server
[08:44:37.033] Testing ssh with ssh -V
[08:44:37.101] ssh exited with code: 0
[08:44:37.101] Got stderr from ssh: OpenSSH_for_Windows_7.6p1, LibreSSL 2.6.4
[08:44:37.105] Running script with connection command: ssh -T -D 52772 xxx.yy.gov bash
[08:44:37.107] Install and start server if needed
[08:44:37.111] Terminal shell path: C:\WINDOWS\System32\cmd.exe
[08:44:37.264] >
[08:44:37.264] Got some output, clearing connection timeout
[08:44:37.611] > myusername#xxx.yy.gov's password:
[08:44:37.612] Showing password prompt
[08:44:44.709] Got password response
[08:44:44.709] "install" wrote data to terminal: "**************"
[08:44:44.730] >
>
[08:44:45.102] > bash: bash: command not found
>
[08:44:45.476] "install" terminal command done
[08:44:45.476] Install terminal quit with output: bash: bash: command not found
[08:44:45.476] Received install output: bash: bash: command not found
[08:44:45.477] Stopped parsing output early. Remaining text: bash: bash: command not found
[08:44:45.477] Failed to parse remote port from server output
[08:44:45.477] Resolver error:
[08:44:45.480] TELEMETRY: {"eventName":"resolver","properties":{"outcome":"failure","reason":"UnparsableOutput",
"askedPw":"1","askedPassphrase":"0","asked2fa":"0","askedHostKey":"0","gotUnrecognizedPrompt":"0",
"remoteInConfigFile":"1"},"measures":{"resolveAttempts":1,"retries":1}}
[08:44:45.482] ------
VSCode Remote-SSH error
There are there are three ways you can try. I know the problem is annoying.
Check your vscode is local window or remote window. Then, check
remote-ssh setting. (Make sure Local Server Download is auto && Use
local Server is marked.).
Remote SSH:Path . you can switch to local ssh or git/ssh
Try to update or revert remote-ssh.(Version 0.50 can connect to server host stably, I found. This one is very useful.
Maybe you just select 'Linux' instead of 'Windows' though you are using Windows when you got the option to select Linux, Windows or Mac.
Since you are connecting to a server and not your own computer, the type of server you are connecting to is most likely Linux.
i am trying to deploy a VM via Ansible on my ESXi host.
I am using the following role for this:
- vsphere_guest:
vcenter_hostname: emea-esx-s18t.****.net
username: ****
password: ****
guest: newvm001
state: powered_off
vm_extra_config:
vcpu.hotadd: yes
mem.hotadd: yes
notes: This is a test VM
vm_disk:
disk1:
size_gb: 10
type: thin
datastore: ****
vm_nic:
nic1:
type: vmxnet3
network: VM Network
network_type: standard
vm_hardware:
memory_mb: 4096
num_cpus: 4
osid: windows7Server64Guest
scsi: paravirtual
esxi:
datacenter: MyDatacenter
hostname: esx-s18t.****.net
when i execute this role now via a playbook i get the following message:
root#ansible1:~/ansible# ansible-playbook -i Inventory vmware_deploy.yml
PLAY ***************************************************************************
TASK [setup] *******************************************************************
ok: [172.20.22.5]
TASK [vmware : vsphere_guest] **************************************************
fatal: [172.20.22.5]: FAILED! => {"changed": false, "failed": true, "msg": "pysphere module required"}
PLAY RECAP *********************************************************************
172.20.22.5 : ok=1 changed=0 unreachable=0 failed=1
So it seems to be "pysphere" module is missing. i've already checked that with the command:
root#ansible1:~/ansible# pip install pysphere
Requirement already satisfied (use --upgrade to upgrade): pysphere in /usr/local/lib/python2.7/dist-packages/pysphere-0 .1.7-py2.7.egg
Then i did the "upgrade" and get the following message back:
root#ansible1:~/ansible# pip install pysphere --upgrade
Requirement already up-to-date: pysphere in /usr/local/lib/python2.7/dist-packages/pysphere-0.1.7-py2.7.egg
So it seems to be it is already installed and its up-to-date , why do i get this error message then?
How can i fix it that my god damn role works fine now?
Jesus, Ansible makes me crazy ..
I hope you guys can help me, thanks in advance!
kind regards,
kgierman
EDIT:
so i've writen a new playbook with the old stuff, the new playbool lookes like this(i've added your localhost and connection local stuff):
---
- hosts: localhost
connection: local
tasks:
vsphere_guest:
vcenter_hostname: emea-esx-s18t.****.net
username: ****
password: ****
guest: newvm001
state: powered_off
vm_extra_config:
vcpu.hotadd: yes
mem.hotadd: yes
notes: This is a test VM
vm_disk:
disk1:
size_gb: 10
type: thin
datastore: ****
vm_nic:
nic1:
type: vmxnet3
network: VM Network
network_type: standard
vm_hardware:
memory_mb: 4096
num_cpus: 4
osid: windows7Server64Guest
scsi: paravirtual
esxi:
datacenter: MyDatacenter
hostname: esx-s18t.****.net
so when i execute this playbook i get the following error:
root#ansible1:~/ansible# ansible-playbook vmware2.yml
ERROR! Syntax Error while loading YAML.
The error appears to have been in '/root/ansible/vmware2.yml': line 7, column 19, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
vcenter_hostname: emea-esx-s18t.sddc-hwl-family.net
username: root
^ here
the struggle is real -.-
You generally should execute provisioning modules such as vsphere_guest on your local ansible machine.
I suspect that 172.20.22.5 is actually your ESX host, and ansible try to execute module from there, where pysphere is surely absent.
Use:
- hosts: localhost
tasks:
- vsphere_guest:
...
Ran into this issue once again on macOS / OSX...
It seems to be related to PYTHONPATH.
I have this in my .profile:
export PYTHONPATH="/usr/local/lib/python2.7/site-packages"
[ ... further down ... ]
export PYTHONPATH="/usr/local/Cellar/ansible/2.1.2.0/libexec/lib/python2.7/site-packages:/usr/local/Cellar/ansible/2.2.1.0/libexec/vendor/lib/python2.7/site-packages:$PYTHONPATH"
The first line with PYTHONPATH is where pysphere and other system modules reside.
Also take note of the specific version of Ansible!
Anyway, this seems to resolve the issue.
Source: https://github.com/debops/debops-tools/issues/159#issuecomment-236536195
I configured my pc and the virtualbox (the first one with Ubuntu Desktop 14.04 and the second one with Ubuntu Server 14.04) in order to communicate through ssh without explicitly ask for password and it works perfectly. Now I'm trying to run a simple hello world using openmpi, but when I run the command
mpirun --host localhost, name_other_host#ip ./hello
it doesn't work. What is wrong in what I'm doing? the executable exists in both hosts in home/name/Desktop/MW/hello
the error is this one
mpirun was unable to launch the specified application as it could not access
or execute an executable:
Executable: ~./hello
Node: domenico-K52Jc
while attempting to start process rank 0.
note: domenico-K52Jc is my localhost
Instead of using "localhost", you could use your "actual host" name in your /etc/hostname.
e.g. type in terminal:
cat /etc/hostname
if it returns something like "myubuntu"
then run the command:
mpirun --host myubuntu,name_other_host#ip ./hello
Also note that there should not be a space between your hostnames.
Hope it helps,
Shang