User Tools

Site Tools


ansible_variable

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

ansible_variable [2025/07/26 17:09] – - Imported by DokuWiki Advanced Plugin wikiadmansible_variable [Unknown date] (current) – removed - external edit (Unknown date) 127.0.0.1
Line 1: Line 1:
-====== Variáveis no Ansible ====== 
-==== Tipos de variáveis ==== 
-  * **vars**: Declara um ou mais valores em uma variável, através da diretiva ''vars''; 
-  * **vars_files:** Declara um ou mais valores em um arquivo de variável, através da diretiva ''vars_files''; 
-  * **register:** Declara uma variável a partir de uma tarefa concluída; 
-  * **--extra-vars**: Declara um ou mais valores em uma variável, através da flag ''--extra-vars'' na linha de comando; 
-  * **fatos:** Utiliza informações do sistema chamada de fatos como valores de variáveis. 
- 
-==== Diretiva vars ==== 
- 
-<file yaml vars-adduser.yml> 
---- 
-- hosts: local 
-  vars: 
-    - usuario: linus 
-  tasks: 
-   - name: Adicionar usuario 
-     user: name={{ usuario }} state=present shell=/bin/bash password=$1$i5CwO/2J$JIaH55NqG10CDpYLqLAZf/ 
-</file> 
- 
-<file bash> 
-$ sudo ansible-playbook vars-adduser.yml 
-</file> 
- 
-==== Diretiva vars_files ==== 
-<file yaml vars_files-pacotes.yml> 
---- 
-- hosts: local 
-  vars_files: 
-    - vars.yml 
-  tasks: 
-   - name: Instala pacotes atraves de variaveis 
-     apt: name={{ pacotes }} state=present update_cache=true 
-</file> 
- 
-<file yaml vars.yml> 
-pacotes: 
-  - elinks 
-  - wget 
-  - curl 
-  - htop 
-  - vim 
-</file> 
- 
-<file bach> 
-$ sudo ansible-playbook --syntax-check vars_files-pacotes.yml 
-$ sudo ansible-playbook vars_files-pacotes.yml 
-</file> 
- 
-==== Diretiva register ==== 
-<file yaml register-ntp.yml> 
---- 
-- hosts: local 
-  tasks: 
-   - name: Instala pacote NTP 
-     apt: name=ntp state=present update_cache=true 
-     register: ntp_installed 
-   - name: Define o arquivo de configuracao do servidor NTP 
-     when: ntp_installed is succeeded 
-     copy: src=ntp.conf dest=/etc/ntp.conf owner=root group=root mode=0644 
-</file> 
- 
-<file bash ntp.conf> 
-driftfile /var/lib/ntp/ntp.drift 
-leapfile /usr/share/zoneinfo/leap-seconds.list 
-statistics loopstats peerstats clockstats 
-filegen loopstats file loopstats type day enable 
-filegen peerstats file peerstats type day enable 
-filegen clockstats file clockstats type day enable 
-pool a.ntp.br iburst 
-pool b.ntp.br iburst 
-pool c.ntp.br iburst 
-pool d.ntp.br iburst 
-restrict -4 default kod notrap nomodify nopeer noquery limited 
-restrict -6 default kod notrap nomodify nopeer noquery limited 
-restrict 172.16.0.0 mask 255.255.0.0 
-restrict ::1 
-restrict source notrap nomodify 
-#restrict source notrap nomodify noquery 
-</file> 
- 
-==== Flag --extra-vars ==== 
-<file yaml create-dir.yml> 
---- 
-- hosts: local 
-  tasks: 
-   - name: Adicionar estrutura de diretórios atraves de variavel 
-     file: dest={{ diretorios }} state=directory recurse=yes owner=root group=root mode=775 
-</file> 
- 
-<file bash> 
-$ sudo ansible-playbook --syntax-check create-dir.yml 
-$ sudo ansible-playbook --extra-vars "diretorios=/tmp/var/www/html/intranet" create-dir.yml 
-</file> 
- 
-==== Fatos ==== 
-<file yaml fatos-apache.yml> 
---- 
-- hosts: webservers 
-  tasks: 
-   - name: Instala Apache no Debian/Ubuntu 
-     when: ansible_os_family == "Debian" 
-     apt: name=apache2 state=present update_cache=true 
-     register: apache2_installed 
-   - name: Instala Apache no CentOS 
-     when: ansible_os_family == "RedHat" 
-     yum:  name=httpd state=present 
-     register: httpd_installed 
-</file> 
- 
-<file bash> 
-$ sudo ansible-playbook --syntax-check fatos-apache.yml 
-$ sudo ansible-playbook fatos-apache.yml 
-</file> 
- 
-<file bash> 
-$ sudo ansible webserver1 -m shell -a 'dpkg -l | grep apache2' 
-$ sudo ansible webserver2 -m shell -a 'rpm -qa | grep httpd' 
-</file> 
  
ansible_variable.1753560543.txt.gz · Last modified: by wikiadm