Gcloud - How to automate installation of gcloud on a server? - linux

I want to write a shell script which basically goes through all the installation steps for gcloud, as outlined at: https://cloud.google.com/sdk/?hl=en
However, when you are run install.sh, you will be asked to enter an authorization code, your project-id, whether you want to help improve Google Cloud or not and so on. Basically user-inputs are required.
But if I want to automate the installation process on a machine where there will not be any user, how can I do this?

There are two separate problems here.
First, how do you install without prompts:
Download the google cloud sdk tar file. This can be found right under the curl command on https://cloud.google.com/sdk/
Untar and cd into the newly created directory.
run CLOUDSDK_CORE_DISABLE_PROMPTS=1 ./install.sh (or install.bat)
This disables all prompts. If you don't like the way it answers the prompts, you can pre-answer them with flags. If you preanswer all the questions, you don't need the CLOUDSDK_CORE_DISABLE_PROMPTS environment variable set. Run ./install.sh --help for a list of flags.
Now that you have it installed, how do you auth it?
If you are on GCE, you can use the credentials on the machine itself automatically. If not, some setup is required.
Since these are automated installs, you want to give them a server key. If there was a human involved, he can just proceed through the normal flow.
Keys can be downloaded from the developer console under "APIs & auth -> Credentials". Click "New credentials -> Service account key". Google recommends you use a JSON key.
When you have that key, you need to move it to the new server and run:
gcloud auth activate-service-account --key-file servicekey.json
gcloud config set project MYPROJECT

There seems to be a better / more elegant way to do this as per the docs:
curl https://sdk.cloud.google.com > install.sh
bash install.sh --disable-prompts

This sequence of commands should help:
file="google-cloud-sdk-101.0.0-linux-x86_64.tar.gz"
link="https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/"
curl -L "$link""$file" | tar xz
CLOUDSDK_CORE_DISABLE_PROMPTS=1 ./google-cloud-sdk/install.sh

Related

Pass password through jenkins build step

I'm trying to add a build step in jenkins to copy files from my build server to my web application server. I've got the following command working in the command prompt
sudo scp -r /var/lib/jenkins/workspace/demoproj/publish root#0.0.0.0:/usr/temp
but when I run this command, it prompts me for a password every time. I found out about sshpass, but when I run this command...
sudo sshpass -p "passwordhere" scp -r /var/lib/jenkins/workspace/demoproj/pub root#0.0.0.0:/usr/temp
the terminal gets stuck. And never makes it through.
My main problem is if I add the first command to a build step in jenkins, it won't be able to pass the password over. How can I either supply the password in jenkins, or modify the command to pass over my credentials?
Helpful information: I'm using Putty on Windows 10 to connect to my
Ubuntu 16.04.3 LTS x64 servers from another Ubuntu 16.04.3 server.
First, sshpass needs to be installed on both the systems that is, the one running your jenkins instance as well as the one you are trying to access that is: root#0.0.0.0. You can verify it by doing 'which sshpass' or 'whereis sshpass'. If its not installed even in one of them then you need to install it first.
Also, Have you ever tried doing a ssh to the said machine: root#0.0.0.0 from the system where you have your jenkins instance? If not then there might not be an entry in the 'known-hosts' of either system. for that you can do ssh with '-o StrictHostKeyChecking=no' option to make an automatic entry in known-hosts.
Alternatively, if you dont want to enter password again and again you should work with 'keys'. Generate a unique key for both the systems and do an scp or ssh with -i option.
You should use jenkins credentials instead of using sensitive passwords directly into the scripts. Put the whole scp or ssh part inside a block which looks like: withCredentials(){}.
What's the point of having CI if you are required to be nearby to enter password every time? Install "publish over ssh" plugin, it has a step to send stuff over ssh.
https://wiki.jenkins.io/display/JENKINS/Publish+Over+SSH+Plugin
Look at "Use SSH during a build" section, you can use "send files or execute commands over SSH" build step. This shall become available after plugin installation.

Hubot with Rocket.chat

I am trying to integrate Hubot with rocketchat and make Hubot talk with rocketchat.
The sources I am referring to are:
https://hubot.github.com/docs/
https://github.com/RocketChat/hubot-rocketchat
I have installed Nodejs and in Node.js command prompt I did:
mkdir myhubot
cd myhubot
yo hubot
Questions I have:
How do I understand if rocketchat is integrated with Hubot?
If I have not integrated rocketchat, how should I do it? (I did refer to https://github.com/RocketChat/hubot-rocketchat). Here, I want to understand how and where to set environment variables. Also, how exactly do I run Docker here?
When I do docker export ROCKETCHAT_ROOM='https: //spree.chat/channel/'
It returns: "Cowardly refusing to save to a terminal. Use the -o flag or redirect."
How can I resolve this?
Here is the screenshot:
1.) Rocket.chat have "Internal hubot" which is integraded and contain some simplest Hubot scripts. Ideal for testing and introduction to Hubot. You can find these scripts in rocketchat/programs/server/npm/node_modules/meteor/rocketchat_internal-hubot/node_modules/hubot-scripts/src/scripts/.
If you wanna use more complex scripts, you must use external Hubot.
2.) Setup "Environment Variables" are different for each platform. For example, if you want set ROCKETCHAT_ROOM to support, you must use something like env ROCKETCHAT_ROOM=support. But this only applies to Linux OS. For Docker syntax is -e ROCKETCHAT_ROOM=support. If you running external Hubot on Windows, you probably must use something different.
3.) ROCKETCHAT_ROOM variable is not for URL of your channel. You must put here name of your chat room.

Google Cloud SDK - Is there a way to manually install google cloud sdk on Linux without internet access?

I am trying to install Google Cloud SDK on a Linux machine without any Internet access.
I am following the instructions at: https://cloud.google.com/sdk/?hl=en
I downloaded the tar file on my local machine and transferred it to the Linux machine using scp. I then ran the install.sh file and got the following error:
[me#user google-cloud-sdk]$ ./install.sh
Welcome to the Google Cloud SDK!
To help improve the quality of this product, we collect anonymized data on how
the SDK is used. You may choose to opt out of this collection now (by choosing
'N' at the below prompt), or at any time in the future by running the following
command:
gcloud config set --scope=user disable_usage_reporting true
Do you want to help improve the Google Cloud SDK (Y/n)? n
This will install all the core command line tools necessary for working with
the Google Cloud Platform.
/home/me/google-cloud-sdk/lib/googlecloudsdk/calliope/cli.py:661: DeprecationWarning: BaseException.message has been deprecated as of Python 2.6
exc_message = getattr(exc, 'message', None)
/home/me/google-cloud-sdk/lib/googlecloudsdk/calliope/cli.py:664: DeprecationWarning: BaseException.message has been deprecated as of Python 2.6
msg = u'({0}) {1}'.format(command_path_string, exc.message)
ERROR: (gcloud.components.update) Failed to fetch component listing from server. Check your network settings and try again.
I have a proxy server that I can use to access the internet from this Linux machine. I tried running install.sh as 'sh install.sh --proxy host:port' but obviously, there is no input parameter called proxy to install.sh.
How can I work around this problem?
Thanks in advance.
Exported my proxy details as "export https_proxy='...'" before running the install.sh file.
This worked for me.
Go to Advanced System settings and create a variable HTTPS_PROXY,
restart CMD.
echo %HTTPS_PROXY%
To make sure it has taken the changes into account.
Launch the install.bat

how to run npm/grunt command from jenkins

I'm new to this area and was trying to run the following commands from jenkins:
npm install
grunt quickStart
So far I've a jenkins running on a window machine as a window service and I've also installed NodeJs plugin for jenkins.
However, I'm stuck and quit confused following instructions here, its asking me to to add one or mode nodeJs installation and I could not find those setting and not even sure if I even need them in the first place.
Here is the bit that's asking me to do:
I cannot see this setting for the jenkins job I create. Is there an easy way to run those command in jenkins from a .bat or .sh script, a .bat would be recomended since I'm on window machine.
Note : I've already checked out a project using git in jenkins!!!
Thanks
"its asking me to to add one or mode nodeJs installation and I could not find those setting and not even sure if I even need them in the first place."
I don't think you need that I have pointed jenkins to the node installation folder an nothing more.., for this you go to Manage Jenkins->Configure System->NodeJS->NodeJS installations.. type in any name you like and point to where the node home folder is.
...cannot see this setting for the jenkins job I create...
Once you have configure that in your jenkins configuration you should have that configuration available like so:
...Is there an easy way to run those command in jenkins from a .bat or .sh script, a .bat would be recomended since I'm on window machine
I'm sorry don't get what commands are you referring to...
so summarizing :
you have to tell jenkins where you have your node installation
use that configuration in your jobs
hope this helps...
The way I made it, was trough execute shell, as the build tool for nodejs is npm, I simply wrote a shell script that instructs jenkins to run npm install in the workspace directory inside jenkins where it clones the git repository and then to zip and move the package if successful to another folder.

How to log in into the linux terminal as ROOT user using ruby script

I want to run a script on remote server using SSH.
I have write all the code which runs properly using system command.
To run my code on remote server I need some packages which I need to install on remote server.
To do so I need login into remote terminal as a ROOT user. When I try to do using Ruby script so I get something like following
[not_root_user#remote_server]$ su
Password:
I need some command using which I can able to login into the remote server something like following
[not_root_user#remote_server]$ su -p ******
[root#remote_server]#
Is there any linux command which accepts the password in it?
So you want your script to act as root?
It's not really recommended, but you can use expect: http://en.wikipedia.org/wiki/Expect
The wiki there has a walkthrough for a basic automated telnet session that you could adapt to your needs.
However, you're going to have your root password in plain text, which could be a security issue. If you go that route, I'd definitely obliterate all copies of that script from the universe once this package is installed.
But if you're allowing direct root logins, you've already got a bit of a security problem. Sudo works out-of-the-box on every modern linux distro I've used, I'd stick with that, if possible.
Another option which is equally tasteless would be to set up root-to-root login without a password via ssh.
Sudo would be my first option to getting around this. Although not the best option.
You can also use Key authentication with SSH, and if password authentication is turned off there is no need to enter a password.

Resources