yourlabs.remember

yourlabs.remember

Overview: This is a special tool for Ansible Automation Architects that enhances the use of Ansible roles.

Key Features:

  • Speed: You’ll only need to state a dependency role once to benefit from it.
  • Inventoryless: Keeps track of variables set from the command line for each host.
  • User Prompts: Asks users questions to gather necessary information.

Important Note: This tool doesn’t automatically download its dependencies; that’s done using the bigsudo command.

Demo: To try it out, you can run the following commands:

pip install --user bigsudo
~/.local/bin/bigsudo yourlabs.fqdn user@somehost
# For local use, skip the hostname:
~/.local/bin/bigsudo yourlabs.traefik

You can use normal ansible commands too, but this method is simpler. Inspired by kubectl, it’s designed for easy use with smaller servers and teams.

How to Use: This tool helps you set up necessary variables for your roles, including descriptions, default values, and checks.

Dependency Management: For example, if yourlabs.traefik needs yourlabs.docker, it can be set up like this:

  • In your.child/requirements.yml:
    - your.parent
    
  • In your.parent/requirements.yml:
    - yourlabs.remember
    

This means your.child relies on your.parent, which in turn relies on yourlabs.remember. When you run bigsudo your.child, it will ensure all requirements are installed.

Without remember, you would include the your.parent role at the start of your tasks:

- name: Install your.parent before our tasks
  include_role: name=your.parent

But this runs every time you invoke your.child, slowing things down. Instead, you could only include it if it hasn’t already run:

- name: Install your.parent if it’s not done yet
  include_role: name=your.parent
  when: ansible_facts['ansible_local']['your_parent']['state']|default('') != 'success'

To make that work, add this at the end of your.parent/tasks/main.yml:

- include_role: name=yourlabs.remember tasks_from=success

Now running bigsudo your.parent will create a fact file indicating success, allowing you to skip it next time.

Interactive Configuration: In your.parent/vars/main.yml, declare the variables you need:

---
remember_fact: your_parent
remember:
- name: email_enable
  question: Enable a custom email?
  default: false
  type: bool
- name: email
  question: What email to use?
  type: email
  default: '{{ lookup("env", "USER") }}@{{ inventory_hostname }}'
  when: email_enable

Then include yourlabs.remember in your.parent/tasks/main.yml to load these variables and prompt users interactively:

- include_role: name=yourlabs.remember

You can look at test.yml in the playbook for examples on how to use it effectively.

Handling Multiple Deployments: If you need to deploy the same role in different locations on the same host, your remember_fact should vary based on input.

For instance, if you want to use different directories, you could have:

remember:
- name: home
  question: Where to deploy to? (Must start with /home)
  default: /home/test
  type: path
  regexp: /home.*

If the user doesn’t specify a home, they’ll be prompted. You can then use this variable in your remember_fact to keep track of those deployments.

Conclusion: This tool lets you:

  • Inject dependency roles dynamically, speeding up role executions and reducing unnecessary runs.
  • Eliminate the need for complex inventory management, as each host maintains its own variables.
  • Interactively gather information without needing to read extensive documentation beforehand.

Acknowledgments: Special thanks to totakoko from beta.gouv.fr for insightful discussions, and to the helpful members of the #ansible channel.

Thank you for reading!

Informazioni sul progetto

Ansible role to inject dependencies OAOO (once and only once).

Installa
ansible-galaxy install yourlabs.remember
Licenza
Unknown
Download
4k
Proprietario
OSS Hack'n'Dev, we provide all kind of paid services on OSS and sponsor OSS