ansible_server_config
Differences
This shows you the differences between two versions of the page.
| ansible_server_config [2025/07/26 17:09] – - Imported by DokuWiki Advanced Plugin wikiadm | ansible_server_config [Unknown date] (current) – removed - external edit (Unknown date) 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== Configuração ansible server ====== | ||
| - | ===== Configurando o ansible.cfg ===== | ||
| - | <file bash> | ||
| - | $ cd / | ||
| - | $ ls | ||
| - | ansible.cfg | ||
| - | </ | ||
| - | * **ansible.cfg**: | ||
| - | * **hosts**: Arquivo de inventário; | ||
| - | * **roles**: Diretório para armazenar as Roles no Ansible. | ||
| - | |||
| - | <file bash> | ||
| - | $ cat ansible.cfg | ||
| - | # Since Ansible 2.12 (core): | ||
| - | # To generate an example config file (a " | ||
| - | # $ ansible-config init --disabled > ansible.cfg | ||
| - | # | ||
| - | # Also you can now have a more complete file by including existing plugins: | ||
| - | # ansible-config init --disabled -t all > ansible.cfg | ||
| - | |||
| - | # For previous versions of Ansible you can check for examples in the ' | ||
| - | # Note that this file was always incomplete | ||
| - | |||
| - | # for example, for 2.9: https:// | ||
| - | </ | ||
| - | |||
| - | <file bash> | ||
| - | $ sudo su | ||
| - | # ansible-config init --disabled > ansible.cfg | ||
| - | </ | ||
| - | |||
| - | <file basg> | ||
| - | # egrep -v " | ||
| - | [defaults] | ||
| - | log_path=/ | ||
| - | private_key_file=/ | ||
| - | remote_user=root | ||
| - | roles_path=/ | ||
| - | timeout=30 | ||
| - | [privilege_escalation] | ||
| - | [persistent_connection] | ||
| - | [connection] | ||
| - | [colors] | ||
| - | [selinux] | ||
| - | [diff] | ||
| - | [galaxy] | ||
| - | [inventory] | ||
| - | [netconf_connection] | ||
| - | [paramiko_connection] | ||
| - | [jinja2] | ||
| - | [tags] | ||
| - | </ | ||
| - | |||
| - | * **log_path**: | ||
| - | * **private_key_file**: | ||
| - | * **remote_user**: | ||
| - | * **roles_path**: | ||
| - | * **timeout**: | ||
| - | |||
| - | ===== Criando chave SSH ===== | ||
| - | <file bash> | ||
| - | # mkdir /etc/keys | ||
| - | </ | ||
| - | |||
| - | <file bash> | ||
| - | # ssh-keygen | ||
| - | Generating public/ | ||
| - | Enter file in which to save the key (/ | ||
| - | Enter passphrase (empty for no passphrase): | ||
| - | Enter same passphrase again: | ||
| - | Your identification has been saved in / | ||
| - | Your public key has been saved in / | ||
| - | The key fingerprint is: | ||
| - | SHA256: | ||
| - | The key's randomart image is: | ||
| - | +---[RSA 3072]----+ | ||
| - | | | | ||
| - | | | | ||
| - | | + | | ||
| - | | E o | ||
| - | |. o o S . | | ||
| - | |.. o = + = | | ||
| - | |. * * B + o | | ||
| - | |o+.X #.= B | | ||
| - | |B+oo%+= *.. | | ||
| - | +----[SHA256]-----+ | ||
| - | </ | ||
| - | |||
| - | FIXME **Informe o local aonde as chaves serão armazenadas. Como foi definido na configuração do Ansible, as chaves serão armazenadas em: ''/ | ||
| - | |||
| - | ==== Permitindo acesso root ==== | ||
| - | |||
| - | <file bash> | ||
| - | # vim / | ||
| - | [...] | ||
| - | # | ||
| - | PermitRootLogin yes | ||
| - | [...] | ||
| - | </ | ||
| - | |||
| - | <file bash> | ||
| - | # systemctl restart sshd | ||
| - | </ | ||
| - | |||
| - | <file bash> | ||
| - | root@ansible-server:/ | ||
| - | New password: | ||
| - | Retype new password: | ||
| - | passwd: password updated successfully | ||
| - | root@ansible-server:/ | ||
| - | exit | ||
| - | </ | ||
| - | ==== Copiando a chave ==== | ||
| - | Com as chaves geradas o próximo passo é copiar a chave pública para as VMs que o Ansible irá gerenciar. | ||
| - | |||
| - | <file bash> | ||
| - | $ sudo ssh-copy-id -i / | ||
| - | </ | ||
| - | |||
| - | <file bash> | ||
| - | $ sudo ssh -i / | ||
| - | 127.0.0.1 localhost | ||
| - | 127.0.1.1 ubuntu2204.localdomain | ||
| - | |||
| - | # The following lines are desirable for IPv6 capable hosts | ||
| - | ::1 | ||
| - | fe00::0 ip6-localnet | ||
| - | ff00::0 ip6-mcastprefix | ||
| - | ff02::1 ip6-allnodes | ||
| - | ff02::2 ip6-allrouters | ||
| - | |||
| - | 127.0.0.1 ubuntu2204.localdomain | ||
| - | |||
| - | 127.0.2.1 ansible-server ansible-server | ||
| - | </ | ||
| - | |||
| - | ===== Inventário ===== | ||
| - | |||
| - | <file bash> | ||
| - | $ cat / | ||
| - | # This is the default ansible ' | ||
| - | # | ||
| - | # It should live in / | ||
| - | # | ||
| - | # - Comments begin with the '#' | ||
| - | # - Blank lines are ignored | ||
| - | # - Groups of hosts are delimited by [header] elements | ||
| - | # - You can enter hostnames or ip addresses | ||
| - | # - A hostname/ip can be a member of multiple groups | ||
| - | |||
| - | # Ex 1: Ungrouped hosts, specify before any group headers: | ||
| - | |||
| - | ## green.example.com | ||
| - | ## blue.example.com | ||
| - | ## 192.168.100.1 | ||
| - | ## 192.168.100.10 | ||
| - | |||
| - | # Ex 2: A collection of hosts belonging to the ' | ||
| - | |||
| - | ## [webservers] | ||
| - | ## alpha.example.org | ||
| - | ## beta.example.org | ||
| - | ## 192.168.1.100 | ||
| - | ## 192.168.1.110 | ||
| - | |||
| - | # If you have multiple hosts following a pattern, you can specify | ||
| - | # them like this: | ||
| - | |||
| - | ## www[001: | ||
| - | |||
| - | # Ex 3: A collection of database servers in the ' | ||
| - | |||
| - | ## [dbservers] | ||
| - | ## | ||
| - | ## db01.intranet.mydomain.net | ||
| - | ## db02.intranet.mydomain.net | ||
| - | ## 10.25.1.56 | ||
| - | ## 10.25.1.57 | ||
| - | |||
| - | # Here's another example of host ranges, this time there are no | ||
| - | # leading 0s: | ||
| - | |||
| - | ## db-[99: | ||
| - | </ | ||
| - | |||
| - | <file bash> | ||
| - | $ sudo vim / | ||
| - | [...] | ||
| - | [local] | ||
| - | ansible-server | ||
| - | |||
| - | [ubuntu] | ||
| - | ub-vm-01 | ||
| - | |||
| - | [oracle] | ||
| - | ol-vm-02 | ||
| - | ansible_python_interpreter=/ | ||
| - | |||
| - | [debian] | ||
| - | de-vm-03 | ||
| - | </ | ||
| - | |||
| - | <file bash> | ||
| - | $ sudo ansible-inventory --list -y | ||
| - | all: | ||
| - | children: | ||
| - | debian: | ||
| - | hosts: | ||
| - | de-vm-03: {} | ||
| - | local: | ||
| - | hosts: | ||
| - | ansible-server: | ||
| - | oracle: | ||
| - | hosts: | ||
| - | ol-vm-02: {} | ||
| - | ubuntu: | ||
| - | hosts: | ||
| - | ub-vm-01: {} | ||
| - | ungrouped: {} | ||
| - | </ | ||
| - | ===== Ajustes no arquivo hosts ===== | ||
| - | <file yaml hosts.yaml> | ||
| - | $ cat hosts.yaml | ||
| - | --- | ||
| - | - name: File /etc/hosts | ||
| - | hosts: local | ||
| - | tasks: | ||
| - | - name: Testing entries in the /etc/hosts file | ||
| - | lineinfile: | ||
| - | path: /etc/hosts | ||
| - | line: " | ||
| - | register: etc_hosts_result | ||
| - | |||
| - | - name: Clear file /etc/hosts | ||
| - | when: etc_hosts_result is changed | ||
| - | shell: echo '' | ||
| - | register: etc_hosts_clear | ||
| - | tags: hosts | ||
| - | |||
| - | - name: Config file /etc/hosts | ||
| - | when: etc_hosts_clear is succeeded | ||
| - | lineinfile: | ||
| - | path: /etc/hosts | ||
| - | line: "{{ item.ip }} {{ item.fqdn }} {{ item.alias }}" | ||
| - | with_items: | ||
| - | - { ip: ' | ||
| - | - { ip: ' | ||
| - | - { ip: ' | ||
| - | - { ip: ' | ||
| - | - { ip: ' | ||
| - | </ | ||
| - | |||
| - | <file bash> | ||
| - | $ sudo ansible-playbook --syntax-check hosts.yaml | ||
| - | |||
| - | playbook: hosts.yaml | ||
| - | </ | ||
| - | |||
| - | <file bash> | ||
| - | $ sudo ansible-playbook hosts.yaml | ||
| - | |||
| - | PLAY [File /etc/hosts] ****************************************************************************************************************************************************************************************** | ||
| - | TASK [Gathering Facts] ****************************************************************************************************************************************************************************************** | ||
| - | ok: [ansible-server] | ||
| - | |||
| - | TASK [Testing entries in the /etc/hosts file] ******************************************************************************************************************************************************************* | ||
| - | changed: [ansible-server] | ||
| - | |||
| - | TASK [Clear file /etc/hosts] ************************************************************************************************************************************************************************************ | ||
| - | changed: [ansible-server] | ||
| - | |||
| - | TASK [Config file /etc/hosts] *********************************************************************************************************************************************************************************** | ||
| - | changed: [ansible-server] => (item={' | ||
| - | changed: [ansible-server] => (item={' | ||
| - | changed: [ansible-server] => (item={' | ||
| - | changed: [ansible-server] => (item={' | ||
| - | changed: [ansible-server] => (item={' | ||
| - | |||
| - | PLAY RECAP ****************************************************************************************************************************************************************************************************** | ||
| - | ansible-server | ||
| - | </ | ||
| - | |||
| - | <file bash> | ||
| - | $ sudo ansible local -m shell -a "cat / | ||
| - | ansible-server | CHANGED | rc=0 >> | ||
| - | |||
| - | 127.0.0.1 | ||
| - | 10.240.0.200 | ||
| - | 10.240.0.201 | ||
| - | 10.240.0.202 | ||
| - | 10.240.0.203 | ||
| - | </ | ||
| - | |||
| - | ===== Compartilhando a chave SSH ===== | ||
| - | <file bash> | ||
| - | $ sudo ssh-copy-id -i / | ||
| - | $ sudo ssh-copy-id -i / | ||
| - | $ sudo ssh-copy-id -i / | ||
| - | </ | ||
| - | |||
| - | <file bash> | ||
| - | $ sudo ansible all -m ping | ||
| - | ansible-server | SUCCESS => { | ||
| - | " | ||
| - | " | ||
| - | }, | ||
| - | " | ||
| - | " | ||
| - | } | ||
| - | de-vm-03 | SUCCESS => { | ||
| - | " | ||
| - | " | ||
| - | }, | ||
| - | " | ||
| - | " | ||
| - | } | ||
| - | ub-vm-01 | SUCCESS => { | ||
| - | " | ||
| - | " | ||
| - | }, | ||
| - | " | ||
| - | " | ||
| - | } | ||
| - | [WARNING]: Platform linux on host ol-vm-02 is using the discovered Python interpreter at / | ||
| - | https:// | ||
| - | ol-vm-02 | SUCCESS => { | ||
| - | " | ||
| - | " | ||
| - | }, | ||
| - | " | ||
| - | " | ||
| - | } | ||
| - | </ | ||
| - | |||
| - | <file bash> | ||
| - | $ sudo ansible oracle -m ping -e ' | ||
| - | ol-vm-02 | SUCCESS => { | ||
| - | " | ||
| - | " | ||
| - | } | ||
| - | </ | ||
| - | |||
| - | ===== Referências ===== | ||
| - | - [[https:// | ||
ansible_server_config.1753560543.txt.gz · Last modified: by wikiadm
