Ansible

Ansible¶ Polycrate provides a special integration with Ansible. The workspace snapshot that is being exported to yaml format and mounted to the Polycrate container will be consumed by Ansible automagically. As a result, the snapshot is available directly as top-level variables in Ansible which can be used in playbooks and templates.

The following example shows:

the default configuration (block.poly) of a block called traefik the user-provided configuration for the block in workspace.poly the Ansible playbook using the exposed variables ( block.config…) an Ansible template using the exposed variables (templates/docker-compose.yml.j2) the resulting file /polycrate/docker-compose.yml that is templated to a remote host Note

Note how in block.poly the configured image is traefik:2.6 but in workspace.poly it’s traefik:2.7. In the resulting docker-compose.yml, the image is traefik:2.7 as defaults in block.poly will be overridden by user-provided configuration in workspace.poly.

The block variable contains the configuration of the current block invoked by polycrate run traefik install. Additionally, there’s a variable workspace available, that contains the fully compiled workspace including additional blocks that are available in the workspace.

Polycrate makes use of a special Ansible Vars Plugin to read in the Yaml-Snapshot and expose it as top-level variables to the Ansible facts.

block.poly workspace.poly install.yml templates/docker-compose.yml.j2 /polycrate/traefik/docker-compose.yml name: traefik config: image: “traefik:v2.6” letsencrypt: email: "" resolver: letsencrypt actions:

  • name: install script:
    • ansible-playbook install.yml
  • name: uninstall script:
    • ansible-playbook uninstall.yml
  • name: prune script:
    • ansible-playbook prune.yml

Ansible Inventory¶ Polycrate can consume yaml-formated Ansible inventory files inside the artifacts directory of a block. Polycrate looks for a file named inventory.yml by default - this can be overridden using the inventory.filename stanza in the block configuration.

An inventory file can be created automatically by a block or provided manually (useful for existing infrastructure).

The inventories can be consumed by the owning block itself or by other blocks using the inventory stanza in the block configuration:

workspace.poly

blocks:

  • namename: block-a inventory: from: block-b filename: inventory.yml # defaults to inventory.yml This will add an environment variable (ANSIBLE_INVENTORY=path/to/inventory/of/block-b) to the container that points Ansible to the right inventory to work with.

The inventory of block-b could look like this:

all: hosts: host-1: ansible_host: 1.2.3.4 ansible_ssh_port: 22 ansible_python_interpreter: “/usr/bin/python3” ansible_user: root children: master: hosts: host-1

Kontakt

Unsere Container-Experten beraten Sie gerne und individuell. Wir antworten in der Regel innerhalb weniger Stunden auf Ihre Nachricht.

🏠 Halbergstr. 4, 66121, Saarbrücken
🕑 Mo - Fr: 09.00 - 17.00 Uhr
✉ hello@ayedo.de
☎ +49 681 3875 3330