== Ansible ==
Ansible - Como utilizar.
Server Ansible - Servidor que se conecta com os demais. (Runner/Manager) \\
Cliente Ansible - Servidores clientes.
* Server
* Instalar o ansible.
* Criar a chave de SSH.
* Configurar os grupos em /etc/ansible/hosts
[grupo]
hostname1
hostname2:2222
hostname3
some_host ansible_port=2222 ansible_user=manager
aws_host ansible_ssh_private_key_file=/home/example/.ssh/aws.pem
jumper ansible_port=5555 ansible_host=192.0.2.50
== Variavel de grupos ==
[grupo:vars]
ntp_server=ntp.atlanta.example.com
proxy=proxy.atlanta.example.com
ou criar /etc/ansible/groups_vars/
---
ntp_server: acme.example.org
database_server: storage.example.org
== Sub grupos ==
[web]
hostA
[db]
hostB
[ubuntu:children]
web
Mais informações: http://docs.ansible.com/ansible/intro_inventory.html
** groups_var com usernames diferente.
* Cliente (servidores clientes)
* Instalar o ansible.
* Habilitar o ssh para o server ansible chegar.
* Copiar a chave para o root
* Cuidado com ssh root com senha (apenas chave)
* Server comandos.
# ansible server_or_group -m module_name -a arguments
# ansible all -m ping
# ansible all -m shell -a "df -lh"
Não tem chave mas possui senha de root --ask-pass
ansible-playbook .yml --list-hosts
ansible-playbook .yml
http://docs.ansible.com/ansible/playbooks_intro.html
https://www.digitalocean.com/community/tutorials/configuration-management-101-writing-ansible-playbooks
repositorio de yml
https://galaxy.ansible.com/list#/roles?page=1&page_size=10
AWX ansible without docker
http://yallalabs.com/devops/how-to-install-ansible-awx-without-docker-centos-7-rhel-7/
== Install ansible ==
1 yum search ansible
2 yum install centos-release-ansible-29.noarch
3 yum search ansible
4 yum install ansible
5 history
== Install AWX ==
1 yum search ansible
2 yum install centos-release-ansible-29.noarch
3 yum search ansible
4 yum install ansible
5 history
6 yum search awx
7 yum install -y yum-utils device-mapper-persistent-data lvm2
8 yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
9 yum search docker
10 yum install docker-ce docker-compose
11 docker ps
12 docker start docker
13 setenforce 0
14 vim /etc/sysconfig/selinux
15 vi /etc/sysconfig/selinux
16 docker start docker
17 docker start docker-ce
18 systemctl start docker
19 docker ps
20 yum install epel-release
21 yum install yum install -y python-pip
22 yum install -y python-pip
23 git clone https://github.com/ansible/awx.git
24 yum install git
25 pip install docker-compose
26 pip install --upgrade pip
27 pip install docker-compose
28 yum install python
29 pip install docker-compose
30 yum install docker-compose
31 git clone https://github.com/ansible/awx.git
32 ls
33 cd awx/
34 ls
35 cd installer/
36 ls
37 cat inventory
38 vim inventory
39 vi inventory
40 ansible-playbook -i inventory install.yml
41 ls
42 vim inventory
43 yum install vim
44 ls
45 #ansible-playbook -i inventory -e docker_registry_password=password install.yml
46 pip3 upgrade docker-compose
47 pip3 update docker-compose
48 pip3 install docker-compose
49 pip3 upgrade docker-compose
50 pip3
51 docker-compose -v
52 ls
53 cd
54 ls
55 cd -
56 ls
57 ansible-playbook -i inventory -e docker_registry_password=qwepoi32 install.yml
58 yum search libselinux
59 yum install libselinux-python libselinux-python2
60 yum -y install libselinux-python libselinux-python3
61 kill %1
62 fg
64 ansible-playbook -i inventory install.yml
65 docker ps -a
66 docker images
67 #ansible-playbook -i inventory install.yml
68 ssh localhost
69 vim /etc/ssh/sshd_config
70 systemctl restart sshd
71 #ansible-playbook -i inventory install.yml
72 ansible-playbook -i inventory install.yml
73 netstat -lntp
74 exit
75 history
Adiciona host no arquivo hosts (inventory):
#hosts
www1 ansible_host=172.20.0.25
mysql ansible_host=172.20.0.26
[webservers]
www1
[mysqlserver]
mysql
Test:
$ ansible -i hosts -m ping www1 / webservers
$ ansible -i hosts all -m ping -u root -k -v
Arquivo YAML para playbook:
* https://docs.ansible.com/ansible/latest/user_guide/playbooks.html
* https://github.com/ansible/ansible-examples
$ ansible-playbook -i hosts install-httpd.yml webservers
Referencia:
https://wiredcraft.com/blog/getting-started-with-ansible-in-5-minutes
https://www.ansible.com/resources/videos/quick-start-video
==Windows==
* /etc/ansible/hosts
[sec]
143.106.73.151 ansible_connection=ssh ansible_shell_type=cmd ansible_python_interpreter=C:\Python27 ansible_user=administrador
Testando:
ansible sec -m win_ping --extra-vars ansible_ssh_pass='senha1234'
ansible sec -m win_shell -a 'date' --extra-vars ansible_ssh_pass='senha1234'