I wrote this code to pull file from S3 bucket, change the file permission and execute the code. However, it's not working for me.
download_file_from_s3:
file.managed:
- name: /opt/agent_installer.sh
- source: s3://bucket_name/install.sh
change_file_permission:
file.managed:
- source: /opt/install.sh
- user: root
- group: root
- mode: 0744
run_rapid7_script:
cmd.run:
- name: /opt/install.sh
There are a couple of changes I can suggest looking at your code.
You are saving the file from S3 as
/opt/agent_installer.shwithfile.managed, let's consider that there is no issue with this.Now, the first thing that we obviously need to change in subsequent tasks, is to use this. Not
/opt/install.sh. Alsofile.managedcan be used once to download the file, change ownership, and permissions. So your SLS can look like:There is also a
cmd.scriptstate which can be used directly with the S3 URL assource, so there is no need to havefile.managedat all.So, just 1 state like below should be sufficient:
If you do have issue with downloading file from S3, then see the documentation on how to configure it correctly.