Spec-Zone.ru › Ansible

Working with playbooks

Playbooks record and execute Ansible’s configuration, deployment, and orchestration functions. They can describe a policy you want your remote systems to enforce, or a set of steps in a general IT process.

If Ansible modules are the tools in your workshop, playbooks are your instruction manuals, and your inventory of hosts is your raw material.

At a basic level, playbooks can be used to manage configurations of and deployments to remote machines. At a more advanced level, they can sequence multi-tier rollouts involving rolling updates and can delegate actions to other hosts, interacting with monitoring servers and load balancers along the way.

Playbooks are designed to be human-readable and are developed in a basic text language. There are multiple ways to organize playbooks and the files they include, and we’ll offer up some suggestions on that and making the most out of Ansible.

  • Templating (Jinja2)
    • Jinja2 Example
  • Using filters to manipulate data
    • Handling undefined variables
    • Defining different values for true/false/null (ternary)
    • Managing data types
    • Formatting data: YAML and JSON
    • Combining and selecting data
    • Randomizing data
    • Managing list variables
    • Selecting from sets or lists (set theory)
    • Calculating numbers (math)
    • Managing network interactions
    • Hashing and encrypting strings and passwords
    • Manipulating text
    • Manipulating strings
    • Managing UUIDs
    • Handling dates and times
    • Getting Kubernetes resource names
  • Tests
    • Test syntax
    • Testing strings
    • Vault
    • Testing truthiness
    • Comparing versions
    • Set theory tests
    • Testing if a list contains a value
    • Testing if a list value is True
    • Testing paths
    • Testing size formats
    • Testing task results
    • Type Tests
  • Lookups
    • The lookup function
    • The query/q function
  • Python3 in templates
    • Dictionary views
    • dict.iteritems()
  • The now function: get the current time
  • The undef function: add hint for undefined variables
  • Loops
    • Comparing loops
    • Using loops
    • Ensuring list input for loop: using query rather than lookup
    • Adding controls to loops
    • Nested Loops
    • Migrating from with_X to loop
  • Controlling where tasks run: delegation and local actions
    • Tasks that cannot be delegated
    • Delegating tasks
    • Templating in delegation context
    • Delegation and parallel execution
    • Delegating facts
    • Local playbooks
  • Conditionals
    • Basic conditionals with when
    • Debugging conditionals
    • Commonly-used facts
  • Blocks
    • Grouping tasks with blocks
    • Handling errors with blocks
  • Handlers: running operations on change
    • Handler example
    • Notifying handlers
    • Notifying and loops
    • Naming handlers
    • Handler insertion order into the play
    • Controlling when handlers run
    • Defining when tasks change
    • Using variables with handlers
    • Handlers in roles
    • Includes and imports in handlers
    • Meta tasks as handlers
    • Limitations
  • Error handling in playbooks
    • Ignoring failed commands
    • Ignoring unreachable host errors
    • Resetting unreachable hosts
    • Handlers and failure
    • Defining failure
    • Defining “changed”
    • Ensuring success for command and shell
    • Aborting a play on all hosts
    • Controlling errors in blocks
  • Setting the remote environment
    • Setting the remote environment in a task
  • Working with language-specific version managers
  • Reusing Ansible artifacts
    • Creating reusable files and roles
    • Reusing playbooks
    • When to turn a playbook into a role
    • Reusing files and roles
    • Reusing tasks as handlers
  • Roles
    • Role directory structure
    • Storing and finding roles
    • Using roles
    • Role argument validation
    • Running a role multiple times in one play
    • Using role dependencies
    • Embedding modules and plugins in roles
    • Sharing roles: Ansible Galaxy
  • Module defaults
    • Module defaults groups
  • Interactive input: prompts
    • Hashing values supplied by vars_prompt
    • Allowing special characters in vars_prompt values
  • Using variables
    • Creating valid variable names
    • Simple variables
    • When to quote variables (a YAML gotcha)
    • List variables
    • Dictionary variables
    • Combining variables
    • Registering variables
    • Referencing nested variables
    • Transforming variables with Jinja2 filters
    • Where to set variables
    • Variable precedence: where should I put a variable?
    • Using advanced variable syntax
  • Discovering variables: facts and magic variables
    • Ansible facts
    • Information about Ansible: magic variables
  • Play Argument Validation
  • Specification Format
  • Sample Specification
  • Playbook Example: Continuous Delivery and Rolling Upgrades
    • What is continuous delivery?
    • Site deployment
    • Reusable content: roles
    • Configuration: group variables
    • The rolling upgrade
    • Managing other load balancers
    • Continuous delivery end-to-end

© 2012–2018 Michael DeHaan
© 2018–2025 Red Hat, Inc.
Licensed under the GNU General Public License version 3.
https://docs.ansible.com/projects/ansible/latest/playbook_guide/playbooks.html

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API