EX294 5.1: Cloning a repository
Make a bare Git repository on a managed node, clone it on the control node over SSH, set your Git identity and push a first commit, and clone it a second time.
Before you start
This VM is the control node. The lab creates the user greg (password
Lab-Pass-1) with an SSH key, and installs ansible-core and git. Work
as greg. His Ansible project is /home/greg/ansible: its ansible.cfg
reads the inventory inventory, logs in as devops and becomes root.
The managed nodes node1 (10.99.1.11) and node2 (10.99.1.12) are
AlmaLinux 10 containers reached over SSH by name, with git installed. On
each, devops has greg's key and passwordless sudo, so
ssh devops@node1 works without a password. 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
- Make a bare repository
/srv/git/playbooks.gitwith the branchmainonnode1(git init --bare -b main /srv/git/playbooks.git, with Ansible or in a shell there). Then, as greg, setinit.defaultBranchtomainand clone it over SSH into/home/greg/playbooks, so thatgit remote -vthere shows the URL for fetch and push, andgit statussays "On branch main". - Set greg's Git name and email globally, then commit a
README.mdin the clone and push it, so thatgit logshows them as the author. - Clone the same repository again, into a directory of your choosing in
greg's home, so that it has the same
git log --onelineas the first clone.
Hints
ansible node1 -a 'git init --bare -b main /srv/git/playbooks.git'makes it as root; fordevopsto push to it, give it to devops withansible.builtin.fileandrecurse: true.git clone devops@node1:/srv/git/playbooks.git; the first SSH connection asks you to trust node1's host key.- An empty repository clones with a warning. Over SSH, its clone starts
on Git's own default branch,
master, unlessgit config --global init.defaultBranch maincomes first; in a clone that's already onmaster,git switch -c mainbefore the first commit. - The first push of a new branch:
git push -u origin main. git config --global user.name ...,user.email,--list;git log --format='%an <%ae>'shows the author.