Loops Flashcards

1
Q

Como se crea un looop en playbook para crear usuarios

A
—- 
- name: Create users
   hosts: servera.lab.example.com
   vars: 
        myusers: 
           - fred
           - barney 
           - wilma 
           - betty 
   tasks:
         - name: Create users 
            user: 
                name: “{{ item }}”
            state: present
            loop: “{{ myusers }}”
...
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Crear grupos con usuarios playbook

Método with_dict: loop

A

—-

  • name: create users in the appropriate groups
    hosts: all
    tasks:
     - name: create groups
        group: 
            name: “{{ item }}”
        loop:
            - flintstones 
            - rubbles
    
      - name: create users in their groups
         user: 
              name: “{{ item.name }}”
              groups: “{{ item.groups }}”
         with_dict: 
               - { name: ‘fred’, groups: ‘flintstones’ }
               - { name: ‘wilma’, groups: ‘flintstones’ }
               - { name: ‘barney’, groups: ‘rubbles’ }
               - { name: ‘betty’, groups: ‘rubbles’ } ...
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Como buscar ayuda de un módulo

A

ansible-doc -t lookup

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

Como se agregan variables se ansible vault y como se usa en playbook

A
  • name: include passwords from vault
    include_vars:
    file: passwords.yml
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Como se usa un nested loop

A
- name: give Beatles access to their dbs
   mysql_user:
       name: “{{ item[0] }}”
       priv: “{{ item[1] }}.*:ALL”
       append_privs: yes
       password: “{{ db_pass }}”
   with_nested:
        - “{{ beatles}}”
        - “{{ category_db }}”
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Como se usa el módulo archive en playbook

A
  • name: create zip
    hosts: localhost
    become: falsevars:
    source: /file
    zipfile: /file.tar.gz
    zipformat: ziptasks:
      - name: create tar 
        archive:  
           format: “{{ zipformat }}”
           path: “{{ source }}”
           dest: “{{ zipfile }}”
    
       - name: check if tar exists
          stat:
              path: “{{ zipfile }}”
          register: archive
    
        - name: show the archive dictionary
           debug:  
                var: archive
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Como se usa una condicion en un loop

A
  • name: name of the play
    hosts: all
    vars:
    my_service: httpdtasks:
     - name: “{{ mr_service }} package is installed”
        yum:  
              name: “{{ my_service }}”
        when: my_service is defined
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Condicionales para where sintaxis

A
Var == “variable”
Var == 99
Var < 99
Var > 99
Var <= 99
Var >= 99
Var != 99
Var is defined
Var is not defined 
Var ( true / false )
Var in Var2
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Ejemplo de condición si ansible_distribution está dentro de supported_distros

A
—-
- name: demonstrate in keyword
   hosts: all
   gather_facts: yes
   vars:
        supported_distros:
           - RedHat
           - Fedora
   tasks:
       - name: install httpd using yum
          yum: 
              name: http
              state: present
          when: ansible_distribution in supported_distros
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Ejemplo de multiple or y and conditions

A

when: ansible_distribution == “RedHat” or ansible_distribution == “Fedora”
when: ansible_distribution_version == “7.5” and ansible_kernel == “3.10.0-327.el7.x86_64”

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

Como se coloca una condición larga en una sola linea

A

when: >
( ansible_distribution == “RedHat” and ansible_distribution_major_version == “7” )
or
( ansible_distribution == “Fedora” and ansible_distribution_major_version == “28” )

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

Como se realiza una validación. Previa de los filesystem para evaluar que haya Espacio disponible antes de instalar un paquete

A

—-

_ name:

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

Lo mi se usa el

Módulo copy para copiar un archivo

A
  • name: Indtall the sudo configuration
    copy:
    src: support.sudo
    dest: /etc/sudoers.d/support
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Como se usa el módulo authorized key de ssh

A
- name: install the ssh key 
   authorized_key: 
       manage_dir: yes
       user: support 
       key: “{{ lookup(‘file’ , ’id_rsa.pub’) }}”
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Como se usa el módulo lineinfile

A
  • name:
    lineinfile:
    state: present
    dest: /etc/ssh/ssh_config
    line: AllowGroups wheel
    notify: Restart the ssh daemon
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Como se usa el parámetro notify de playbook para tareas

A

Se usa para notificar o lanzar tareas posteriores de otros módulos, solo
Ejecutan si la tarea resulta en change state

tasks:

   - name: Disallow password authentication
      lineinfile:
         state: present
         dest: /etc/ssh/ssh_config
         line: PasswordAuthentication no
         notify: Restart the ssh daemon
handlers:
    - name: Restart the ssh daemon
       service: 
          name: sshd
          state: restarted
17
Q

Como se forza a qué se ejecute un handler

A

Parámetro
- name: play level
force_handlers: true

18
Q

Como registras un shellscript como fallido con el shell module

A

tasks:
- name: run user creation script
shell: /usr/local/bien/create_users.sh
register: command_result
Failed_when: “‘Password missing’ in command_result.stdout”

19
Q

Como se usa el fail module

A

tasks:
- name: run user creation script
shell: /usr/local/bien/create_users.sh
register: command_result
ignore_errors: yes
- name: report script failure
fail:
msg: “the password is missing in the output”
when: “‘Password missing’ in the command_result.stdout”

20
Q

Como se reporta como changed en shell module ejemplo

A
  • name: get Kerberos credentials as admin
    shell: echo “{{ krb_admin_pass }}” | kinit -f admin
    changed_when: false
21
Q

Como

Se logra especificar un ejemplo de colocar cuando esté en estado changed

A

tasks:
- shell:
cmd: /usr/local/bin/upgrade-database
register: command_result
changed_when: “‘Success’ in command_result.stdout”
notify:
- restart_database

handlers:
- name: restart_database
service:
name: mariadb
state: restarted

22
Q

Como se utilizan los. Bloques mostrar ejemplo en playbook

A
  • name: block example
    hosts: all
    tasks:
    - name: installing and configuring yum
    block:
    - name: package need it
    yum:
    name: yum-plugin-versionlock
    state: present
    - name: lock version of tzdata
    lineinfile: tzdata-2016j-1
    state: present
    when: ansible_distribution == “RedHat”
23
Q

Como funciona rescue y always en un bloque playbook

A
  • name: upgrade database
    block:
    - name: upgrade database
    shell:
    cmd: /usr/local/bin/upgrade-database
    rescue:
    - name: revert upgrade
    shell:
    cmd: /usr/local/bin/revert-database
    always:
    - name: always restart database
    service:
    name: mariadb
    state: restarted
24
Q

Como se usa ignore errors en un playbook

A

task:
- name: install {{ web_package }} package
yum:
name: “{{ web_package }}”
state: present
ignore_errors: yes

25
Q

Que parámetro se usa en los módulos de comando o shell para indicar que no cambio nada

A

changed_when: false

El estado default es changed

26
Q

Como sobre escribimos una tarea para indicar que fallo con una condición

A

failed_when: web_package == “httpd”