Learn › Git

Repo Layout and Secrets Hygiene for Ops Automation

Structure an automation repo for scripts, Jenkins and Ansible so it scales across teams, and keep passwords, keys and real server details out of Git.

Advanced 12 min read
By Gopinath Karthikeyan

An automation repo starts as a folder of scripts and, two years later, runs half your operations. A sensible layout and strict secrets habits early on save a painful clean-up later.

A layout that scales

winops-automation/
├── README.md                 how to use the repo, who owns it
├── .gitignore
├── .github/                  PR template, CODEOWNERS, workflows
├── modules/                  PowerShell modules (reusable functions)
│   └── WinOpsTools/
├── scripts/                  stand-alone scripts, grouped by area
│   ├── patching/
│   ├── reporting/
│   └── maintenance/
├── ansible/
│   ├── ansible.cfg
│   ├── inventories/
│   │   ├── lab/
│   │   └── prod/
│   ├── group_vars/
│   ├── roles/
│   └── playbooks/
├── jenkins/                  Jenkinsfiles, one per pipeline
├── tests/                    Pester and other tests
└── docs/                     runbooks and decisions

Principles:

  • Code is generic; environment details live in inventories and variables. The same playbook runs in lab and prod with a different inventory.
  • One owner per folder (CODEOWNERS).
  • A README in every top-level folder explaining what’s inside.

The golden rule: no secrets in Git

Secrets include passwords, API tokens, private keys, certificates with keys (.pfx), connection strings, and cloud access keys. Treat anything that grants access as a secret.

Where they go instead:

Use Store secrets in
Jenkins pipelines Jenkins Credentials
GitHub Actions Repository / environment Secrets
Ansible Ansible Vault, or a lookup from your vault service
Scripts on servers Windows Credential Manager / SecretManagement module, or a central vault

Code refers to the secret by name (e.g. credentialsId: 'win-lab-ssh'), never contains its value.

Keep infrastructure details generic too

Even without passwords, a public or widely-shared repo can leak useful information to attackers: real hostnames, internal domains, IP ranges, share paths, account names. Keep these in inventory files that stay private, and use examples like SRV01 and contoso.local in docs and samples.

A defensive .gitignore

# secrets
*.pfx
*.pem
*.key
*.kdbx
.env
*secret*
*credential*
vault-password*

# local and generated
*.log
reports/
.vscode/
*.retry

.gitignore is a safety net, not a guarantee – it doesn’t stop someone from adding a secret to a normal script.

Scan for secrets automatically

Tools like gitleaks find secrets in commits:

gitleaks detect --source . --verbose          # scan the repo and its history
gitleaks protect --staged                     # check what you're about to commit

Run it in your pipeline on every pull request, and turn on GitHub secret scanning / push protection if your plan includes it – it blocks pushes containing known token formats.

If a secret is committed

Act in this order:

  1. Revoke or rotate it immediately. Assume it’s compromised – history is copied to every clone.
  2. Remove it from the current code and commit.
  3. If the repo was shared beyond your team, clean history with git filter-repo or BFG, force-push, and ask everyone to re-clone. This is disruptive, which is why step 1 matters most.
  4. Note what happened and add a check so it can’t recur.

FAQ

Is a private repo safe enough for passwords? No. Private repos get cloned to laptops, forked, backed up and opened to new team members and tools. Secrets belong in a secrets store.

What’s next

You’ve completed the Git track. Continue with Jenkins parameters and credentials.

Practise this topic

Test yourself with free questions on this topic – instant answers and explanations.

Start practice questions

GitSecuritySecretsBest PracticesAdvanced

Gopinath Karthikeyan

Gopinath Karthikeyan – Windows Site Reliability Engineer with about 12 years in enterprise Windows Server infrastructure, and founder of WinOps Academy. YouTube · LinkedIn

More in Git