Skip to content

Add ec2 user data scripts #247

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open

Add ec2 user data scripts #247

wants to merge 22 commits into from

Conversation

Yarkrn
Copy link
Collaborator

@Yarkrn Yarkrn commented Jul 6, 2025

Adding 2 scripts for launching AWS EC2 instances Windows and Linux, the scripts are applied as user data.
The scripts create FSXn volume and mount it to the the instance while installing all the required libraries for that action.

@Yarkrn Yarkrn added the enhancement New feature or request label Jul 6, 2025
@Yarkrn Yarkrn requested a review from kcantrel as a code owner July 6, 2025 07:14
Copy link
Contributor

github-actions bot commented Jul 6, 2025

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

Copy link
Collaborator

@kcantrel kcantrel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your submission, however, there are a few things that need to be fixed before it can be approved:

  1. It needs to get a successful pass from GitHub's 'Super Linter'. Both the PowerShell and the bash scripts have things it didn't like.
    a) For the bash version, looks like you just need to put double quotes around the "initial setting" that has spaces in it.
    b) The PowerShell lint found lots of things it didn't like. I don't think you have to fix the informational ones, but it would be nice. The one 'Error' one will probably require you to simply adding an exception for that one error for that one function.
  2. I saw the following issue with the README file:
    a) You should probably mention it will create a LUN as well as a volume.
    b) The correct abbreviation of FSx for ONTAP is "FSxN" (not FSXn).
    c) There are places where it is not formatted correctly. Please review the README file from the GitHub page. You should be able to spot the issues.
  3. I saw the following issues with the Linux script:
    a) "The FSXN_PASSWORD" variable is assigned at top. That should be deleted since you are using secrets.
    b) The ONTAP_USER variable assignment should be moved to the "user data" block so users will know they can easily change the ONTAP username that the script will use.
    c) The fsxnSshCommand() function is never used so it should be deleted.
    d) The "checkCommnd on line 83 will report the status of the grep command, not whether the sed command was successful.
    e) You should use 'systemctl' instead of 'service'. For example. to start the iscsi service you should run systemctl start iscsid. You should probably enabling it first. Enabling it means it will start every time the system boots. systemctl enable iscsid. Also to check that a service is running, the following is better than grep'ing the output: systemctl is-active --quiet service. The exit code will be 0 for running, non-zero for anything else. So, you could use your CheckCommand after calling that.
    f) Note that the 'user-data' script is run as 'root' so you really don't need to put 'sudo' in front of any commands.
    g) You should maybe consider using 'curl' with ONTAP APIs instead of 'ssh'. Mostly because then you could more programmatically look at the output and provide useful error messages.
  4. I saw the following issues with the PowerShell script:
    a) I don't know if that is your AWS account ID in the example script ARN, but if it is, you should replace it with an obvious mock number.
    b) You should move the $user variable assignment to the top with the other variable assignments.
    c) I'm sure it is just me, since I don't mess with PowerShell much, but I'm not seeing where the ONTAP PowerShell tool kit is being installed

@@ -24,13 +24,15 @@ function unInstall {
}

# default values
# All FSxN instances are created with the user 'fsxadmin' which can't be changed
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All FSxN instance are created with a default admin user with the name of 'fsxadmin' but there is nothing to stop you, and many customers do this, from creating new users. especially if the user is going to be used in automation. That way they can create a user that only has the permissions it needs to do the tasks that the automation will ask it to do. Please support this capability.

Fixed formatting and other issues.
LUN_NAME=${VOLUME_NAME}_$(($RANDOM%($max-$min+1)+$min))

# defaults
# All FSxN instances are created with the user 'fsxadmin' which can't be changed
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All FSxN instance are created with a default 'fsxadmin' user, but there is nothing stopping you from creating additional ones, Please support this capability.

catch {
Write-Output "Failed to add igroup initiator, due to: $_" >> $currentLogPath
Write-Host "Failed to add igroup initiator, due to: $_" -ForegroundColor Red
unInstall $printUninstallConnect
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be passing the $ip $credentials $svm_name parameters? Looks like $printUninstallConnect was set to $true on line 190, but never set to $false before this line, so I'm guessing that could cause issues with the call to Connect-NcController within the unInstall function

Looks like there are many instances of this below.

Created some exceptions to the PowerShell lint program. I couldn't add them to the source itself, because it was a file to be included as a "userdata" for an EC2 instance and therefore it had to have <powershell> as the first line. This caused the PowerShell lint to ignore the in source directives.
@kcantrel
Copy link
Collaborator

kcantrel commented Jul 8, 2025

I created a parameter file for the PowerShell Analyzer that forced it to exclude the 'PSAvoidUsingConvertToSecureStringWithPlainText', 'PSAvoidTrailingWhitespace' and 'PSAvoidUsingWriteHost' rules. There are just a few warnings left. Please try to address them.

@kcantrel
Copy link
Collaborator

kcantrel commented Jul 8, 2025

You may have noticed I totally redid README file. I felt it was probably easier to do that than try and explain the issues.

use systemctl instead of service for iscsi operations
@Yarkrn
Copy link
Collaborator Author

Yarkrn commented Jul 9, 2025

  • In the power shell script lines 69-82 import NetApp.ONTAP package if its not exists.
  • service was changed to systemctl
  • using curl instead of ssh is possible but requires lot of efforts, it can be done later

Fix linter warnings
ONTAP_USER=fsxadmin
LOG_FILE=/home/ec2-user/install.log

VOL_SIZE=$(echo $VOLUME_SIZE | sed 's/.$//')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you should just assume the user put a 'g' at the end. Maybe change to:
VOL_SIZE=$(echo $VOLUME_SIZE | sed 's/g$//')

# verify read write
# example: echo "test mount iscsci" > /mnt/myIscsi/testIscsi.txt
echo "test mount iscsci" > /$directory_path/$mount_point/testIscsi.txt
cat /$directory_path/$mount_point/testIscsci.txt
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should you check that these commands succeeded? Otherwise, why do the test?

Also, you should probably delete the test file after you are done.

@kcantrel
Copy link
Collaborator

kcantrel commented Jul 9, 2025

You should update the /etc/fstab in the Linux script so that the LUN is mounted when the system is rebooted. Also, maybe put a comment in the README file that if they want it to be mounted somewhere else, they should create the desired directory and update the /etc/fstab file and reboot.

kcantrel and others added 5 commits July 9, 2025 15:58
- Set LUN size to 90% of vol size
- Make disk persist after boot 
- Move ONTAP_USER to user data section
- Fix check of multi session update
- Fix check if service is running
add notes regarding actual volume size and process running time
Fix lint issue
Fix mount disk after restart
Fix lun size to 90% of vol size
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants