How to use the libssh connection plugin on ansible - ssh

I'm working on a playbook to create/delete users on different storage devices.
The problem is that ansible is not able to create the temp directory and execute the module code.
I was thinking to use shell to create the connection and then to run the command.
Something like this:
- name: Create user
shell: |
sshpass "password" ssh user#storage_device
command_to_create_user
exit
Obviously this approach is risky, if you are not able to connect to the server, you can run the command on the local ansible server.
I have been told that network plugins exist to create a similar connection (ansible.netcommon.network_cli).
But I wasn't able to find much information.
https://www.ansible.com/blog/new-libssh-connection-plugin-for-ansible-network
How can use the libssh connection plugin to run a command?
Thanks

Related

What happens when I run "ssh git#gitlab.com

I have tried google it and check the gitlab-documentation but did not find a good answer for this.
When I setup GitLab I am advised to test my SSH-keys to my GitLab URL instance.
I use git#gitlab.com.
What actually happens when I run "ssh git#gitlab.com"
I understand how you use SSH to login to a remote device e.g. Cisco Router with SSH Admin. But in this case: who is git#gitlab.com? [username]#gitlab.com makes more sense to me.
Somehow it must find my Gitlab account (since it is there my public key is stored). How can I do that when I use a generic git#gitlab.com ?
I am after a more step-by-step answer (Client-Server)
[username]#gitlab.com makes more sense to me
It would not: that would ask to open an SSH session as 'username': that account does not exist. Only one account exists: 'git'.
Then, in ~/.ssh/authrorized_keys, your public key is found, alongside:
an ID (as shown here), matching your registered GitLab account,
a forced command, which will call a GitLab script in order to execute the Git command.
That way:
there is no interractive session possible on GitLab's server
the project gitlab-shell gets your ID and hangle your Git query
for found it, go in repository on clone, select ssh, begin start copy up to :,
now test

Cannot ssh into Google-Engine, connecting in a loop

I am unable to connect through SSH to my GCE instance. I was connecting without any problem, the only think I changes was my user name through top right corner of the browser then selected Change Linux Username.
When I try to ssh into my google engine via browser, I keep having following message in a endless loop:
When I try to ssh via cloud shell I also get following error message, (serial console output):
Permission denied (publickey).
ERROR: (gcloud.compute.ssh) [/usr/bin/ssh] exited with return code [255].
[Q] Is there any way to fix this problem? Since I have no access to the engine now, I don't know what to do.
However you could always get back access through serial console then from there you could internally y troubleshoot user/ssh issue.
1) $ gcloud compute instances add-metadata [INSTANCE_NAME] --metadata=serial-port-enable=1
You can then connect to the instance through the serial port
NOTE:The root password have must been already set in order to use the serial port
2)
$ gcloud compute connect-to-serial-port [INSTANCE_NAME]
If you never set the root password you could set it by adding a startup-script to your instance that will set a password as root by running the below command :
NOTE: the instance must be rebooted in order to run the startup script.
3) $ gcloud compute instances add-metadata [instance name] --metadata startup-script='echo "root:YourPasswdHere" | chpasswd'
Reboot the instance run the command on the step "2)" authenticate your self as root with the password that you set on the startup script in the step "3)" .
I had the same problem, It took me several days to figure out what was happening in my case.
To find out, I created a new instance from scratch and started making all modifications I've done to those that eventually couldn't connect to, one by one, exiting the ssh connection and re entering so as to test it.
I've tried it a couple of times, in both cases, the connection was impossible after uninstalling python (I only needed 3.7 version so I was uninstalling all others and installing that one I needed).
My command for uninstalling it was
sudo apt purge python2.7-minimal
and
sudo apt purge python3.5-minimal
I don't know if it was specifically because of deleting python, or because of using purge (in which case this problem might reproduce if using purge with another program).
I don't even know why would this affect ssh connection.
Could it be that google cloud is somehow using destination python for the ssh web?
In any case, if you are experiencing this problem try to avoid uninstalling anything from the base VM.

I am trying to ssh to a windows machine from ansible, the program gets stuck

tasks:
name: Connect to Windows hpst machine through an ssh script
script : windows_connect.ssh
name: Run the bat file
script : C:\OV\sentenv.bat
name: To exit from the remote machine
shell: exit
This is what my playbook looks like.
Windows_connect.sh contains a script to connect to a windows machine via ssh.
ssh root#host
So ideally shouldnt ansible prompt me for a password?
Instead it gets stuck.
Please help me with the same
Ansible opens at least one new ssh connection for every task in the play.
So the idea to open a ssh connection with the first task and then reuse the connection in the later tasks will not work. Actually Ansible won't be able to execute the first task because the script module you are trying to use will already need a working connection to the remote host.
I have found little information on how many ssh connection Ansible will use to execute a task so I might be wrong here.
You should consult the Ansible documentation for Window support and implement a solution based on the winrm Python module.

why ssh-copy-id still need password when using fabric

I have set env.user and env.password,but when I use:
run('ssh-copy-id -i $HOME/.ssh/id_rsa.pub server1')
it still asks me for the password,why?
env.user and env.password are used to ssh to remote server and then run the command inside run () at the remote server.
They are not used for the remote command itself (running in the remote server).
So ssh-copy-id doesn't know anything about the user or password.
If this is not what you mean, I would advice you to edit the question and make things more clear, like providing more context of what you are trying to accomplish: pasting the function that contains this 'run' for example.

Connect to remote host from Aptana Studio 3 terminal

How to connect to remote host from Aptana Studio 3 terminal view, and use commands on that server?
I'm using symfony framework, the project is in my host 192.168.0.100, so I want to run symfony commands like: $ symfony propel:build-schema
To connect to a remote host run the following command in your console:
$ ssh -l <username> 192.168.0.100
Enter your password and you're golden. Unfortunately you have to do this every time you open Aptana, but it's better than nothing.
Another alternative if you need to specify a port number(or dont need to).
ssh <username>#<server> -p <portnumber>
i know its a old question but hope it helps someone.
first post as well!
You can install Target Management (http://www.eclipse.org/tm/) to create a remote project in aptana.