Skip to content
This repository was archived by the owner on Jul 11, 2019. It is now read-only.
Open
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
8 changes: 8 additions & 0 deletions tools/aws_lab_setup/provision_lab.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,11 @@
gather_facts: no
roles:
- email

- name: Email inventory to instructor
hosts: localhost
connection: local
become: no
gather_facts: no
roles:
- email_instructor
4 changes: 4 additions & 0 deletions tools/aws_lab_setup/roles/email_instructor/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# sendgrid_user:
# sendgrid_pass:
# sendgrid_api_key:
email_instructor: False
19 changes: 19 additions & 0 deletions tools/aws_lab_setup/roles/email_instructor/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
- name: Send email to students with inventory attached
delegate_to: localhost
sendgrid:
username: "{{ sendgrid_user | default(omit) }}"
password: "{{ sendgrid_pass | default(omit) }}"
api_key: "{{ sendgrid_api_key | default(omit) }}"
subject: "[Ansible] Instructor Inventory Details"
body: |
Attached is the Ansible inventory to be used for training.<br>
Please check your ability to connect to each of the hosts via ssh.<br>
<br>
to_addresses: "{{ instructor_email }}"
html_body: yes
from_address: "{{ instructor_email }}"
attachments:
- "instructor_inventory.txt"
when: email_instructor
tags:
- email_instructor
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ ansible_port={{ ssh_port }}
[{{ user.username }}]
{% for host in instances.results %}
{% if user.username in host.invocation.module_args.instance_tags.Name %}
{{ host.invocation.module_args.instance_tags.Name | regex_replace(ec2_name_prefix ~ '-','') }} ansible_host={{ hostvars[host.invocation.module_args.instance_tags.Name]['ansible_host'] }} ansible_user={{ ec2_login_names[host.item.1.type] }}
{{ host.invocation.module_args.instance_tags.Name | regex_replace(ec2_name_prefix ~ '-','') }} ansible_host={{ hostvars[host.invocation.module_args.instance_tags.Name]['ansible_host'] }} ansible_user={{ user.username }} ansible_ssh_pass={{ admin_password }}
{% endif %}
{% endfor %}
{% endfor %}