In salt states, we use "grains.host" to get the host details. How do we get the AWS EC2 availability zone name using salt grains?
In salt states, we use "grains.host" to get the host details. How do we get the AWS EC2 availability zone name using salt grains?
To get the hostname I give the below:
{%- if 'aws-dev-01' in grains.host %}
{%- set device = '.....' %}
To get the EC2 AZ name, are the below lines correct?
{%- if 'aws-dev-01' in grains.availability_zone %}
{%- set device = '.....' %}
do you know?
how many words do you know
See also questions close to this topic
-
Upload file from html when block public access is true
I am using
django-s3direct
to file uploadhttps://github.com/bradleyg/django-s3direct
Using IAM role setting because I upload the file from the server on ECS container.
Now I set the
blockPublicAccess
ofS3
false.When uploading images from html, there comes error.
https://s3.ap-northeast-1.amazonaws.com/static-resource-v/images/c64d6e593de44aa5b10dcf1766582547/_origin.jpg?uploads (403 (Forbidden) ) initiate error: static-resource-v/line-assets/images/c64d6e593de44aa5b10dcf1766582547/_origin.jpg AWS Code: AccessDenied, Message:Access Deniedstatus:403
OK, it is understandable.
Browser try to access the for initiation.
However there is any way to upload file from browser when blockPublicAccess is true??
-
Linux on Lightsail instance is asking for a password and it's not working
I'm trying to restart
mariaDB
on Ubuntu but it's not letting me.I enter:
systemctl restart mariadb
and get:
==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units === Authentication is required to restart 'mariadb.service'. Authenticating as: Ubuntu (ubuntu) Password: polkit-agent-helper-1: pam_authenticate failed: Authentication failure ==== AUTHENTICATION FAILED ===
I have the same password for all functions so I do not understand why it is not working. What can I do?
-
AWS Pinpoint sendMessages() Addresses param field error
I'm having trouble replicating the format of the params object's Addresses format in a way where I can easily add to the object.
If I use this as the params with
destinationNumber[0]
anddestinationNumber[1]
in the format of 1 + 9 digit number ie13334535667
then it sends the message to both numbers no problem.const params = { ApplicationId: applicationId, MessageRequest: { Addresses: { [destinationNumber[0]]: { ChannelType: 'SMS' }, [destinationNumber[1]]: { ChannelType: 'SMS' } }, MessageConfiguration: { SMSMessage: { Body: message, Keyword: registeredKeyword, MessageType: messageType, OriginationNumber: originationNumber } } } };
I'm trying to replicate this format for
Addresses
, but I'm gettingUnexpected key '13334535667' found in params.MessageRequest.Addresses['0']
. The format my console output shows for Addresses is[ { '12345678910': { ChannelType: 'SMS' } }, { '12345678911': { ChannelType: 'SMS' } } ]
I'm using a map to call this
function createPhoneMessagingObject(phoneNumber: string) { return { [phoneNumber]: { ChannelType: 'SMS' } }; }
I tried wrapping key in array like in phone object, but per the output, the brackets goes away so maybe there's an easier/more correct way of doing this. I appreciate any help!
-
API Gateway with EC2 Instance hosted API Integration
I am new to AWS I have hosted my API on EC2 Instance. Imported my API swagger file to Gateway. Now I want to call my EC2 instance API from API gateway how to integrate? should I choose integration type as HTTP, If yes then for each endpoint I have to map it manually in EndPoint section or should I integrate it with my EC2 instance
-
Python code stops automatically after 2-4 hours on AWS EC2
i have a python code which runs on my laptop for 24 hours and the same code on EC2 instance stops after couple of hours. This is a code which operates on a broker API and fetches historical data, generates candles and then send trade signals to the broker
-
Assign ELB Account to S3 Bucket Policy
I used the AWS console from the load balancer edit attributes screen and used it to create a bucket to use for access logging. I'm using this policy to form CDK code in typescript to stand up new S3 buckets to use for access logging in higher level environments where I cannot use the console. This is the policy I need to somehow form in typescript CDK code:
"Statement": [ { "Effect":Allow", "Principal": { "AWS": "arn:--ELB-arnstuff--:root" }, "Action": "s3:PutObject", "Resource": "arn:--S3-Bucket-arnstuff--/AWSLogs/123456789/*" } ]
I've managed to get the cdk code figured out to this point:
bucket.addToResourcePolicy( new cdk.aws_iam.PolicyStatement({ effect: awsIam.Effect.ALLOW, principals: //'**This is part I haven't figured out**', actions: ['s3:PutObject'], resources: ['${bucket.bucketArn}/*'] }) );
At this point I don't care if it's hard coded in the CDK, I just need something to help keep the ball rolling forward. Any help is appreciated, thanks
-
How to get conf value from airflow dag?
I want to get conf value from dag area.
"{{ dag_run.conf['company'] }}"
is recognized as a string.How can I get this value?
Values are passed fine when calling other dags.
t_trigger = TriggerDagRunOperator( task_id="t-trigger", trigger_dag_id="example_dag", conf={ "company": "{{ dag_run.conf['company'] }}", }, )
However, in the dag area the value is recognized as a string.
t_task_a = PythonOperator( task_id="t-task-a", python_callable=task-a, ) employees = Variable.get( "{{ dag_run.conf['company'] }}", # problem default_var=['company'], deserialize_json=True ) for employee in employees: t_employee_operator = PythonOperator( task_id=f"t-test-operator", python_callable=employee_operator, op_kwargs={"employee": employee} ) t_task_a >> t_employee_operator
-
How can I alternate the elements of multiple lists in Ansible?
I have multiple lists as input (all lists have the same length, but the input can have more than 3 lists). I want to create a list which is a sum of all input lists alternating their elements.
For example, given the following input:
data: - ['1','2','3','4','5'] - ['6','7','8','9','10'] - ['11','12','13','14','15']
I'm expecting the following output:
lst: [['1','6','11'],['2','7','12'],['3','8','13'],['4','9','14'],['5','10','15']]
This is what I've tried:
--- - name: zip more than 3 lists with loop hosts: localhost tasks: - name: Set facts set_fact: list: - ['1','2','3','4','5'] - ['6','7','8','9','10'] - ['11','12','13','14','15'] - name: zip to make pairs of both lists set_fact: lst: "{{ list[0] | zip(list[1]) | zip(list[2]) | list }}" - name: Debug ['1','6','11'],['2','7','13'],... debug: msg: "{{ item | flatten }}" loop: "{{ lst }}" - name: zip to make pairs of both lists set_fact: lst2: "{{ lst2 | default([]) | zip(ansible_loop.nextitem) | list }}" loop: "{{ list }}" loop_control: extended: yes - name: Debug debug: msg: "{{ lst2 }}"
The first
set_fact
outputs loop elements butlst
doesn't include the actual output I expect. And the limitation of the firstset_fact
is that I can't iterate in the loop due tozip
filter. I don't know how to acheive my goal. -
How to prevent Flask-WTF forms from closing modal when submitting invalid input?
I am trying to build a website where you can upload a video (this already works). But when submitting a wrong file format, the Flask-WTF form closes the modal. I want it to stay open.
(I am trying it first with an image PNG)
This is the form:
class VideoUploadForm(FlaskForm): video = FileField('Upload video', validators=[FileAllowed(['png']), FileRequired()]) submit = SubmitField('Upload')
This is the route:
@main.route("/video", methods=['GET', 'POST']) @login_required def video(): form = VideoUploadForm() if form.validate_on_submit(): f = form.video.data filename = secure_filename(f.filename) f.save(os.path.join( os.path.abspath(os.path.join(os.path.dirname(os.path.realpath(__file__)), os.pardir)), 'static\\videos', filename )) flash('Video has been succesfully uploaded', 'success') return redirect(url_for('main.video')) return render_template('video.html', title='Upload video', form=form)
This is the modal:
<div class="modal fade mt-5" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true"> <div class="modal-dialog" role="document"> <div class="modal-content"> <div class="modal-header"> <h5 class="modal-title" id="exampleModalLabel">Upload video</h5> <button type="button" class="close" data-dismiss="modal" aria-label="Close"> <span aria-hidden="true">×</span> </button> </div> <form method="POST" action="" enctype="multipart/form-data"> {{ form.hidden_tag() }} <div class="modal-body"> {% if form.video.errors %} {{ form.video(class="form-control form-control-lg is-invalid") }} <p class="mt-1 ml-1"><small>Allowed formats: mov, mp4</small></p> <div class="invalid-feedback"> {% for error in form.video.errors %} <span>{{ error }}</span> {% endfor %} </div> {% else %} {{ form.video }} <p class="mt-1 ml-1"><small>Allowed formats: mov, mp4</small></p> {% endif %} </div> <div class="modal-footer"> <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button> {{ form.submit(class="btn btn-primary") }} </div> </form> </div> </div> </div>
How to prevent the modal from closing when I try to upload a jpg file for example? For now it will close the modal and if opened again it shows the error message. But i want it to stay open so that you immediately can see the error message.
-
Saltstack Config job returns "The minion has not yet returned"
I am new to saltstack and I am trying to run a job using the SaltStack Config. I have a master and minion(Windows machine).
the init.sls file is the following:
{% set machineName = salt['pillar.get']('machineName', '') %} C:\\Windows\\temp\\salt\\scripts: file.recurse: - user: Administrator - group: Domain Admins - file_mode: 755 - source: salt://PROJECTNAME/DNS/scripts - makedirs: true run-multiple-files: cmd.run: - cwd: C:\\Windows\\temp\\salt\\scripts - names: - ./dns.bat {{ machineName }}
and the dns.bat file:
Get-DnsServerResourceRecordA -ZoneName corp.local
The main idea is to create DNS record, but for now I am trying to run only this command to check things out, but I get the following info message when I run the job:
"The minion has not yet returned. Please try again later."
I went to check out in the master and ran the command:
salt-run manage.status
and got the following:salt-run manage.status /usr/lib/python3.7/site-packages/requests/__init__.py:91: RequestsDependencyWarning: urllib3 (1.23) or chardet (4.0.0) doesn't match a supported version! RequestsDependencyWarning) down: - machine1 - machine2 - machine3 up: - saltmaster
I tried some commands, to restart the machines, but still no success. Any help would be appreciated! Thanks in advance!
-
Error passing a pillar variable with special characters to Salt's cmd.script
I'm doing some automation with Salt using cmd.script with Powershell as the shell. While passing arguments to the state module, I get the error " Cannot process argument transformation on parameter 'Conn_String'. Cannot convert value to type System.String." I saw this error can be resolved in a regular powershell script by wrapping the variable passed as an argument in single quotes('') but I don't know how I can achieve the same behavior in a salt state file where the variable is set using jinja as seen below. If I enclose Conn_String in single quotes like this
"-Conn_String" + 'Conn_String'
in the args, i get Conn_String in the PowerShell when I Write-Host instead of the actual connection string. I appreciate any help in resolving this.Here is an example of my state and PowerShell script:
# pillar info in state # content of Conn_String is "Server=testServer,2022;database=exampleDatabase;Integrated Security=SSP" {% set var1 = pillar['var1'] %} {% set var2 = pillar['var2'] %} {% set Conn_String = pillar['Conn_String'] %} {% set args = " -var1 " + var1 + " -var2 " + var2 + " -Conn_String " + Conn_String %} CallPowerShell: cmd.script: - source: {{ salt:// + pillar['var1'] + "/scripts/sendmail.ps1" %} - shell: powershell -cwd: D:\ - args: {{ args }} # The PowerShell script(sendmail.ps1) that is called param( [Parameter(Mandatory)] [string]$var2 [Parameter(Mandatory)] [string]$Conn_String ) Write-Host "$Conn_String" ...
-
Why does Bcrypt use salts for hashing?
I’ve recently found that Bcrypt hash function generates different outputs even when the inputs are the same. I searched for it and found that Bcrypt uses a salt consist of a random string and store it into the first 22 characters of its hash so that someone with the original string can authenticate. However, I don’t feel like it’s necessary and safer because if you are able to get the salt from the hash, you can easily go through it using the salt you found. For example, a hacker with a rainbow table can decipher a salted hash into the plain hash and compare it with the hashes in the table. I just don’t understand why it is built-in even though it requires more resources and time, but is not that effective.
-
Salt schedule not executing function
I have the scheduler enabled on my salt master. I have a job that is configured to execute a runner function on a list of machines every month, like this example:
schedule: updater: args: - L@machine1,machine2,machine3 cron: 0 * * * * enabled: true function: util.patch_selected jid_include: true maxrunning: 1 name: updater
I've confirmed that the runner function (including the arguments) works fine on its own, however the scheduler does not execute the runner function. I've run
salt-run saltutil.sync_runner
on the master, andsalt '*' saltutil.refresh_pillar
on all the minions. What am I missing to get this running?