Deploying Custom Files With Jinja2 Templates Flashcards

1
Q

Como se usa el módulo template

A
  • name: render the configuration
    template:
    src: vhost.template.j2
    dest: /etc/httpd/conf.d/{{ ansible_hostname }}.conf
    owner: apache
    group: root
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Ejemplo de template jinja2

A

{{ ansible_managed }}

ServerAdmin root@{{ ansible_domain }}
ServerName {{ ansible_fqdn }}
ServerAlias {{ ansible_hostname }}
DocumentRoot /vhosts/{{ ansible_fqdn }}/html
ErrorLog logs/{{ ansible_hostname }}-error.log
CustomLog logs/{{ ansible_hostname}}-access.log common

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Ejemplo de loop en template jinja2 template

A

{% for user in users %}
{{ user }}
{% endfor %}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Como se hace un loop condicional que evite el usuario root de la variable users

A

{% for myuser in users if not myuser == “root” %}
User number {{ loop.index }} - {{ myuser }}
{% endfor %}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Ejemplo de jinja2 template loop para hosts

A

{% for myhost in groups[‘myhosts’] %}
{{ myhost }}
{% endfor %}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Ejemplo de

Jinja2 template para hosts usando facts

A

{% for host un groups[‘all’] %}
{{ hostvars[‘host’][‘ansible_facts’][‘default_ipv4’][‘ipv4.address’] }}
{{ hostvars[‘host’][‘ansible_facts’][‘fqdn’] }} {{ hostvars[‘host’][‘ansible_facts’][‘hostname’] }}
{% endfor %}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Ejemplo para listar usando archivo de variables en diccionario network_data

A

{% for host in network_data %}
{{ host.ipv4 | ipaddr(‘addresss’) }} {{ host.lname }} {{ host.sname }}
{% endfor %}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Ejemplo de Variable filters en jinja2

A

{{ output| to_json }}
{{ output| to_yaml }}

{{ output| to_nice_json }}
{{ output| to_nice_yaml }}
{{ output| from_json }}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Como se hace uso del módulo setup para obtener processor y memtotal

A

ansible hostname -m setup | grep -E ‘processor|memtotal’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Como se listan los todos los hosts

A

ansible all —list-hosts

How well did you know this?
1
Not at all
2
3
4
5
Perfectly