Managing Packages Flashcards
Como se instala el paquete http en ansible
- name: install http
yum:
name: httpd
state: latest
Como
Se actualizan todos los paquetes
- name: update all packages
yum:
name: ‘*’
state: latest
Como
Se remueve un paquete
- name: remove httpd
yum:
name: httpd
state: absent
Como
Se instalan las devolpment tools group
- name: install dev
yum:
name: ‘@Development Tools’
state: present
Install perl app stream module
- name: install perl app stream module
yum:
name: ‘@perl:5.6/minimal’
state: present
Como se colecta información de paquetes
—- - name: display installed packages hosts: servera tasks: - name: gather info package_facts: manager: auto
- name: List installed package debug: msg: “Versión {{ ansible_facts.packages[‘NetworkManager’][0].version” when: “‘NetworkMager’ in ansible_favts.packages
Instalación de multiplataforma con varios package managers
—-
- name: install the required packages
hosts: webservers
tasks:
- name: httpd on rhel
yum:
name: httpd
state: present
when: “ansible_distribution == ‘Redhat’”
- name: httpd on Fedora dnf: name: httpd state: present when: “ansible_distribution == ‘Fedora’”
Como se puede colocar que se instale el paquete independientemente del repo manager
—-
- name: install required packages in the webservers
hosts: webservers
tasks:
- name: install httpd
package:
name: httpd
state: present
Como se usa el redhat_subscription
- name: register the server redhat_subscription: username: “{{ user }}” password: “{{ pass }}” auto_attach: true
Como se deshabilitan todos los repositorios
- name: disable all repositories
rhsm_repository:
name: ‘*’
state: disabled
Como se coloca una condición donde solo cuando una variable tenga valor se ejecute un bloque
tasks:
block:
- name: register redhat_susbscription: username: “{{ user }}” password: “{{ password “} when: - cdn_username != “” - cdn_password != “”
Como se usa el modulo yum_repository
- name: define “{{ repo_name }}” yum_repository: file: “{{ repo_name }}” name: “{{ repo_name }}” description: “{{ repo_desc }}” base_url: “{{ repo_ desc }}” pgpcheck: “{{ repo_gpgcheck }}” enabled: “{{ repo_enabled }}” state: present
Como se copia la llave gpg para desplegar con módulo rpm_key
- name: deploy the fog key
rpm_key:
key: http://materials/RPM-GPG-KEY-example
state: present
Playbook para crear usuario y grupos con reinicio de ssh al finalizar
- name: play
hosts: webservers
vars_files:
- vars/users_vars.ymlhandlers:
- name: restart sshd
service:
name: sshd
state: restartedtasks:
- name: add we admin group
group:
name: wasasmin
state: present- name: create users user: name: user groups: webadmin loop: “{{ users }}” - name: get authorized keys authorized_keys: user: key: lookup: {{users}}