aglitke.prism

Prism

The Prism role provides a way to manage different systems using a single, consistent playbook. For instance, you may want to set up storage volumes across various storage types or handle VLANs on switches from different companies. Prism lets you create backends (supporting different operations) and set up specific targets that work with those backends. Once set up, you can create playbooks to perform tasks on these targets without worrying about how they actually operate.

This role is designed to be a foundation for other roles that can add their own backends and actions.

Requirements

This has been tested with Ansible version 2.3.0 or higher, but it might work with older versions as well.

Configuration

To use this role effectively, you should understand the following concepts: operations (tasks you want to perform), backends (types of systems you can control), and targets (specific instances of those systems).

For example, if you wish to handle remote object storage, you might need operations like Create, Retrieve, Update, and Delete. Possible backends could include HTTP/REST and FTP. Let's say we have a REST API available at http://api.example.com/v2 with username 'foo' and password 'pass', and an FTP server at 192.168.2.47 with the directory /pub/api, username 'ftp', and password 'secret'. Each of these serves as a target.

To set up the backends, first create a folder for your playbook templates. The default folder is templates/ in this role. Create a subfolder for each backend you want to support (like ftp and http). Next, create playbook templates in each backend folder for the operations you want to support, naming the files <operation>.yml.j2.

To configure the targets, create a folder for target definitions. The default location is /etc/prism/targets. For each target, create a configuration file named <target>.yml.

Example of an operation

Here is a file (named create.yml.j2 in the rest/ subfolder of templates) that defines the create operation for the 'rest' backend.

- hosts: "{{ target_host }}"
  remote_user: "{{ target_user }}"

  tasks:
  - name: REST: Create operation
    uri:
      url: "{{ backend_config.base_url }}/{{ params.path }}"
      method: POST
      user: "{{ backend_config.auth.username }}"
      password: "{{ backend_config.auth.password }}"
      body: "{{ params.object.data }}"

Example of a target definition

Here’s a file (saved as web.yml) that defines a target called 'web'.

# Host and user to use for the generated playbook
target_host: host.example.com
target_user: admin

# Backend this target uses
backend: rest

# Target-specific config
backend_config:
  base_url: http://api.example.com/v2
  auth:
    username: foo
    password: pass

Generating a playbook

The following playbook can generate another playbook to store an object using the 'web' target:

# Generate the playbook on the local machine
- hosts: localhost
  roles:
    - prism

  vars:
    # Optional: customize paths if needed
    target_definitions_dir: /etc/prism/targets
    playbook_templates_dir: /etc/prism/templates

    # Specify the output playbook name. If left out, no playbook will be generated.
    generated_playbook: /tmp/prism-playbook.yml

    # Choose a target for this operation
    target: web

    # Select the operation
    operation: create

    params:
      path: messages
      object:
        id: 1
        data: TG9yZW0gSXBzdW0gaXMgc2ltcGx5IGR1bW15IHRleHQu=

  # No additional task needed since the playbook generation task is included in the role.

This generates a playbook in /tmp/prism-playbook.yml, which can be executed with ansible-playbook to perform the action:

- hosts: host.example.com
  remote_user: admin

  tasks:
  - name: REST: Create operation
    uri:
      url: "http://api.example.com/v2/messages"
      method: POST
      user: foo
      password: pass
      body: TG9yZW0gSXBzdW0gaXMgc2ltcGx5IGR1bW15IHRleHQu=

To switch to an 'ftp' target, just change one line, and the generated playbook will configure itself to communicate with the FTP server:

target: ftp

License

GPLv3

Author Information

Written by Adam Litke - alitke@redhat.com

Informazioni sul progetto

Control a heterogeneous set of targets from a uniform playbook interface

Installa
ansible-galaxy install aglitke.prism
Licenza
Unknown
Download
93
Proprietario