Skip to content

Instantly share code, notes, and snippets.

@0xSheepdog
Last active August 22, 2025 16:42
Show Gist options
  • Select an option

  • Save 0xSheepdog/a03c92eaa80d2ed296bf06b4cce30af0 to your computer and use it in GitHub Desktop.

Select an option

Save 0xSheepdog/a03c92eaa80d2ed296bf06b4cce30af0 to your computer and use it in GitHub Desktop.
script to create new repo for developing ansible content
#!/bin/bash
# by 0xSheepdog
# version 0.1.1
#
# This script creates a new project directory with a specified name, then
# initializes it as a git repo with a README.md file, a .gitignore file, and a
# few required files and directories. Finally it installs Ansible and Ansible
# Navigator in a python virtual environment within the project directory.
#
# ToDo - actually incorporate some VScode stuff :P
#
# Usage: ./create-project.sh <project_name>
set -e
if [ -z "$1" ]; then
echo "Usage: $0 <project_name>"
exit 1
fi
PROJECT_NAME="$1"
# Create the project directory structure
mkdir -p "$PROJECT_NAME" "$PROJECT_NAME/collections" "$PROJECT_NAME/playbooks/files"
cd "$PROJECT_NAME"
# Initialize the git repository
git init
# Create the README.md file with the project name
echo "# $PROJECT_NAME" > README.md
# Create the LICENSE file
cat << EOF > LICENSE
MIT License
Copyright (c) [year] [fullname]
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
EOF
# Create the basic Ansible configuration file
cat << EOF > ansible.cfg
[defaults]
inventory = inventory.yml
host_key_checking = false
retry_files_enabled = false
collections_path = collections
[privilege_escalation]
become_method = sudo
[galaxy]
server_list = release_galaxy
#server_list = automation_hub, release_galaxy # uncomment to use Automation Hub
# uncomment to use Automation Hub
#[galaxy_server.automation_hub]
#url=https://console.redhat.com/api/automation-hub/content/published/
#auth_url=https://sso.redhat.com/auth/realms/redhat-external/protocol/openid-connect/token
#token=[your_token_here]
[galaxy_server.release_galaxy]
url=https://galaxy.ansible.com/
EOF
# Create the Ansible Navigator configuration file
cat << EOF > ansible-navigator.yml
---
ansible-navigator:
ansible:
config:
path: ./ansible.cfg
execution-environment:
enabled: false
logging:
level: debug
playbook-artifact:
enable: false
EOF
# Create the Ansible Collections requirements.yml file
cat << EOF > requirements.yml
---
collections:
- name: ansible.netcommon
- name: ansible.posix
- name: ansible.utils
- name: community.general
EOF
# Create the inventory.yml file
cat << EOF > inventory.yml
---
all:
hosts:
localhost:
ansible_connection: local
EOF
# Create the .gitignore file
cat << EOF > .gitignore
scratch.txt
*.bak
# MY Python virtual environments
.venv/
# Ignore most VSCode settings and workspace files
.vscode*
# ansible stuff
.ansible
ansible-errors.json
collections/
.playbook-artifacts/
playbook-artifacts/
*.retry
# Vim stuff
*.swp
*.swo
*.un~
Session.vim
Sessionx.vim
# Python byte-compiled / optimized / DLL files
__pycache__/
*.py[codz]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/ .installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py.cover
.hypothesis/
.pytest_cache/
cover/
EOF
# Install python3.12 and create the virtual environment
sudo dnf install -y python3.12
python3.12 -m venv .venv
# Activate the virtual environment
source .venv/bin/activate
# Upgrade pip to the latest version
pip install --upgrade pip
# Install Ansible and Ansible Navigator w/ current Red Hat supported versions
pip install --upgrade "ansible-core==2.16.14" "ansible-navigator==25.5.0"
# Install the Ansible Collections
ansible-galaxy collection install -r requirements.yml
# Deactivate the virtual environment
deactivate
# Report the project creation
echo ""
echo "Project '$PROJECT_NAME' created successfully with Ansible and Ansible Navigator installed."
echo ""
echo "Don't forget to activate your virtual environment with 'source .venv/bin/activate'"
echo ""
echo "You can tell if you are in the virtual environment by checking your shell prompt for '(.venv)'"
echo ""
echo "You can now start adding your playbooks in the 'playbooks' directory."
echo ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment