Repository

Create directories to serve as our local repository

make directory and files
1mkdir ansible_lab
2touch error.yml      { create blank file named error.yml }
3touch noerror.yml
4touch inventory
5touch ios.yml

Note

Highlighted lines show files already created in the container

If this was successful then let’s add the blank inventory to the repository. From our project directory ansible_lab let’s initialize this project

git config --global init.defaultBranch main
git init

Let’s configure our git config

git config --global user.email "your@email.com"
git config --global user.name "username"
git config --list

Note

Git config options set the email and username and is used when making commits, you can also see what url you are using

Let’s start pushing code from our local repository up to GitLab. You can add individual files or all files. This marks all files . in the working directory to be added to staging

Add all Files
 git add .
Add individual Files
 git add <filename1> <filename2>

Now we can move the staged files to commit. We use the switch -m for the commit message and will see this in Gitlab.

git commit -m "initial push"

Warning

Make sure you use the switch -m and add a message

Now let’s set the remote repository (Gitlab) and sync our local files to the remote main

git push -u git@gitlab.com:<username>/ansible_lab.git main

You can also see what branches you have within your repository:

git branch
* main

This shows the branch ‘main’ that we just made and that we are in that branch denoted by the *

We can now edit files locally and push them to our remote repository by

git push

Important

IF moving to Module2, GitOps, click here