Featured resource
2025 Tech Upskilling Playbook
Tech Upskilling Playbook

Build future-ready tech teams and hit key business milestones with seven proven plays from industry leaders.

Check it out
  • Lab
    • Libraries: If you want this lab, consider one of these libraries.
    • Cloud
Google Cloud Platform icon
Labs

Working with AMIs Using Ansible

Image creation in AWS provides for both simplified system management and improved deployment performance. Ansible can be leveraged to automate AMI upkeep, and we will be doing just that in this exercise!

Google Cloud Platform icon
Lab platform
Lab Info
Level
Intermediate
Last updated
Sep 22, 2025
Duration
30m

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.
Table of Contents
  1. Challenge

    Create `/home/ansible/updateAMI.yml`, and Add an Ansible Play that Updates the Software on `node1` Then Updates `/home/ansible/image.txt`, as Described in the Instructions

    In our solution, we'll complete the required steps and add a task for collecting facts from EC2 metadata, which will help us collect the instance ID of node1.

    Edit the playbook such that it resembles the following:

    - hosts: node1
      become: yes
      tasks:
        - name: Update packages
          yum:
            name: "*"
            state: latest
        - name: Update image.txt
          lineinfile:
            path: /home/ansible/image.txt
            line: "Image updated {{ ansible_date_time.date }}"
        - name: Gather facts
          ec2_metadata_facts:
    
  2. Challenge

    Edit the `/home/ansible/updateAMI.yml` and Add an Ansible Play that Collects the instance_id of `node1`, stops `node1`, Creates the AMI as Described in the Instructions, and Stores the AMI ID in the File `/home/ansible/ami.txt`

    We will be using the facts we collected in the first play to satisfy the objectives for this task.

    Edit the playbook such that it resembles the following:

    - hosts: localhost
      tasks:
        - name: Stop node1
          local_action: ec2
          args:
            region: us-east-1
            state: stopped
            instance_id: "{{ hostvars['node1'].ansible_ec2_instance_id }}"
            wait: yes
        - name: Create AMI
          local_action: ec2_ami
          args:
            state: present
            instance_id: "{{ hostvars['node1'].ansible_ec2_instance_id }}"
            name: UpdatedImage
          register: ami_output
        - name: Write AMI info to file
          lineinfile:
            create: yes
            path: /home/ansible/ami.txt
            line: "{{ ami_output.image_id }}"
    
  3. Challenge

    Run `/home/ansible/updateAMI.yml` to Perform the Required Tasks and Then Log into the AWS Console to Verify Your Work
    • Change some environment variables:
      • source keys.sh
    • Run the playbook:
      • ansible-playbook /home/ansible/updateAMI.yml
    • Log into the AWS Console and confirm the new EC2 instance:
      • Search for "EC2" in the AWS console search and select the EC2 dashboard.
    • Confirm the AMI was updated:
      • Select AMIs from the menu on the left.
About the author

Pluralsight Skills gives leaders confidence they have the skills needed to execute technology strategy. Technology teams can benchmark expertise across roles, speed up release cycles and build reliable, secure products. By leveraging our expert content, skill assessments and one-of-a-kind analytics, keep up with the pace of change, put the right people on the right projects and boost productivity. It's the most effective path to developing tech skills at scale.

Real skill practice before real-world application

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Learn by doing

Engage hands-on with the tools and technologies you’re learning. You pick the skill, we provide the credentials and environment.

Follow your guide

All labs have detailed instructions and objectives, guiding you through the learning process and ensuring you understand every step.

Turn time into mastery

On average, you retain 75% more of your learning if you take time to practice. Hands-on labs set you up for success to make those skills stick.

Get started with Pluralsight