# here's a cool advanced topic about how to perform conditional logic in ansible without resorting
# to writing your own module that defines facts.  You can do that too, and it's easy to do, but
# often you just want to run a command and then decide whether to run some steps or not.  That's
# easy to do, and here we'll show you how.

- name: test playbook
  user: root
  hosts: all

  tasks:

      # it is possible to save the result of any command in a named register.  This variable will be made
      # available to tasks and templates made further down in the execution flow.  

      - action: shell grep hi /etc/motd
        ignore_errors: True
        register: motd_result

      # and here we access the register.  Note that variable is structured data because
      # it is a return from the command module.   The shell module makes available variables such as
      # as 'stdout', 'stderr', and 'rc'.  

      # here we run the next action only if the previous grep returned true

      - action: shell echo "motd contains the word hi"
        only_if: "${motd_result.rc} == 0"


