Let’s Play: RHCE 8/Ansible Training

I’ll be using this space for notes and do-dads in prep for RHCE 8 training. Might as well make them public, might help someone :))

Tips from Reddit:

Don’t waste your time. Instead, if you want just the parameters + what they do:

$ ansible-doc -s copy
- name: Copy files to remote locations
      attributes:            # The attributes the resulting file or directory should have. To get supported flags look at the man page for `chattr' on the target system. This string should contain the attributes in the same order as the one displayed by `lsattr'. The `=' operator is assumed as default, otherwise `+' or `-' operators need to be included in the string.
      backup:                # Create a backup file including the timestamp information so you can get the original file back if you somehow clobbered it incorrectly.
      checksum:              # SHA1 checksum of the file being transferred. Used to validate that the copy of the file was successful. If this is not provided, ansible will use the local calculated checksum of the src file.
      content:               # When used instead of `src', sets the contents of a file directly to the specified value. Works only when `dest' is a file. Creates the file if it does not exist. For advanced formatting or if `content' contains a variable, use the [template] module.
      decrypt:               # This option controls the autodecryption of source files using vault.
      dest:                  # (required) Remote absolute path where the file should be copied to. If `src' is a directory, this must be a directory too. If `dest' is a non-existent path and if either `dest' ends with "/" or `src' is a directory, `dest' is created. If `dest' is a relative path, the starting directory is determined by the remote host. If `src' and `dest' are files, the parent directory of `dest' is not created and the task fails if it does not already exist.

and if you want just the examples:

$ ansible-doc copy | grep EXAMPLES -A 100 | less

if you are using Vim, you can even redirect this to another buffer and quickly copy / paste:

:r! ansible-doc ...

The only ones that you might want to memorize are less than a handful such as immediate for firewalld for the changes to occur in the runtime configuration


Announcing the evolution of the Red Hat Certified Engineer program

Much of what is tested in the Red Hat Certified Specialist in Ansible Automation exam (EX407) will form the foundation of the new RHCE exam. 

Sample Exam (Supposedly harder than the RHCE)

Red Hat Enterprise Linux (RHEL) System Roles

An environment made as a preparation for RHCE [EX294] exam


$cat first_pb.yml 

- name: Getting Started First Playbook
  gather_facts: true
  hosts: all

        - name: Print all available facts
            var: ansible_facts['nodename']
~/plays danny% ansible-playbook -u danny -k first_pb.yml
SSH password: 

PLAY [Getting Started First Playbook] *************************************************************************************************************************************************************************

TASK [Gathering Facts] ****************************************************************************************************************************************************************************************
ok: [23.253.245.xxx]

TASK [Print all available facts] ******************************************************************************************************************************************************************************
ok: [23.253.245.xxx] => {
    "ansible_facts['nodename']": "heel-2020",
    "changed": false

PLAY RECAP ****************************************************************************************************************************************************************************************************
23.253.245.xxx             : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
:~/plays danny% cat loadavgout.yml 

- name: Load Average Output (3 ways)
  hosts: all 

        - name: first task
          command: sar -q
          register: sarq

        - debug: msg="{{ sarq.stdout }}"

        - debug: var=sarq

        - debug: var=sarq.stdout_lines


Leave a Reply

Your email address will not be published. Required fields are marked *