Skip to content
This repository has been archived by the owner on Jul 11, 2019. It is now read-only.

[Provisioner] Instructor_inventory to closely match student_instance_inventory #335

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
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 %}