Home

Awesome

ansible-lib

Provide common tasks as includable task files, e.g. libs and does not run any task itself.

Synopsis

- name: Include check-mode detection
  tags: "{{ role_name }}"
  include: "{{ playbook_dir }}/roles/silpion.lib/tasks/checkmodedetection.yml"
- name: Include data persistency paradigm
  tags: "{{ role_name }}"
  include: "{{ playbook_dir }}/roles/silpion.lib/tasks/datapersistency.yml"
# requires datapersistency.yml

- name: Download some asset
  tags: "{{ role_name }}"
  include: "{{ playbook_dir }}/roles/silpion.lib/tasks/get_url.yml"
  vars:
    url: "{{ url_variable }}"
    filename: "{{ filename_variable }}"
    checksum: "{{ checksum_variable }}"
# requires datapersistency.yml

- name: Upload downloaded asset
  tags: "{{ role_name }}"
  include: "{{ playbook_dir }}/roles/silpion.lib/tasks/copy.yml"
  vars:
    filename: "{{ filename_variable }}"
# requires {{ role_path }}/vars/{{ ansible_os_family }}.yml
# respects {{ role_path }}/vars/{{ ansible_distribution }}-{{ ansible_distribution_major_version }}.yml
# respects {{ role_path }}/vars/{{ ansible_distribution }}.yml

- name: Include OS specific configuration
  tags: "{{ role_name }}"
  include: "{{ playbook_dir }}/roles/silpion.lib/tasks/os-specific-vars.yml"
# requires {{ role_path }}/vars/versions/{{ role_name_version }}.yml

- name: Include version specific configuration
  tags: "{{ role_name }}"
  include: "{{ playbook_dir }}/roles/silpion.lib/tasks/version-specific-vars.yml
  vars:
    version: "{{ role_name_version }}"
- name: Include local facts installation
  tags: "{{ role_name }}"
  include: "{{ playbook_dir }}/roles/silpion.lib/tasks/localfacts.yml
  vars:
    template: myrolesfactstemplate.j2
    namespace: myroleshortname

Assumption

Assumption on using silpion.lib is that roles for a playbook are installed in a directory called roles beneath playbook.yml. Otherwise defaults/ fallbacks when including os-specific or version-specific variables might fail unrelated.

role-aware includes

Ansible is currently working on role-aware includes, like:

- name: Include file from silpion.lib role
  tags: "{{ role_name }}"
  include:
    role: silpion.lib
    file: datapersistency.yml

As soon as this is available, silpion.lib will have marked TODOs addressed and there shouldn't be assumptions anymore.

Configuration

silpion.lib role uses variables from silpion.util role as default values for its own variables. If there is no variable from silpion.util role configured, silpion.lib role uses the same sane defaults.

See Role Variables documentation below.

Library

The following features/paradigms are available to be used.

Data persistency

Download assets once to the local workstation and distribute as often as required in context of local network.

- name: Include data persistency tasks
  tags: "{{ role_name }}"
  include: "{{ role_name }}/../silpion.lib/tasks/datapersistency.yml"

By default this installs one directory on the workstation and one on the managed node.

See Role Variables documentation below.

Vars

Download assets (get_url.yml)

tasks/get_url.yml is basically a wrapper for the Ansible get_url module using some defaults based on the util/lib configuration, e.g. become based privilege escalation with local_action.

Downloads will be stored in {{ lib_persistent_data_path_local }}.

NOTE: With Ansible 2.1 the sha256sum argument got deprecated. sha256sum is replaced with checksum in silpion.lib >= 2.1.N and requires the new format of algorithm:checksum.

- name: Download some assets with silpion.lib/get_url
  tags: "{{ role_name }}"
  include: "{{ role_name }}/../silpion.lib/tasks/get_url.yml"
  vars:
    src: "{{ url }}"
    filename: "{{ filename }}"

Vars

See ansible-doc get_url for a more in-depth documentation of module related configuration options.

Mandatory
Optional

Upload assets (copy.yml)

tasks/copy.yml is basically a wrapper for the Ansible copy module using some defaults based on the util/lib configuration, e.g. become based privilege escalation.

Uploads will be stored in {{ lib_persistent_data_path_remote }}.

- name: Upload some assets with silpion.lib/copy
  tags: "{{ role_name }}"
  with_items:
    - filename1
    - filename2
  include: "{{ playbook_dir }}/roles/silpion.lib/tasks/copy.yml"
  vars:
    filename: "{{ item }}"

Vars

See ansible-doc copy for a more in-depth documentation of module related configuration options.

Mandatory
Optional

Check mode detection

lib role provides tasks for check mode detection. Including checkmodedetection.yml provides a boolean run-time fact lib_fact_check_mode to use when conditionals with.

- name: Include check mode detection
  tags: "{{ role_name }}"
  include: "{{ role_name }}/../silpion.lib/tasks/checkmodedetection.yml

- name: Run a task when Ansible is NOT in --check mode
  tags: "{{ role_name }}"
  when: not lib_fact_check_mode
  module:
    arg: value

Local facts installation

tasks/localfacts.yml will ensure availability of a directory to store local facts into, deploy roles local facts based on a template to be provided into this tasks file and re-read local facts based on changed events when the template has been deployed.

- name: Include local facts installation
  tags: "{{ role_name }}"
  include: "{{ role_name }}/../silpion.lib/tasks/localfacts.yml"
  vars:
    template: "{{ role_name_fact_template }}.j2"
    namespace: myroleshortname

Vars

Mandatory
Optional

Requirements

<a name="role_variables"></a>Role Variables

All variables use the corresponding variable from silpion.util role as defaults. If there are no variables from silpion.util are configured, the |default() values are copied from the defaults of silpion.util.

privilege escalation (local_action)

privilege escalation (action)

data persistency

modules configuration

play configuration

local facts

Ansible setup module supports fact_path variable. This can be configured with a variable from util role.

Contributing

If you want to contribute to this repository please be aware that this project uses a gitflow workflow with the next release branch called next.

Please fork this repository and create a local branch split off of the next branch and create pull requests back to the origin next branch.

License

Apache Version 2.0

Integration testing

This role provides integration tests using the Ruby RSpec/serverspec framework with a few drawbacks at the time of writing this documentation.

Running integration tests requires a number of dependencies being installed. As this role uses Ruby RSpec there is the need to have Ruby with rake and bundler available.

# install role specific dependencies with bundler
bundle install
<!-- -->
# run the complete test suite with Docker
rake suite

Author information

Mark Kusch @silpion.de mark.kusch

<!-- vim: set nofen ts=4 sw=4 et: -->