Skip to main content

A butler CLI for assistance in managing Ansible projects

Project description

ansible-butler

Butler CLI for Ansible projects

Functions

Object Action Description
directory init initialize an ansible directory
directory clean cleanup an ansible directory
ee init initialize an execution environment directory for ansible-builder
ee dependencies[deps] parse the dependency tree based on execution environment definition (or collection requirements)
role list list roles
role dependencies[deps] Build a dependency graph between roles in a specified directory [Example]
role clean clean role directory structure (remove empty yml files & dirs)
role mk-readme auto generate readme based on role meta and basic yml info
playbook update map legacy module names to FQCNs
playbook list-collections[lc] list collections used in a playbook (following include_* directives)

Usage

Usage:
  ansible-butler directory init [<dir>] [--config=PATH]
  ansible-butler directory clean [<dir>] [--skip-roles]
  ansible-butler ee init [<dir>] [--config=PATH]
  ansible-butler ee [dependencies|deps] [--config=PATH] [<name>]
  ansible-butler role list [--roles-path=PATH] [<name> --recursive]
  ansible-butler role [dependencies|deps] [--roles-path=PATH]
  ansible-butler role clean [--roles-path=PATH] [<name> --recursive]
  ansible-butler role mk-readme [--roles-path=PATH] [<name> --recursive]
  ansible-butler playbook update [--context=CONTEXT] [--config=PATH] [<name>] [--recursive] [--force]
  ansible-butler playbook [list-collections|lc] [--context=CONTEXT] [--config=PATH] [<name>] [--recursive] [--force]

Arguments:
  name    name of target (accepts glob patterns)
  dir     path to directory [default: ./]

Options:
  -h --help           Show this screen
  -r --recursive      Apply glob recursively [default: False]
  -f --force          Make file changes in place
  --config=PATH       Path to config file
  --roles-path=PATH   Path to roles directory [default: ./roles]
  --context=CONTEXT   Path to context directory [default: ./]
  --skip-roles        Flag to skip cleaning roles

Examples

  • Initialize Ansible Directory
    • ansible-butler directory init ./sandbox
    • ansible-butler directory init ./sandbox --config=~/configs/ansible-butler.yml
  • Clean an Ansible Directory
    • ansible-butler directory clean ./sandbox
    • ansible-butler directory clean ./sandbox --skip-roles
  • Initialize Execution Environment Directory
    • ansible-butler ee init ./ee-windows
    • ansible-butler ee init ./ee-windows --config=~/configs/ansible-butler.yml
  • Inspect Execution Environment Dependencies
    • ansible-butler ee dependencies execution-environment.yml
    • ansible-butler ee deps requirements.yml --config=~/configs/ansible-butler.yml
  • Clean Roles
    • ansible-butler role clean my-role-1
    • ansible-butler role clean my-role-*
  • List Roles
    • ansible-butler role list
    • ansible-butler role list ansible_collections/namespace/collection/roles
  • Generate Dependency Graph
    • ansible-butler role deps
    • ansible-butler role deps ansible_collections/namespace/collection/roles
  • Generate README
    • ansible-butler role mk-readme my-role-1
    • ansible-butler role mk-readme my-role-*
  • Update Playbooks
    • ansible-butler playbook update --context=./playbooks -r
    • ansible-butler playbook update legacy-*.yml
    • ansible-butler playbook update -f
  • List Collections
    • ansible-butler playbook list-collections --context=./playbooks -r
    • ansible-butler playbook lc example-playbook.yml

Configuration

Create an .ansible-butler.yml in one or more of the following locations:

/etc/ansible-butler/    ## least precedence
~/
./                      ## highest precedence

You can also specify a specific path at runtime via the --config option.

# Example Configuration Schema
execution_environment:
  init:
    # Refer to full schema here:
    # https://ansible.readthedocs.io/projects/builder/en/stable/definition/#overview
    version: 3
    additional_build_files:
      - src: files/ansible.cfg
        dest: configs
    ee_base_image: registry.redhat.io/ansible-automation-platform-24/ee-minimal-rhel9:latest
    dependencies:
      system:
        - ...
      python:
        - ...
      collections:
        - name: ansible.utils
          version: ">=3.1.0"
        - ...
    additional_build_steps:
      prepend_galaxy:
        - ADD _build/configs/ansible.cfg ~/.ansible.cfg

directory:
  init:
    lint: 
      enabled: true
    code_bot:
      enabled: true
      interval: weekly
    vscode:
      enabled: true
      settings:
        "files.trimTrailingWhitespace": true
        "editor.renderFinalNewline": "on"
        "files.trimFinalNewlines": true
    folders:
      - name: plugins
        folders:
          ...
        files:
          - README.md
    files:
      - playbook.yml

role:
  dependencies:
    output_fmt: html # [html,json]
    output_dest: graph.html
    include_tests: false
    master_node: role-common-setup
    initial_direction: downstream
    title: ansible-butler roles dependency graph
    title_text_color: white
    title_background_color: black
    tree_options:
      # Customize the color palette
      circleStrokeColor: '#2b8f91'
      linkStrokeColor: '#dddddd'
      closedNodeCircleColor: '#9bd3d4'
      openNodeCircleColor: white
      cyclicNodeColor: '#FF4242'
      missingNodeColor: '#CC0100'
      maxDepthNodeColor: '#FF5850'

playbook:
  update:
    modules:
      smart_device:
        redirect: zjleblanc.kasa.smart_device
      custom_module:
        redirect: company.it.custom_module

🔗 Default configuration file
🔗 Example adding test plugins directory
🔗 Example adding module redirects
🔗 Example customizing directory init configs

Troubleshooting

  • ansible-butler: command not found
    • check the $PATH environment variable and ensure that ~/.local/bin is included

License

GNU General Public License

Author Information

Zach LeBlanc

Red Hat

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ansible-butler-1.2.0.tar.gz (78.3 kB view details)

Uploaded Source

Built Distribution

ansible_butler-1.2.0-py3-none-any.whl (78.7 kB view details)

Uploaded Python 3

File details

Details for the file ansible-butler-1.2.0.tar.gz.

File metadata

  • Download URL: ansible-butler-1.2.0.tar.gz
  • Upload date:
  • Size: 78.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.1

File hashes

Hashes for ansible-butler-1.2.0.tar.gz
Algorithm Hash digest
SHA256 b1c7ceb77bd78b2c19507224f6fd5dbcf6b720a1ba789ecb02e4c862ebbda8e5
MD5 de87a696482290fd81ebcb0f583a1186
BLAKE2b-256 2d7c4f049091cba9c72cfc2e2ade6097a9da749311796647d1be775e2368fd7b

See more details on using hashes here.

File details

Details for the file ansible_butler-1.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for ansible_butler-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e5cac575818c063943839d5a9170c952136a7a8278ec25716337e779c9ab3d3d
MD5 ae1408763d7deda393a6070562134b01
BLAKE2b-256 ac3d52165c333fe5b2571030c107b88c17a1e364b6d1ab969296b9b9f96ec3e2

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page