Le Blog Utux

HTTP 200 GET /

Thank you debops (advanced Ansible tricks)

Rédigé par uTux Aucun commentaire

I think debops developers are really good and I learn a lot of advanced stuff when I read their roles. I think they should be the reference for Ansible best practises. Here is 3 useful tricks that I did not know.

if in variables

From debops/ansible-docker:

docker__upstream: '{{ True
                      if (docker__distribution_release == "stretch")
                      else False }}'

Self explanatory.

Variables mapping

From debops/ansible-docker::

docker__upstream_arch_map:
  'x86_64': 'amd64'
  'armhf': 'armhf'

docker__upstream_repository: '{{ "deb [arch="
        + docker__upstream_arch_map[ansible_architecture]
        + "] https://download.docker.com/linux/" + docker__distribution|lower + " "
        + docker__distribution_release + " " + docker__upstream_channel }}'

The fact ansible_architecture is x86_64, so the variable docker__upstream_arch_map[ansible_architecture] will be resolve to amd64.

YAML to json j2

From debops/ansible-docker:

{{ docker__tpl_options | to_nice_json }}

In a variable file, simply set a YAML dictionnary, ie /defaults/main.yml:

docker__tpl_options:
  data-root: /var/lib/docker
  storage-driver: overlay2

In templates/daemon.j2:

{{ docker__tpl_options | to_nice_json }}

Thank you debops :)

Écrire un commentaire

Quelle est la première lettre du mot konxx ?

Fil RSS des commentaires de cet article