From 9945c09f6011aa5dcae59bdda7341505a9d8ac80 Mon Sep 17 00:00:00 2001 From: Nicholas Chia Date: Thu, 19 Apr 2018 09:07:19 +0800 Subject: [PATCH 1/8] Correct irritating typo in task name "inventroy" Change from "inventroy" to "inventory". --- tools/aws_lab_setup/roles/email/tasks/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/aws_lab_setup/roles/email/tasks/main.yml b/tools/aws_lab_setup/roles/email/tasks/main.yml index 396e2fc5..259d639c 100644 --- a/tools/aws_lab_setup/roles/email/tasks/main.yml +++ b/tools/aws_lab_setup/roles/email/tasks/main.yml @@ -1,4 +1,4 @@ -- name: Send email to students with inventroy attached +- name: Send email to students with inventory attached delegate_to: localhost sendgrid: username: "{{ sendgrid_user | default(omit) }}" From d2c30937e8be07c7169ba65fdd7e1f98c5bf702b Mon Sep 17 00:00:00 2001 From: Nicholas Chia Date: Tue, 3 Jul 2018 16:02:22 +0800 Subject: [PATCH 2/8] Propose updating instructor_inventory to closely match student_instance_inventory This update makes the instructor inventory clearer by explicitly stating username and admin_password to the inventory for each student login. I usually upload instructor inventory to gist during workshop. Removes ec2-user to avoid any confusion. --- .../manage_ec2_instances/templates/instructor_inventory.j2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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..04a7f199 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_password={{ admin_password }} {% endif %} {% endfor %} {% endfor %} From 6f0e3899115d0609e7edee6382bc05da6fcabaec Mon Sep 17 00:00:00 2001 From: Nicholas Chia Date: Tue, 3 Jul 2018 16:35:53 +0800 Subject: [PATCH 3/8] Update instructor_inventory.j2 --- .../manage_ec2_instances/templates/instructor_inventory.j2 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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..283af227 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 @@ -1,4 +1,4 @@ -[all:vars] +all:vars] {% if ssh_port is defined %} ansible_port={{ ssh_port }} {% endif %} @@ -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 %} From a7574f056551168a5b1d6ed522e539bc5d4ee645 Mon Sep 17 00:00:00 2001 From: Nicholas Chia Date: Tue, 3 Jul 2018 16:36:12 +0800 Subject: [PATCH 4/8] Update instructor_inventory.j2 --- .../manage_ec2_instances/templates/instructor_inventory.j2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 283af227..516e4e53 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={{ user.username }} ansible_ssh_pass={{ admin_password}} +{{ 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 %} From f81044b734088eb72fcfe64320d965d44efd23bb Mon Sep 17 00:00:00 2001 From: Nicholas Chia Date: Tue, 3 Jul 2018 16:39:35 +0800 Subject: [PATCH 5/8] Update instructor_inventory.j2 --- .../manage_ec2_instances/templates/instructor_inventory.j2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 516e4e53..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 @@ -1,4 +1,4 @@ -all:vars] +[all:vars] {% if ssh_port is defined %} ansible_port={{ ssh_port }} {% endif %} From bbcbe96aad26f56ca2abd919804ceb83d5790c28 Mon Sep 17 00:00:00 2001 From: Nicholas Chia Date: Tue, 3 Jul 2018 16:47:37 +0800 Subject: [PATCH 6/8] Propose new role for emailing instructor_inventory.txt This role will email the instructor_inventory.txt when the extra_var email_instructor is set to True. Default is set to False. --- .../roles/email_instructor/tasks/main.yml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 tools/aws_lab_setup/roles/email_instructor/tasks/main.yml 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 From 4c7f7ea2380e934cc4c7a0d2861376eba38445fc Mon Sep 17 00:00:00 2001 From: Nicholas Chia Date: Tue, 3 Jul 2018 16:53:19 +0800 Subject: [PATCH 7/8] Default settings for email_instructor This is set to False by default and does not email the instructor_inventory.txt by default. --- tools/aws_lab_setup/roles/email_instructor/defaults/main.yml | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 tools/aws_lab_setup/roles/email_instructor/defaults/main.yml 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 From 841124c12c7e89c4a2e5ca6125034a43a57ddcef Mon Sep 17 00:00:00 2001 From: Nicholas Chia Date: Tue, 3 Jul 2018 16:57:33 +0800 Subject: [PATCH 8/8] Update to provision.yml to add task "Email inventory to instructor" This will email the instructor_inventory.txt with Sendgrid. Default is set to False. To enable, set email_instructor to "True" in the extra_vars.yml file. This update requires email_instructor role. --- tools/aws_lab_setup/provision_lab.yml | 8 ++++++++ 1 file changed, 8 insertions(+) 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