Adding AWS EC2 instance to Rundeck server

Posted: February 8, 2018 in Amazon Web Services (AWS), Linux, RunDeck

In last post we added node to Rundeck, now we’ll add EC2 instance as node

First,we need to add AWS EC2 plugin

cd /var/lib/rundeck/libext/
wget https://github.com/rundeck-plugins/rundeck-ec2-nodes-plugin/releases/download/v1.5.1/rundeck-ec2-nodes-plugin-1.5.1.jar
systemctl restart rundeckd

Now create New project-Add source-AWS EC2 Resources

1.PNG

Specify Access Key, Secret Key, Endpoint (for list of endpoint refer to https://docs.aws.amazon.com/general/latest/gr/rande.html#ec2_region)

In mapping parameters field specify:

name.selector=tags/Name;

hostname.selector=publicIcDnsName;

description.default=Ec2 node instance;

osArch.selector=architecture;

osFamily.selector=platform;

osFamily.default=unix;

osName.selector=platform;

osName.default=Linux;

username.selector=tags/Rundeck-User;

username.default=root;

ssh-keypath.default=/var/lib/rundeck/.ssh/id_rsa;

editUrl.default=https://console.aws.amazon.com/ec2/home#c=EC2&s=Instances;

attribute.publicIpAddress.selector=publicIpAddress;

attribute.publicDnsName.selector=publicDnsName;

tags.selector=tags/Rundeck-Tags

Click Save, EC2 node(s) should be visible in Rundeck

Line in projet properties

resources.source.2.config.mappingParams=name.selector\=tags/Name;hostname.selector\=publicDnsName;description.default\=Ec2 node instance;osArch.selector\=architecture;osFamily.selector\=platform;osFamily.default\=unix;osName.selector\=platform;osName.default\=Linux;username.selector\=tags/Rundeck-User;username.default\=root;ssh-keypath.default\=/var/lib/rundeck/.ssh/id_rsa;editUrl.default\=https\://console.aws.amazon.com/ec2/home\#c\=EC2&s\=Instances;attribute.publicIpAddress.selector\=publicIpAddress;attribute.publicDnsName.selector\=publicDnsName;tags.selector\=tags/Rundeck-Tags

1.PNG

On Rundeck server, if not already done create key pair

ssh-keygen –t rsa
cp /root/.ssh/id_rsa /var/lib/rundeck/.ssh/id_rsa
cp /root/.ssh/id_rsa.pub /var/lib/rundeck/.ssh/id_rsa.pub

Now, copy content id_rsa.pub to EC2 instance to /root/.ssh/authorized_keys

In Rundeck GUI, click on project-Nodes, EC2 instance should be visible

 

1.PNG

 

Also, command should be executed

 

1.PNG

 

Running AWS CLI from Rundeck server:

Install AWS CLI, on Rundeck server

On Rundeck go to commands tab in node specify local server, enter following command in interface:

 

aws configure set aws_access_key_id your_access_key
aws configure set aws_secret_access_key your_secret_key
aws configure set default.region us-west-2

 

Advertisements
Comments
  1. Dendi says:

    Hi Admin,

    Would you mind to discuss this with me in chat? if so, please let me know when you are free. I have some question on the Mapping Params field option. should I paste all the parameters you provided to mapping params field or paste a project.properties file?

    Thank you.

    You can email me dendipradigta@gmail.com

    Like

  2. Alejandro Longas Herrera says:

    You can put the information directly in the field: Mapping Params and separate by using “;” . I used this way and don’t have problems.

    My doubt is regarding the public IP, you need to use a fixed IP or the plugin has the ability to load the information of AWS and detect this change when the instances start.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s