diff --git a/tools/aws_lab_setup/provision_lab.yml b/tools/aws_lab_setup/provision_lab.yml
index 747bbe6d..dff20ac2 100644
--- a/tools/aws_lab_setup/provision_lab.yml
+++ b/tools/aws_lab_setup/provision_lab.yml
@@ -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
diff --git a/tools/aws_lab_setup/roles/email_instructor/defaults/main.yml b/tools/aws_lab_setup/roles/email_instructor/defaults/main.yml
new file mode 100644
index 00000000..e53479c1
--- /dev/null
+++ b/tools/aws_lab_setup/roles/email_instructor/defaults/main.yml
@@ -0,0 +1,4 @@
+# sendgrid_user:
+# sendgrid_pass:
+# sendgrid_api_key:
+email_instructor: False
diff --git a/tools/aws_lab_setup/roles/email_instructor/tasks/main.yml b/tools/aws_lab_setup/roles/email_instructor/tasks/main.yml
new file mode 100644
index 00000000..aa06f897
--- /dev/null
+++ b/tools/aws_lab_setup/roles/email_instructor/tasks/main.yml
@@ -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.
+ Please check your ability to connect to each of the hosts via ssh.
+
+ to_addresses: "{{ instructor_email }}"
+ html_body: yes
+ from_address: "{{ instructor_email }}"
+ attachments:
+ - "instructor_inventory.txt"
+ when: email_instructor
+ tags:
+ - email_instructor
diff --git a/tools/aws_lab_setup/roles/manage_ec2_instances/templates/instructor_inventory.j2 b/tools/aws_lab_setup/roles/manage_ec2_instances/templates/instructor_inventory.j2
index 38811f77..9ade0408 100644
--- a/tools/aws_lab_setup/roles/manage_ec2_instances/templates/instructor_inventory.j2
+++ b/tools/aws_lab_setup/roles/manage_ec2_instances/templates/instructor_inventory.j2
@@ -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 %}