Skip to content

Adding-aws-ses-role #2003

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

Merged
merged 4 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions roles/aws/aws_ses/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
_ses_domain: codeenigma.uk
region: "{{ _aws_region}}"

Check warning on line 2 in roles/aws/aws_ses/defaults/main.yml

View workflow job for this annotation

GitHub Actions / Lint the codebase

jinja[spacing]

Jinja2 spacing could be improved: {{ _aws_region}} -> {{ _aws_region }}
36 changes: 36 additions & 0 deletions roles/aws/aws_ses/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
- name: "Ensure {{ _ses_domain }} domain identity exists"
community.aws.ses_identity:
profile: "{{ _aws_profile }}"

Check warning on line 4 in roles/aws/aws_ses/tasks/main.yml

View workflow job for this annotation

GitHub Actions / Lint the codebase

jinja[spacing]

Jinja2 spacing could be improved: {{ _aws_region}} -> {{ _aws_region }}
identity: "{{ _ses_domain }}"
state: present
region: "{{ _aws_region}}"

- name: Gather AWS account ID if it isn't already set.
amazon.aws.aws_caller_info:
profile: "{{ _aws_profile }}"
delegate_to: localhost
register: aws_account_id

- name: Add sending authorization policy to domain identity
community.aws.ses_identity_policy:
identity: "{{ _ses_domain }}"
policy_name: AWSses
policy: "{{ lookup('template', 'ses.json.j2') }}"
state: present
region: "{{ _aws_region }}"

- name: Fetch SES domain CNAME
ansible.builtin.command: "aws ses verify-domain-dkim --domain {{ _ses_domain }} --region {{ _aws_region }}"
register: ses_dkim_attributes

- name: Add a DNS records in Route 53 for validation.
amazon.aws.route53:
state: present
zone: "{{ _ses_domain }}"
record: "{{ item }}._domainkey.{{ _ses_domain }}"
profile: "core"
type: CNAME
ttl: 300
value: "{{ item }}.dkim.amazonses.com"
loop: "{{ ses_dkim_attributes.stdout | from_json | json_query('DkimTokens') }}"
37 changes: 37 additions & 0 deletions roles/aws/aws_ses/templates/ses.json.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"ses:SendEmail",
"ses:PutEmailIdentityDkimAttributes",
"ses:PutEmailIdentityDkimSigningAttributes",
"ses:ListRecommendations",
"ses:BatchGetMetricData",
"ses:UntagResource",
"ses:TagResource",
"ses:PutEmailIdentityMailFromAttributes",
"ses:PutEmailIdentityFeedbackAttributes",
"ses:PutEmailIdentityConfigurationSetAttributes",
"ses:DeleteEmailIdentityPolicy",
"ses:DeleteEmailIdentity",
"ses:UpdateEmailIdentityPolicy",
"ses:CreateDeliverabilityTestReport",
"ses:CreateEmailIdentityPolicy",
"ses:GetDomainStatisticsReport",
"ses:GetEmailIdentityPolicies",
"ses:GetEmailIdentity",
"ses:SendBulkTemplatedEmail",
"ses:SendTemplatedEmail",
"ses:SendRawEmail"
],
"Principal": {
"AWS": [
"{{ aws_account_id.account }}"
]
},
"Resource": "arn:aws:ses:{{ _aws_region }}:{{ aws_account_id.account }}:identity/{{ _ses_domain }}"
}
]
}
Loading