We have a tendency to forget things when we have a bunch of things on our plate. Imagine the impact of forgetting crucial steps while deploying critical applications on multiple servers. This is when automation tools like Rundeck come handy and you can configure steps for it to execute on different remote servers.
Rundeck is a cross-platform open source tool for running jobs on remote machines. It helps us run tasks on remote server node using web interface. Using Rundeck we can also schedule jobs & build workflows.
Below is the step by step guide on how to create jobs in Rundeck. I have executed all steps on Ubuntu16.4 version. Basically I have used two servers to execute all the commands.
Server1: Rundeck Server (IP: 127.0.0.1)
Server2: Remote Server (IP: 192.168.56.101)\
Step1: Download Rundeck package from http://rundeck.org/downloads.html and run the below command to setup it on Server1.
root@ubuntu:~# dpkg -i rundeck-2.10.2-1-GA.deb
Following commands are used to start/stop Rundeck service,
root@ubuntu:~# service rundeckd start
root@ubuntu:~# service rundeckd stop
Once all the setup is done you can hit URL in browser http://localhost:4440
To login into Rundeck use default user name as ‘admin’ and password as ‘admin’
Step2: Click on “New Project” and create a new job
Step3: To execute the command on Remote Server you have to add the server as a node into Rundeck Server, and you can do this by,
Logging in to remote Linux server, and creating a new Rundeck user and setting user password
root@ubuntu:~# adduser rundeck
root@ubuntu:~# usermod -aG sudo rundeck
root@ubuntu:~# su rundeck
- Log in as rundeck user and execute below commands
Generate key
rundeck@ubuntu:~# ssh-keygen
rundeck@ubuntu:~# cat .ssh/id_rsa.public - Create a new file and copy public key from .ssh/id_rsa.public
rundeck@ubuntu:~# vi .ssh/authorized_keys - Ensure that the following files exist under /home/rundeck/.ssh folder
-rw-r--r-- 1 rundeck rundeck 402 Dec 23 22:44 id_rsa.pub
-rw------- 1 rundeck rundeck 1679 Dec 23 22:44 id_rsa
-rw-rw-r-- 1 rundeck rundeck 402 Dec 23 22:51 authorized_keys - Edit the file using root account and Rundeck user entry
rundeck@ubuntu:~# vi /etc/sudoers
# Allow members of group sudo to execute any command
%sudo ALL=(ALL:ALL) ALL
rundeck ALL=(ALL) NOPASSWD: ALL
Step4: On Rundeck Server we have to add Remote Server as a new entry under
- Goto Project->Nodes
- Add a new note entry in the file
root@ubuntu:~# vi /var/rundeck/projects/MyProject/etc/resources.xml
<node name="Rose" description="Rose Server" tags="" hostname="192.168.56.101" osArch="amd64" osFamily="unix" osName="Linux" username="rundeck" ssh-key-storage-path="keys/myproj/rose.key"/> - Click on the upper right setting in Rundeck Server and go to “Key Storage”
- Go to Remote Server and copy private key
rundeck@ubuntu:~# cat .ssh/id_rsa
Step5: Create a new Job to execute commands on selected/all configured nodes
- Goto Jobs->Job Action->New Job
- Under the Workflow section add a new command line step and specify your command
eg.sudo service nginx restart
Also under the node section select node on which you want to execute the command.
- Once you save the job, and again click on Job menu then the screen will look like
Now you can run the job by clicking play button before the job name and it will execute the command on all specified nodes.
- Once the job is executed successfully on different notes then you can check the status of the job by clicking ‘recent’ link under ‘Activity for Jobs’ section
Above steps should help you in setting up jobs in Rundeck.
I hope this blog helps serve the purpose and further makes your life easier on deployment of large applications! You are good to go!