Skip to main content

Helper package to make running Ansible a bit smoother

Project description

ansible_please

image

image

Documentation Status

Helper package to make running Ansible a bit smoother

  • Run Ansible tasks and playbooks from python with ease!

Overview

Main Components:

  • Inventory - Handles ansible inventory creation from input:

    • Basic input:
    hosts:
        master_host:
          - 'localhost'
    host_info:
      '127.0.0.1':
        'python_path': /usr/bin/python3
    
  • AnsibleTask - Handles individual ansible task creation

    • Docker Task creation
      from ansible_please.task_templates.docker_container import DockerContainer
      
      docker_container_task = DockerContainer(
        task_description="start-test-redis",
        name="test-redis",
        image="redis:latest",
      )
      
      • converts to yaml:
        - name: '[up] start-test-redis'
          docker_container:
            name: test-redis
            image: redis:latest
            user: nobody
            keep_volumes: false
            detach: true
            tty: false
            interactive: false
            network_mode: host
            container_default_behavior: compatibility
          tags:
          - up
        
    • up to start the container, down to tear it down
  • Playbook - Handles playbook creation

    from ansible_please.playbook import Playbook
    p = Playbook(name="Set up master_host",
               hosts="master_host",
               tasks=[docker_container_task.up(), docker_container_task.down()])
    
    • converts to yaml:
      - name: Set up master_host
        hosts: master_host
        gather_facts: true
        tasks:
        - name: '[up] start-test-redis'
          docker_container:
            name: test-redis
            image: redis:latest
            user: nobody
            keep_volumes: false
            detach: true
            tty: false
            interactive: false
            network_mode: host
            container_default_behavior: compatibility
          tags:
          - up
        - name: '[down] start-test-redis'
          docker_container:
            name: test-redis
            state: absent
            user: nobody
            keep_volumes: false
            detach: true
            tty: false
            interactive: false
            network_mode: host
            container_default_behavior: compatibility
          tags:
          - down
      
  • AnsibleRunner - main handler for running playbooks

    r = AnsibleRunner(playbook=p, input_path="test_input.yml") # or pass in Inventory class
    r.up()
    

See full examples

Free software: MIT license

Documentation: https://ansible-please.readthedocs.io.

Credits

This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.

History

0.1.0 (2020-12-22)

  • First release on PyPI.

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_please-0.1.0.tar.gz (23.7 kB view hashes)

Uploaded Source

Built Distributions

ansible_please-0.1.0-py3.8.egg (22.6 kB view hashes)

Uploaded Source

ansible_please-0.1.0-py2.py3-none-any.whl (18.0 kB view hashes)

Uploaded Python 2 Python 3

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