DevOps Classroom Series – 19/May/2021

Ansible Variable Precedence

  • In Ansible we can define the variables at multiple places.
  • If the variable is defined only once then that variable will be applied, But if the variable is defined at multiple places (inventory file, host_vars, group_vars, role_defaults,…) then ansible has a precedence for variables
  • Refer Here for the official docs
  • Refer Here for the change set Preview
  • Refer Here for the next change set

Ansible Forks and controlling playbook execution

  • Fork: This represents how many parallel nodes can ansible execute. By default ansible is configured to run on 5 nodes
  • Ansible forks can be set
    • by passing argument to ansible-playbook command (ansible-playbook -f 20 ….)
    • Change the ansible.cfg and add the following which applies to all the ansible playbook executions
    [defaults]
    forks = 25
    

Debugging in Ansible

  • In Ansible we can resolve errors in the debugger
  • For that add debugger in the play (debugger: on_failed)
- name: test playbook
  hosts: all
  debugger: on_failed
  tasks:
    - name: Wrong variable
      file:
        path: "{{ file_name }}"
        state: touch
    - name: Learning
      debug:
        msg: "Learning debugging"
  • now execute the playbook Preview
  • Available debug commands
Command Shortcut Action
print p Prints information about the task
task.args[key] = value no shortcut Update module args
task_vars[key] = value no shortcut Update task variables
update_task u Recreate a task with updated task variables
redo r Run the task again
continue c Continue executing, starting with next task
quit q Quit the debugger

Preview Preview Preview

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Please turn AdBlock off
Floating Social Media Icons by Acurax Wordpress Designers

Discover more from Direct DevOps from Quality Thought

Subscribe now to keep reading and get access to the full archive.

Continue reading

Visit Us On FacebookVisit Us On LinkedinVisit Us On Youtube