Saturday, December 16, 2017

getting started with amazon AWS with Powershell

You first need windows and I got it from here
https://aws.amazon.com/powershell/
Now I do not want to show you my credentials to log in to my aws so that you can spin up your own workload on my credit card so I downloaded the csv file containing the access key ID and secret key.

1
2
3
4
5
$credCsv = 'C:\Users\gaju\Syncplicity Folders\aws_accessKeys.csv'
$csv = Import-Csv $credCsv
$keyId = $csv.'Access key ID'
$skey = $csv.'Secret access key'
Set-AWSCredential -AccessKey $keyId -SecretKey $skey -StoreAs batman

1. path to the credentials
2. import the csv file contents
3. extracting the access key ID and storing it as a variable to use later
4. extracting the secret access key from the csv
5. loging in to my AWS and storing it as a profile


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
PS C:\Users\gaju> $credCsv = 'C:\Users\gaju\Syncplicity Folders\aws_accessKeys.csv'
$csv = Import-Csv $credCsv
$keyId = $csv.'Access key ID'
$skey = $csv.'Secret access key'
Set-AWSCredential -AccessKey $keyId -SecretKey $skey -StoreAs batman
Get-AWSRegion

Region         Name                      IsShellDefault
------         ----                      --------------
ap-northeast-1 Asia Pacific (Tokyo)      False         
ap-northeast-2 Asia Pacific (Seoul)      False         
ap-south-1     Asia Pacific (Mumbai)     False         
ap-southeast-1 Asia Pacific (Singapore)  False         
ap-southeast-2 Asia Pacific (Sydney)     False         
ca-central-1   Canada (Central)          False         
eu-central-1   EU Central (Frankfurt)    False         
eu-west-1      EU West (Ireland)         False         
eu-west-2      EU West (London)          False         
sa-east-1      South America (Sao Paulo) False         
us-east-1      US East (Virginia)        False         
us-east-2      US East (Ohio)            False         
us-west-1      US West (N. California)   False         
us-west-2      US West (Oregon)          False   

Now you see that when you run Get-AWSRegion I get a list of all the available regions.This is the time you want to play with it. Whenever you start automating or scripting stuff, you should and must always start only with getting information. Generating reports etc., which will safely allow you to get a hang on the eco system. You do not want to accidentally do something which you will regret for life.

Amazon AWS automation with python

I hate the fact that AWS GUI keeps changing (atleast now, may be not that much in future) so fast that you wonder where some stuff is which you used yesterday. It is time for me to get my hands dirty with aws via text, that is cli, python etc.,
you need the following though

  1. aws account (duhh...of course you should)
  2. python and pip installed and working
  3. aws cli
    https://aws.amazon.com/cli/
  4. boto3 (pip install boto3
    or if you are a not python aficionado or pythonista then you can choose your own diet her
    http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-welcome.html
Now do the following

aws configure

you will notice that it asks for a key. Go to AWS IAM and create a new user and do not use root user. give necessary permissions and rights to this user.
click on the user
security credentials tab
generate access key
download the csv file
use the details of the csv file when you run aws configure
leave the default region name empty
default output format, set this to json (yes I like json over others, blow me :p)
Note : you cannot recover a lost key. you can only generate a new one. delete the lost access key id and key pair and keep only the one which are in use and relevant.

Tuesday, December 12, 2017

Python 3.6 Json

https://github.com/MrAmbiG/LearningPython

Cloning the Dell iDRAC configuration to others

Hopefully this is the last among-st my series of iDRAC configuration automation. This takes one source machine as reference, takes the xml and pushes it to all the others. Whatever changes that you want to edit or omit, you can when the script is paused for you to update the csv files.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
$source = '10.1.211.222'
$user = 'root'
$pass = 'P@ssword'
$filename = "$source.xml"
$sourceXml = "$psscriptroot"+"$filename"
if (!$sourceXml) {
racadm -r $server -u $user -p $pass get -t xml -f $sourceXml
} else { Read-Host "There is an existing $sourceXml sourcefile configuration, Hit enter/return to use the same" }

Write-Host "
A CSV file will be opened (open in excel/spreadsheet)
populate the values,
save & close the file,
Hit Enter to proceed
" -ForegroundColor Blue -BackgroundColor White

$csv = "$PSScriptRoot/nameCompare.csv"
get-process | Select-Object idrac_ip_address| Export-Csv -Path $csv -Encoding ASCII -NoTypeInformation
Start-Process $csv
Read-Host "Hit Enter/Return to proceed"
Write-Host "processing your entries from the csv file...."
$csv = Import-Csv $csv
 foreach ($line in $csv) 
 {
    $server = $($line.server)
    racadm -r $server -u $user -p $pass set -t xml -f $sourceXml
 }








automating the configuration of snmp settings on Dell iDRAC

This is one of my many posts of automating individual tasks on dell iDRACs. It was intended for our VxRacks but otherwise useful for all iDRACs.
http://topics-cdn.dell.com/pdf/idrac7-8-lifecycle-controller-v2.40.40.40_reference%20guide_en-us.pdf


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<#
.SYNOPSIS
    set the snmp for dell iDRAC servers
.DESCRIPTION
    opens up a csv file. put the ip addresses of idrac, root password, snmp address
.NOTES
    File Name      : idracSetSnmp.ps1
    Author         : gajendra d ambi
    Date           : Dec 2017
    Prerequisite   : PowerShell v4+, Dell OpenManage DRAC Tools, includes Racadm (64bit) v8.1 or higher
    Copyright      - None
.LINK
    Script posted over: github.com/MrAmbiG/
#>
#Start of Script
Write-Host "
A CSV file will be opened (open in excel/spreadsheet)
populate the values,
save & close the file,
Hit Enter to proceed
" -ForegroundColor Blue -BackgroundColor White

$csv = "$PSScriptRoot/idracSetSnmp.csv"
get-process | Select-Object idrac_ip_address, root_password, snmpAddress, snmpString | Export-Csv -Path $csv -Encoding ASCII -NoTypeInformation
Start-Process $csv
Read-Host "Hit Enter/Return to proceed"
Write-Host "processing your entries from the csv file...."
$csv = Import-Csv $csv
foreach ($line in $csv)
{
    $idrac_ip_address = $($line.idrac_ip_address)
    $root_password = $($line.root_password)
    $snmpAddress = $($line.snmpAddress)
    $snmpString = $($line.snmpString)
    $user = 'root'
    # enable snmp
    write-host enabling snmp agent -ForegroundColor Green
    racadm -r $idrac_ip_address -u $user -p $root_password --nocertwarn set iDRAC.SNMP.AgentEnable 0
    write-host setting snmp TrapFormat v2 -ForegroundColor Green
    racadm -r $idrac_ip_address -u $user -p $root_password --nocertwarn set iDRAC.SNMP.TrapFormat 1
    write-host setting snmp target $snmpAddress
    racadm -r $idrac_ip_address -u $user -p $root_password --nocertwarn set iDRAC.SNMP.Alert.DestAddr $snmpAddress
    write-host setting snmp community string $snmpString
    racadm -r $idrac_ip_address -u $user -p $root_password --nocertwarn set iDRAC.SNMP.AgentCommunity $snmpString
    write-host enabling snmp alert -ForegroundColor Green
    racadm -r $idrac_ip_address -u $user -p $root_password --nocertwarn set iDRAC.SNMP.Alert.Enable 1
}