Skip to content

Instantly share code, notes, and snippets.

@ngf-davef-devops
Created November 11, 2022 11:12
Show Gist options
  • Save ngf-davef-devops/3cb365440826fe30d3595ee25e1c2989 to your computer and use it in GitHub Desktop.
Save ngf-davef-devops/3cb365440826fe30d3595ee25e1c2989 to your computer and use it in GitHub Desktop.
Playbook to create a default directory & file structure for Ansible projects, create a folder, copy this playbook to it and execute it from within that folder.
---
- hosts: localhost
connection: local
gather_facts: false
become: false
tasks:
- name: Create folder structure
ansible.builtin.file:
path: "{{ item }}"
state: directory
mode: 0755
loop:
- ./files
- ./group_vars
- ./host_vars
- ./inventory
- ./roles/role1/defaults
- ./roles/role1/files
- ./roles/role1/handlers
- ./roles/role1/meta
- ./roles/role1/tasks
- ./roles/role1/tests
- ./roles/role1/vars
- ./templates
- ./vault
- name: Create default config
ansible.builtin.copy:
dest: ./ansible.cfg
content: |
[defaults]
# Default inventory
inventory = ./inventory/
# Add timer to Ansible tasks
callback_enabled = ansible.posix.profile_tasks
# Use the YAML callback plugin.
stdout_callback = yaml
# Use the stdout_callback when running ad-hoc commands.
bin_ansible_callbacks = True
[persistent_connection]
network_cli_retries = 5
- name: Create default role content
ansible.builtin.copy:
dest: "{{ item }}"
content: |
---
# Content below
loop:
- ./roles/role1/defaults/main.yml
- ./roles/role1/files/main.yml
- ./roles/role1/handlers/main.yml
- ./roles/role1/meta/main.yml
- ./roles/role1/tasks/main.yml
- ./roles/role1/tests/main.yml
- ./roles/role1/vars/main.yml
- ./requirements.yml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment