Error while bootstraping ec2 instance through a bash script - amazon-ec2

I'm trying to bootstrap an ec2 instance through a bash script. Following is the command i use,
knife bootstrap xx.xx.xx.xx --sudo --ssh-user ubuntu --identity-file ~/Desktop/temp/temp.pem --node-name test
The above command works when it's executed directly from the terminal. But when it is included in a bash script it doesn't execute properly. ( In the bash script I use "cd ~/chef-repo/" to change the directory to chef-repo, there's no issue finding the "knife" command)
The error I get is,
Connecting to xx.xx.xx.xx
ERROR: Network Error: Connection refused - connect(2)
Check your knife configuration and network settings
Anybody knows why am I getting this error ?

Related

Docker daemon not running: error during connect: open //./pipe/docker_engine

Error during connect: this error may indicate that the docker daemon is not running: Get "http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.24/containers/json?all=1&filters=%7B%22label%22%3A%7B%22com.docker.compose.project%3Dkafka-waffle-stack%22%3Atrue%7D%7D": open //./pipe/docker_engine: The system cannot find the file specified
How can I fix this issue and get the docker-compose command to work?
I am trying to run a docker-compose command, but I am receiving the above error message. The error message seems to indicate that the Docker daemon is not running. I have tried starting the Docker daemon by running the command "dockerd" in the command prompt, but the issue persists.

VS Code - Openfolders and edit files through SSH tunnel

I typically use VS Code's Remote-SSH extension to connect to an AWS instance where I do my work. There's a nice section of their documentation about how to do that here. I hate just using the terminal alone because I like the debugger and the ability to open up folders and files for viewing. Until recently I had been SSH-ing from my MacBook Pro (A) to an AWS instance running Ubuntu 18.04.4 LTS (B) without any issues. Now, however, I need to work on a new instance, also Ubuntu 18.04.4 LTS, (C) that I can only SSH into from B, and not from A.
This part of the documentation indicates that I can SSH from A to B and then forward a port to create an SSH tunnel. However, this only allows me to open a terminal into C. However, this doesn't allow me to open folders and files in the Explorer like I want to.
I've followed Qinsheng's instructions here to set up an SSH tunnel and use the Remote-SSH extension's "ProxyJump" functionality My config file looks like this:
Host B
HostName B.mydomain.com
IdentityFile /Users/MyID/.ssh/B_private_key
User me
Host C
HostName C
IdentityFile /Users/MyID/.ssh/C_private_key
ProxyJump B
User me
This works perfectly when I use the terminal on VS Code to run ssh C. Without having to input any password(s) I am taken to C and can perform my work. However, when I try to use the "Remote-SSH: Connect to Host" functionality to SSH into C, using ProxyJump through B and subsequently open a folder/view files there, I get the message "Could not establish connection to 'C'". The stack trace looks like this:
[13:59:48.537] Log Level: 2
[13:59:48.539] remote-ssh#0.51.0
[13:59:48.539] darwin x64
[13:59:48.541] SSH Resolver called for "ssh-remote+C", attempt 1
[13:59:48.541] SSH Resolver called for host: C
[13:59:48.541] Setting up SSH remote "C"
[13:59:48.546] Acquiring local install lock: /var/folders/w2/0w6jys8d34x940rj7f5r20vnh83ht7/T/vscode-remote-ssh-C-install.lock
[13:59:48.590] Looking for existing server data file at /Users/MyID/Library/Application Support/Code/User/globalStorage/ms-vscode-remote.remote-ssh/vscode-ssh-host-v1-91899dcef7b8110878ea59626991a18c8a6a1b3e-0.51.0/data.json
[13:59:48.593] Using commit id "91899dcef7b8110878ea59626991a18c8a6a1b3e" and quality "stable" for server
[13:59:48.595] Install and start server if needed
[13:59:48.599] Checking ssh with "ssh -V"
[13:59:48.629] > OpenSSH_8.1p1, LibreSSL 2.7.3
[13:59:48.632] askpass server listening on /var/folders/w2/0w6jys8d34x940rj7f5r20vnh83ht7/T/vscode-ssh-askpass-c4eabfddec4ae91c1e423a3167dd184d8553da26.sock
[13:59:48.633] Spawning local server with {"ipcHandlePath":"/var/folders/w2/0w6jys8d34x940rj7f5r20vnh83ht7/T/vscode-ssh-askpass-b00842fb08dbbff49678439b1335f105364fd9d5.sock","sshCommand":"ssh","sshArgs":["-v","-T","-D","52911","-o","ConnectTimeout=15","C"],"dataFilePath":"/Users/MyID/Library/Application Support/Code/User/globalStorage/ms-vscode-remote.remote-ssh/vscode-ssh-host-v1-91899dcef7b8110878ea59626991a18c8a6a1b3e-0.51.0/data.json"}
[13:59:48.633] Local server env: {"DISPLAY":"1","ELECTRON_RUN_AS_NODE":"1","SSH_ASKPASS":"/Users/MyID/.vscode/extensions/ms-vscode-remote.remote-ssh-0.51.0/out/local-server/askpass.sh","VSCODE_SSH_ASKPASS_NODE":"/Users/MyID/Desktop/Visual Studio Code.app/Contents/Frameworks/Code Helper (Renderer).app/Contents/MacOS/Code Helper (Renderer)","VSCODE_SSH_ASKPASS_MAIN":"/Users/MyID/.vscode/extensions/ms-vscode-remote.remote-ssh-0.51.0/out/askpass-main.js","VSCODE_SSH_ASKPASS_HANDLE":"/var/folders/w2/0w6jys8d34x940rj7f5r20vnh83ht7/T/vscode-ssh-askpass-c4eabfddec4ae91c1e423a3167dd184d8553da26.sock"}
[13:59:48.635] Spawned 29414
[13:59:48.734] > local-server> Spawned ssh: 29415
[13:59:48.738] stderr> OpenSSH_8.1p1, LibreSSL 2.7.3
[13:59:48.740] stderr> /bin/false: No such file or directory
[13:59:48.740] stderr> kex_exchange_identification: Connection closed by remote host
[13:59:48.741] > local-server> ssh child died, shutting down
[13:59:48.745] Local server exit: 0
[13:59:48.745] Received install output: OpenSSH_8.1p1, LibreSSL 2.7.3
/bin/false: No such file or directory
kex_exchange_identification: Connection closed by remote host
[13:59:48.746] Stopped parsing output early. Remaining text: OpenSSH_8.1p1, LibreSSL 2.7.3/bin/false: No such file or directorykex_exchange_identification: Connection closed by remote host
[13:59:48.746] Failed to parse remote port from server output
[13:59:48.747] Resolver error:
[13:59:48.750] ------
It seems clear to me that the main problem is something trying to access /bin/false as the interpreter. I assume that this is an issue with my MacBook Pro (A). I did notice that when running echo $SHELL on A that it was returning /bin/false, but I ran export SHELL=/bin/bash to change that and followed the suggestions in this post to set VS Code's integrated shell for MacOS to /bin/bash as well. I've checked echo $SHELL on B as well and it is similarly showing /bin/bash too.
My questions are these:
Is what I am trying to accomplish possible?
If it is, what am I doing wrong?/what can I check to help make sure that I can get to the VS Code functionalities that I want?
I figured it out. I had a bunch of /bin/false references in my /etc/passwd file, so I changed those out to /bin/bash and now it works like a charm. :)

Can start ChromeDriver within CLI tool but won't allow connections

I'm using Laravel homestead and I'm writing a little artisan command line tool that I need to browse my site with javascript execution.
I run dusk test regularly with no difficulty, so I thought I would use Laravel's tools for this script.
I started out by running this early in my script:
\Laravel\Dusk\TestCase::startChromeDriver();
This started the driver fine running on port 9515 running as user vagrant (default homestead user)
But when I tried to access it (also from within the script) I would get an error:
Failed to connect to localhost port 9515: Connection refused
If I instead started it manually on the command line:
$ ./vendor/laravel/dusk/bin/chromedriver-linux --port=9515
The driver started fine again running on port 9515 as user vagrant, but this time my tool runs fine.
But I really want to be able to start the ChromeDriver from within the tool. So I also tried:
$process = new \Symfony\Component\Process\Process('./vendor/laravel/dusk/bin/chromedriver-linux --port=9515');
$process->start();
Connection was refused again.
Any idea why this works when I start it from the command line but not within my artisan command?
I can't explain why this makes a difference but it has. If I launch the driver with the full path:
/home/vagrant/Code/mysite/vendor/laravel/dusk/bin/chromedriver-linux --port=8888
all works fine now.

Unable to bootstrap node on windows node using chef and knife

I've exhausted my options in trying to bootstrap a windows node running in azure. I have the workstation connected to my self-hosted chef server without any issues. I run the bootstrap command and get the following:
Creating new client for vm1
Creating new node for vm1
Connecting to 104.***.***.***
ERROR: Net::SSH::ConnectionTimeout: Net::SSH::ConnectionTimeout
I know the username and password are valid as well as the IP of the target node. What are my options here for debugging such a problem? I believe the necessary ports are open, unless I'm missing something special. I have telnet enabled. Does anyone have any better ideas?
To copy down from the comments, to bootstrap over WinRM you need the knife bootstrap windows winrm command.
you can also bootstrap windows machine with following command. Core Chef now supports bootstrapping Windows systems without a knife plugin
sudo knife bootstrap -o winrm <pubic_IPV4_Address/DNS_of_client_machine> -U Administrator -P '<pwd>' --node-name <node_name> --run-list 'recipe[<cookbook_name>]'
where,
pubic_IPV4_IP/DNS_of_client_machine --> Public IP address/ DNS of the client machine.
node_name --> String representing node name.
cookbook_name --> Cookbook that we want to execute on client machine.
pwd --> password to connect with windows client machine
Note: Make sure to execute above command from ~/chef-repo/.chef/ directory.
If you are unable to execute above command with -o winrm option then install below gem packages
chef gem install winrm
chef gem install knife-windows

Jenkins with SSH key

I am trying to run a script on a remote server..I have created ssh key and tested running it from my remote server to another remote server where my script is located, after trying to run it I have succeeded. I have jenkins installed on my server which there I tried the same command in order to run the script on the remote server... it failed.
this is what I tried in my jenkins job:
ssh -i /path/to/my/private/key user#host_name /path/to/my/script/clean_cache_ruby.sh
I am getting in Jenkins the following error: Host key verification failed.
how can i make it run from Jenkins as it run perfectly from my server when I try the same command on the server terminal?
You can use the ssh option StrictHostKeyChecking option.
ssh -o StrictHostKeyChecking=no -i /path/to/my/private/key user#host_name /path/to/my/script/clean_cache_ruby.sh
Or another option is to manually add the finger print to /var/lib/jenkins/.ssh/known_hosts

Resources