Courseiva
EX294Chapter 16 of 18Objective 6.2

Ansible Pull and Push Patterns

Ansible pull mode lets managed nodes fetch their own configuration instructions from a central repository instead of waiting for a control node to push them. This matters for the EX294 exam because you must know when to use push vs pull and how to configure ansible-pull correctly. Red Hat tests whether you understand that pull mode is essential for managing nodes that are offline, behind firewalls, or too numerous for a single control node to reach.

12 min read
Advanced
Updated Jul 23, 2026
Editorial oversight: Johnson Ajibi· Security Systems Architect · MSc IT Security · IEEE Senior Member

A simple way to picture Ansible Pull and Push Patterns

The Restaurant Kitchen Analogy

4 chefs work in a busy restaurant kitchen. Each chef has a printed recipe card taped to their station for cooking the same dish. When the head chef updates the recipe, they must walk to each of the 4 stations and replace every card by hand. That is the push pattern. One chef is responsible for making sure everyone follows the latest recipe. Now imagine a different system: each chef has a tablet that auto-downloads the latest recipe from a central server every 15 minutes. The chefs do not wait for the head chef to walk over. Each tablet pulls the new recipe automatically. That is the pull pattern.

The push pattern works well when you have a few chefs right next to each other. But if the restaurant chain has 200 locations across the country, the head chef cannot physically walk to each station. The pull pattern scales because each station checks for updates on its own schedule. In Ansible, the control node pushes playbooks to managed nodes in push mode. In pull mode, each managed node runs ansible-pull to fetch the latest playbook from a central Git repository and applies it locally. The system administrator does not need to be online or connected to every node at once.

How It Actually Works

Ansible is an automation tool that configures servers, installs software, and runs commands across multiple machines. In a standard setup, you have one control node — a laptop or server — that stores your playbooks. A playbook is a YAML file containing a list of tasks. The control node connects to managed nodes over SSH and pushes the playbook to them. This is the push pattern.

The push pattern works well when all managed nodes are reachable over the network and the control node can initiate connections to every machine at once. But real environments often have nodes that are not always online, such as laptops that employees take home, servers in a factory that lose internet at night, or devices behind strict firewalls that block inbound SSH. In those cases, the control node cannot push because it cannot start the connection.

Ansible pull mode solves this by reversing the direction. Instead of the control node pushing the playbook to each managed node, each managed node runs a command called ansible-pull. That command connects to a version control repository — usually Git — and downloads the latest playbook. Then it runs that playbook locally on the node itself. The node effectively pulls its own configuration.

Here is how it works step by step. First, you store your playbook in a Git repository. Git is a version control system that tracks changes to files over time. Every time you update the playbook, you commit and push the changes to the repository. Second, on each managed node, you install Ansible. Third, you set up a cron job, which is a scheduled task, that runs ansible-pull at a regular interval, for example every hour. Fourth, when the cron job runs, ansible-pull clones the Git repository to a local directory. Cloning means downloading the entire repository so the node has a local copy. Fifth, ansible-pull runs the playbook from that local copy, applying the desired state to the node.

The ansible-pull command accepts several important options. The -U or --url flag specifies the Git repository URL. The -d or --directory flag sets where to clone the repository locally. The -i or --inventory flag points to an inventory file if you need to target specific nodes. The --accept-host-key flag automatically accepts the Git server's host key, which avoids interactive prompts. The -C or --checkout flag selects a specific branch or tag. The -o or --only-if-changed flag tells ansible-pull to only run the playbook if the repository has changed since the last pull.

Why does pull mode matter for the EX294 exam? Red Hat wants you to know that pull mode is not a replacement for push mode. It is a specialised tool for specific scenarios. You must understand the ansible-pull command syntax, the required options, and how to test a pull setup. The exam may ask you to write a cron job that runs ansible-pull every 30 minutes, or to debug why a pull did not apply the latest playbook changes. You must also know that pull mode requires Git to be installed on the managed nodes, and that the managed node must have network access to the Git repository.

Key terms to remember:

- ansible-pull: the command each managed node runs to fetch and apply a playbook from a Git repository. - Git repository: a remote storage location for your playbook files, typically hosted on GitHub, GitLab, or a private server. - cron: a Linux utility that runs commands at scheduled times. You use it to schedule ansible-pull to run periodically. - control node: the machine where you normally run ansible commands in push mode. In pull mode, the control node role shifts to the Git repository. - managed node: the machine that Ansible configures. In pull mode, the managed node initiates the connection to the Git repository.

This diagram shows the pull pattern: the control node pushes changes to a Git repository, and each managed node pulls the playbook from that repository to apply it locally.

Walk-Through

1

Store the playbook in a Git repository

You create a playbook file (e.g., site.yml) and push it to a Git repository that all managed nodes can access. The repository becomes the single source of truth for the configuration.

2

Install Git and Ansible on each managed node

The managed node needs both Git to clone the repository and Ansible to run the playbook. Without Git, ansible-pull will fail with a 'git not found' error.

3

Write the ansible-pull command with required options

You construct the command with -U for the repository URL, -d for the local directory, and -o to only run if changed. For example: ansible-pull -U https://example.com/repo.git -d /opt/ansible -o

4

Set up a cron job to run the command periodically

You edit the root crontab using crontab -e and add a line like: 0 * * * * /usr/bin/ansible-pull -U https://example.com/repo.git -d /opt/ansible -o. This runs the command every hour.

5

Test the pull on one managed node

You run the ansible-pull command manually on one node to verify it clones the repository and runs the playbook correctly. You check the output for errors and confirm the desired state is applied.

6

Update the playbook and push to the Git repository

When you need to change the configuration, you edit the playbook locally, commit the change, and push to the repository. The managed nodes will pull the new version on their next scheduled cron run.

What This Looks Like on the Job

Maria works as a systems administrator for a retail company with 500 point-of-sale terminals in shops across the country. Each terminal is a Linux server running inventory management software. The terminals are behind highly restrictive firewalls that block inbound SSH connections. Maria cannot use push mode because her control node cannot initiate connections to the terminals. She must use pull mode.

First, Maria sets up a private Git repository on a central server that the terminals can reach over HTTPS. She creates a playbook named pos-config.yml that installs security updates, updates the inventory application, and configures the network settings. She commits and pushes the playbook to the repository.

Next, Maria writes a script that runs ansible-pull on each terminal. The script uses these options:

- -U https://git.company.internal/ansible/pos-playbook.git - -d /opt/ansible/pull - -o (only run if changed) - --accept-host-key - -C main (use the main branch)

She then sets up a cron job on each terminal to run this script every hour. She uses the root user's crontab to ensure the playbook has permission to make system changes. The cron line looks like this: 0 * * * * ansible-pull -U https://git.company.internal/ansible/pos-playbook.git -d /opt/ansible/pull -o --accept-host-key -C main.

Three weeks later, a critical security patch is released for the inventory software. Maria updates the playbook in the Git repository and pushes the change. Over the next hour, all 500 terminals pull the updated playbook and apply the patch automatically. Maria does not need to log into each terminal or wait for a maintenance window. The pull pattern handles the scale.

A common real-world requirement is to set up a pull interval that balances timeliness with network load. Maria chose hourly because the terminals have limited bandwidth. If a node misses its pull because the terminal is powered off, it will pull the next time it boots and the cron job runs. Maria also added logging to the cron job so she can audit which terminals pulled which version of the playbook.

The key lesson: pull mode frees the administrator from being the single point of failure. If Maria's control node crashes, the terminals continue to pull the latest playbook from Git. They do not depend on Maria's machine being online.

How EX294 Actually Tests This

The EX294 exam tests your ability to configure and use Ansible pull mode. You will see questions that ask you to write the exact ansible-pull command to accomplish a given task. You must memorise the key options and their flags. The exam also tests the difference between push and pull patterns, and when to use each.

Here are the exact concepts the exam loves to test:

- The ansible-pull command syntax: ansible-pull -U <repository-url> [options] - The -U flag is mandatory. You must specify the repository URL. - The -d flag for the local directory where the repository is cloned. - The -o flag for only-if-changed. The exam will ask you to run the playbook only if the repository has new commits. - The --accept-host-key flag to avoid interactive prompts. The exam expects you to use this in automated scripts. - The -C flag to specify a branch, tag, or commit hash. - The use of cron to schedule ansible-pull. The exam may ask you to write a cron line for a specific interval, for example every 30 minutes. - The requirement that Git must be installed on the managed node. A trap question might ask you to debug why ansible-pull fails — the answer could be that git is not installed. - The default behaviour of ansible-pull if no playbook is specified: it looks for a file named site.yml in the root of the cloned repository.

Trap patterns:

The exam might give you a command with a missing -U flag and ask you to identify why it fails. The answer is that the URL is required.

The exam may present a scenario where push mode fails because nodes are behind a firewall, and ask you to select the correct solution: pull mode.

A question might describe a scheduled task but not use cron. The correct answer will be to set up a cron job that runs ansible-pull.

The exam may ask about idempotency. Ansible playbooks are idempotent, meaning running them multiple times produces the same state. The exam expects you to know that ansible-pull does not change this — the playbook remains idempotent.

Key definitions to memorise:

- ansible-pull pulls a playbook from a Git repository and runs it locally. - Push mode: control node initiates connection to managed nodes. - Pull mode: managed nodes initiate connection to a Git repository. The exam may include a question about the --only-if-changed flag. You must know that it compares the local repository state to the remote repository state. If nothing has changed, ansible-pull exits without running the playbook. This saves time and resources.

Finally, the exam will test that you understand the infrastructure requirements: the managed node needs network access to the Git repository, Git installed, and Ansible installed. The control node is not involved in pull mode except to push changes to the Git repository.

Key Takeaways

ansible-pull requires the -U flag to specify the Git repository URL.

The -o flag (--only-if-changed) prevents ansible-pull from running the playbook when no changes exist.

Pull mode is used when managed nodes are behind firewalls or not always online.

Push mode is the default and preferred pattern for reachable nodes because it offers direct control.

The managed node must have Git installed for ansible-pull to work.

Use cron to schedule ansible-pull to run at regular intervals.

When no playbook is specified, ansible-pull looks for a file named site.yml in the repository root.

The control node does not need to be online for pull mode to work.

Easy to Mix Up

These come up on the exam all the time. Here's how to tell them apart.

Push Mode

Control node initiates the connection to managed nodes.

Requires inbound SSH access to every managed node.

Best for small numbers of reachable nodes.

Pull Mode

Managed node initiates the connection to a Git repository.

Does not require inbound access; only outbound HTTPS or SSH.

Best for large numbers of nodes or nodes behind firewalls.

ansible-push (ad-hoc or playbook)

Runs from the control node using the ansible or ansible-playbook command.

Uses an inventory file to target specific hosts.

Can run once immediately or on a schedule from the control node.

ansible-pull

Runs from the managed node using the ansible-pull command.

Does not require an inventory file.

Must be scheduled on each managed node using cron.

ansible-pull with -o flag

Runs the playbook only if the Git repository has new commits.

Saves bandwidth and execution time on unchanged nodes.

Recommended for frequent scheduled runs.

ansible-pull without -o flag

Clones the repository and runs the playbook every time.

Wastes resources when no changes exist.

Useful for debugging or forcing a re-apply.

Watch Out for These

Mistake

Ansible pull mode replaces push mode entirely, so I should always use pull.

Correct

Pull mode is a specialised tool for nodes that are offline, behind firewalls, or too many to manage with push. Push mode is simpler and preferred when all nodes are reachable.

Beginners assume that because pull mode solves one hard problem, it must be better in all cases. In reality, push mode gives more control over timing and order of execution.

Mistake

I can run ansible-pull without a Git repository URL because Ansible will use the local playbook.

Correct

The -U flag is mandatory. ansible-pull will fail if you do not specify a Git repository URL. It always pulls from a remote repository, never from a local file.

The command name contains 'pull', so beginners think it pulls from the current directory. But 'pull' refers to pulling from a remote Git repository, not the local filesystem.

Mistake

If I set up a cron job to run ansible-pull, the control node must be online for the pull to work.

Correct

The control node is not involved. The managed node connects directly to the Git repository. The control node only needs to push updates to the Git repository, but it does not need to be online when the managed node pulls.

Beginners confuse push and pull. They assume the control node is always required. In pull mode, the Git repository replaces the control node as the source of truth.

Mistake

ansible-pull will automatically run the playbook even if the Git repository has not changed.

Correct

Without the -o flag, ansible-pull will clone the repository and run the playbook every time, even if nothing changed. The -o flag prevents unnecessary runs.

Beginners assume ansible-pull is smart about changes. But by default it runs the playbook every time. You must explicitly use --only-if-changed to skip unnecessary runs.

Do You Actually Know This?

Reveal each answer, then mark whether you got it right. Score 60%+ to unlock the next chapter.

Frequently Asked Questions

Does ansible-pull require an inventory file?

No, ansible-pull does not require an inventory file because it runs locally on the managed node. The playbook is applied to the local machine only.

Can I use ansible-pull with a private Git repository?

Yes, but you must configure SSH keys or a personal access token on the managed node so it can authenticate to the private repository.

What happens if the managed node cannot reach the Git repository?

ansible-pull will fail with a network error. The cron job will retry on the next scheduled run. The node retains its current state until a successful pull occurs.

Does ansible-pull work with branches other than the default?

Yes, you use the -C flag to specify the branch, tag, or commit hash. For example, -C develop pulls the develop branch.

Is ansible-pull idempotent?

Yes, because it runs a playbook which is designed to be idempotent. Running ansible-pull multiple times will produce the same result if the playbook and repository have not changed.

What is the difference between ansible-pull and ansible-push?

In ansible-push, the control node connects to managed nodes and runs playbooks. In ansible-pull, each managed node connects to a Git repository, downloads the playbook, and runs it locally.

Terms Worth Knowing

Keep going

You've finished Ansible Pull and Push Patterns. Continue through the EX294 study guide to build a complete picture of the exam.

Done with this chapter?