Skip to content

Latest commit

 

History

History
61 lines (45 loc) · 1.24 KB

when_practice.md

File metadata and controls

61 lines (45 loc) · 1.24 KB

More Practice with WHEN and LOOPS!

student@bchd~$ vim whenpractice.yml

---
- name: When and Loops
  hosts: localhost
  vars:
    names_list:
      - Chad
      - Damian
      - Jason

  tasks:
    - name: Print that only YOUR name is awesome
      debug:
        msg: "{{ item }} is awesome!"
      loop: "{{ names_list }}"
      # CHALLENGE: Add a `when` condition here that this task only prints out YOUR name as awesome :)

student@bchd~$ ansible-playbook whenpractice.yml

3 Hints and a Solution

Gimme a hint!
  • Hint 1: Your name is being compared to the current item in the loop.
Need another hint?
  • Hint 2: You'll need to confirm that your name and the current item are the same.
Want another hint?
  • Hint 3: Use == to compare your name to the current item.
Want the answer?
  • Hint 4: Use the when condition like this:
    - name: Print that only YOUR name is awesome
      debug:
        msg: "{{ item }} is awesome!"
      loop: "{{ names_list }}"
      when: item == "YourName"

Replace "YourName" with your actual name.