EX294 5.2: Adding and pushing files
Add a playbook to a clone and push it, ignore files that don't belong in the repository, and get past a rejected push with a merge.
Before you start
This VM is the control node. The lab creates the user greg (password
Lab-Pass-1) with an SSH key and a Git name and email, and installs
ansible-core and git. Work as greg. His Ansible project is
/home/greg/ansible, with a playbook site.yml.
The managed nodes node1 (10.99.1.11) and node2 (10.99.1.12) are
AlmaLinux 10 containers reached over SSH by name. On node1, the bare
repository /srv/git/playbooks.git (owned by devops, who has greg's
key) has one commit, and greg's clone of it is /home/greg/playbooks,
with origin devops@node1:/srv/git/playbooks.git. For a root shell on a
node, sudo podman exec -it node1 bash. Everything stays on this VM: the
repository lives on a node, not on a hosting service.
Tasks
- Copy
/home/greg/ansible/site.ymlinto/home/greg/playbooks, commit it and push it, so that a fresh clone in another directory contains it. - In
/home/greg/playbooks, add a.gitignorethat ignores ansible-navigator's playbook artifacts (*-artifact-*.json) and log (ansible-navigator.log) and the vault password file.vault_pass, and commit it. Thengit status --shortdoesn't list such files. - Make a second clone of the repository, and push a commit from it. Then
make a different commit in
/home/greg/playbooksand try to push it: it's rejected. Pull withgit pull --no-rebase, then push again, so thatgit log --graph --onelineshows the merge and node1's repository has it.
Hints
git add,git commit -m,git push;git log origin/main --oneline.touch site-artifact-2026-10-30T10:00:00.json ansible-navigator.log .vault_passandgit status --shorttest the.gitignore.- Plain
git pullon diverged branches stops with "Need to specify how to reconcile divergent branches";--no-rebasemerges, andgit config --global pull.rebase falsemakes that the default.