? ?????? ????? ????? Ansible?? ????????????? ? ¿Ansible? ????????? ??? ?????????????.
? ???? ?????????? ?? ???????, ??? ????????? ?????????? ?????????? ? Ansible. ?? ????? ?????????? ? ?????????? ?????????? ???????????? Ansible.
????? ????, ?? ??????? ????????? ??????? ¿Ansible? ??????? ????????? ??????? Ansible ad-hoc.
??????? ???????????? ansible
??????? ?? ??, ??? ?? ?????? ???????????? ???????????? raíz ? Ansible??? ??????? ?????? Ad hoc ? libros de jugadas, ??? ?????????? ?? ????????????? ? ?? ????????? ?????? ????????? ??-?? ?????? ????????????, ??????? ????? ?????????? ??? ?????????? ??????? raíz ???????????? ssh.
?? ???? ??????? ????????????? ??????? ?????????? ???????????? ¿Ansible? ???????????? sudo (??? ???? ??????) ?? ???? ?????? (???????????? ? ???????????? ??????).
???????, ??? Ansible?????????? ¿SSH? Pitón??? ?????????? ???? ??????? ?????? ?? ???????, ??????? ??? ?????? ????, ??????? ??? ????? ????? ????????? ????? ????????? Ansible:
- ??????? ?????? ???????????? ?? ???? ??????.
- ???????????? ?????????? sudo?????? ???????????? ?? ???? ?????.
- ???????????? ????? SSH??? ?????? ???????????? ?? ?????????? ????.
- ?????????? ??????? ???? SSH?? ?????????? ????.
????, ??? ?????? ????, ??????? ?????? ? ??????? ?????? ???????????? ? ?????? andreyex?? ???? ??????:
[root@control ~]# useradd -m andreyex [root@node1 ~]# useradd -m andreyex [root@node2 ~]# useradd -m andreyex [root@node3 ~]# useradd -m andreyex [root@node4 ~]# useradd -m andreyex
????? ????????? ?????? ??????? ?? ???? ?????? ?? ?????? ??????? ? ???? 2; ?? ?????? ???????????? andreyex sudo?????????? ??? ???? ?????? ??? ??????, ??????? ????????? ?????? ? ???? /etc/sudoers:
[root@control ~]# echo "andreyex ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers [root@node1 ~]# echo "andreyex ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers [root@node2 ~]# echo "andreyex ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers [root@node3 ~]# echo "andreyex ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers [root@node4 ~]# echo "andreyex ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
?????? ??????? ? ??????? ??? ???????????? andreyex?? ????? ?????????? ???? ? ???????????? ???? ?????? ssh:
[andreyex@control ~]$ ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (/home/andreyex/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/andreyex/.ssh/id_rsa. Your public key has been saved in /home/andreyex/.ssh/id_rsa.pub. The key fingerprint is: SHA256:Xf5bKx0kkBCsCQ/7rc6Kv6CxCRTH2XJajbNvpzel+Ik andreyex@control The key's randomart image is: +---[RSA 3072]----+ | .oo . | | . ooo . o | | . = *=.o o | | o =.o+ . o . . | | . . .. S . . o | |. .. . . . . | |.. . oo.o o o| |. = o oo++. . +.| | + ..++Eoo. o. | +----[SHA256]-----+
???????, ?? ?????? ?????????? ??????? ssh-???? ??????? ?? ??? ?????????? ????? ? ??????? ??????? ssh-copia-id ????????? ???????:
[andreyex@control ~]$ ssh-copy-id node1 [andreyex@control ~]$ ssh-copy-id node2 [andreyex@control ~]$ ssh-copy-id node3 [andreyex@control ~]$ ssh-copy-id node4
?????? ? ??? ?????? ???? ?????????? ???????????? ?? sssh?? ???? ?????????? ????? ??? ??????? ??????; ??? ????? ?????????? ?????? ?????? ????????? ????? ssh (???? ?? ?? ???????? ?? ??????, ??-??).
??????? ?????? ????????? ansible
???? ??????????????? ¿Ansible? ??? ? ??????? ????, ??????? ??????? ?????? ???????, ?????? ??????? ??? IP-??????, ??????? ????????? ?? ?????, ???????? ?? ?????? ????????? ? ??????? Ansible (??????????? ????).
?/etc/ansible/hosts????? ??????????????? ?? ?????????. ?????? ? ?????? ???, ??? ????????? ?????????? ????? ????????? ? Ansible.
??????? ??????? ???????
?? ?? ?????? ?????????? ? ????????? /etc/ansible; ?? ?????? ????????? ??? ? /etc/ansible? ?????????? ???? ? ? ??????? ?????? ???????????? ??? ? ??????? ?????????? ????????? ??? ??????? ?????? ???????????????, ??????????????? ?????? ???????????? ??????? ¿Ansible? ?. ?.
?????? ??????? ??????? ????? ??????? ??????? ¿Ansible? ?????? ? /home/andreyex ? ?????? obras de teatro, ??????? ?? ?????? ???????????? ??? ??????? ???? ????? ????????? ? Ansible????? (libros de jugadas, ?????? ?????????, ????? ? ?. ?.), ??????? ?? ?????? ????????? ? ????? ???????:
[andreyex@control ~]$ mkdir /home/andreyex/plays
??????? ???????, ??? ???, ??? ?? ????????? ? ????? ???????, ????? ? ?????????? ????.
??????? ????? ???????????????
????????? ? ??????? /home/andreyex/plays ? ??????? ???? ??????????????? ? ?????? mis anfitriones? ??????? ????? ?????? ???? ????? ?????????? ?????, ????? ?? ? ??????? ????? ??????? ???:
[andreyex@control plays]$ cat myhosts node1 node2 node3 node4
??????? -i ????????????? ??? ??????? ????? ??????????????? mis anfitriones. ???? ?? ??????? ??????? -yo, Ansible ????? ?????? ????? ? ????? ??????????????? /etc/ansible/hosts.
?????? ? ????, ??? ????? ? ????????? ????? ?????? ? ??? ??? ???? (????????????? ??????), ??????? ? ?????? ? Azur, ????????? ? ????? ???????, ? ??? ?? ????? ???????????? ? DNS, ????????? ?? ??????????????? Azur.
???? ? ??? ??? ?????????? DNS-???????, ?? ?????? ??????? ?????? IP-?????? / ????? ????? ????? ????? ? /etc/hosts, ?????? ????:
??????? ????? ? ??????? ????? ????
?? ?????? ???????????? ???? ?????????? ????? ? ?????? ? ?????????. ?????????, ?? ?????? ??????????????? ???? mishosts, ????? ??????? ??? ?????? prueba ? pinchazo ????????? ???????:
[andreyex@control plays]$ cat myhosts [test] node1 node2 [prod] node3 node4
?? ?????? ?????????? ????? ? ?????? pinchazo, ????????? ????????? ???????:
[andreyex@control plays]$ ansible prod -i myhosts --list-hosts hosts (2): node3 node4
? Ansible???? ??? ?????? ?? ?????????:
- todo ? ??????? ??? ????? ? ?????????
- ¿desagrupados? ??????? ??? ?????, ?? ??????? ?? ? ???? ?????? (????? ????).
??????? ??????? ???????????? nodo5? ???? ??????????????? mishosts, ????? ????????????????????? ?????????????????? ??????:
[andreyex@control plays]$ cat myhosts node5 [test] node1 node2 [prod] node3 node4
??????? ???????, ??? ? ??????? nodo5? ????? ?????? (? ?? ? ?????) ????? mishosts, ????? ?? ????? ????????? ?????? ?????? pinchar.
?????? ?? ?????? ????????? ????????? ???????, ????? ??????? ?????? ???? ?????????????????? ??????:
[andreyex@control plays]$ ansible ungrouped -i myhosts --list-hosts hosts (1): node5
?? ????? ?????? ??????? ?????? (padre), ??????? ??????? ????????? (niños). ????????? ?? ????????? ??????:
[andreyex@control plays]$ cat myhosts [web_dev] node1 [web_prod] node2 [db_dev] node3 [db_prod] node4 [development:children] web_dev db_dev [production:children] web_prod db_prod
?????? ?????????? ??????? ??? ?????, ??????? ????????? ? web_dev, ???? ??? ?????, ??????? ????????? ? db_dev. ????? ??? ?? ???????????????? ?????? ??????? ??? ?????, ??????? ????????? ? web_prod, ???? ??? ?????, ??????? ????????? ? db_prod.
[andreyex@control plays]$ ansible development -i myhosts --list-hosts hosts (2): node1 node3 [andreyex@control plays]$ ansible production -i myhosts --list-hosts hosts (2): node2 node4
????????? ansible
? ???? ??????? ?? ??????? ? ??????? ?????? ?????????? ???????????? Ansible. ?? ?????????? ???? ????? ?? ?????? ????????? ?????? ????????? ????????????, ????? ? ???? ????????? ?????????????.
/etc/ansible/ansible.cfg? ???? ???????????? ?? ?????????. ?????? ????? ????????????? ?? ?????????? ? /etc/ansible/ansible.cfg? ?????? ???????????? ??? ? ??????? ??????. ?? ?????? ??????? ???? ?????????? ???? ???????????? ¿Ansible? ??????? ??????? Ansible.
??????? ansible ?versión ??????? ???, ????? ???? ???????????? ?? ?????????? ? ?????? ??????:
[andreyex@control plays]$ ansible --version ansible 2.9.14 config file = /etc/ansible/ansible.cfg configured module search path = ['/home/andreyex/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /usr/lib/python3.6/site-packages/ansible executable location = /usr/bin/ansible python version = 3.6.8 (default, Dec 5 2019, 15:45:45) [GCC 8.3.1 20191121 (Red Hat 8.3.1-5)]
??? ????? ?? ??????, /etc/ansible/ansible.cfg ? ????????? ????? ????????????, ????????? ?? ??? ?? ??????? ???? ?????????? ???? ansible.cfg? ??????? ???????.
/etc/ansible/ansible.cfg ??????? ????? ????????? ?????????? ???????????? ¿Ansible? ???????:
[andreyex@control plays]$ wc -l /etc/ansible/ansible.cfg 490 /etc/ansible/ansible.cfg
??? ??????? ?????? ???????, ??????? ??? ?????????? ?????????? ? ????? ???????????? Ansible:
- [predeterminado]
- [escalada_privilegio]
? ??????? [predeterminado] ????????? ??????? ?????? ?????????, ? ??????? ??? ????? ???????:
- inventario ? ????????? ???? ? ?????? ????? ?????????.
- usuario_remoto? ????????? ????????????, ??????? ????? ???????????? ? ?????????? ?????? ? ????????? libros de jugadas.
- tenedores ? ????????? ?????????? ??????, ????????? Ansible????? ????????? / ???????????? ????????????; ?? ????????? 5.
- host_key_checking? ?????????, ?????? ?? ?? ??????? / ????????? ??????? ????? ????? SSH; ?? ????????? Verdadero.
? ??????? [escalada_privilegio] ?? ?????? ????????? ????????? ?????????:
- convertirse? ???????, ??? ?????????/????????? ????????? ??????????; ?? ????????? ? FALSO.
- convertirse en método? ??????? ?????? ????????? ??????????; ?? ????????? ? sudo.
- convertirse en usuario? ??????? ????????????, ??????? ?? ????? ? ?????????? ????????? ??????????; ?? ????????? ? raíz.
- convertirse_ask_pass? ???????, ???????????? ??? ?? ?????????? ?????? ????????? ??????????; ?? ????????? ? FALSO.
?????? ? ????, ??? ??? ?? ????? ????????? ?????-???? ?? ???? ??????? ? ??????. ??? ??? ?????????????????? ? /etc/ansible/ansible.cfg.
?????? ??????? ???? ?????????? ???? ???????????? ansible.cfg? ??????? ??????? ¿Ansible/home/andreyex/plays? ?????????? ????????? ?????????:
[predeterminado]
inventario = mishosts
usuario_remoto = elliot
host_key_checking = falso
[escalada_privilegio]
convertirse en = verdadero
convertirse_metod = sudo
convertirse en usuario = root
convertise_ack_pass = falso
?????? ????????? ??????? ansible ?versión ??? ???; ?? ?????? ???????, ??? ??? ????? ???? ???????????? ?????? ?????????:
[andreyex@control plays]$ ansible --version ansible 2.9.14 config file = /home/andreyex/plays/ansible.cfg configured module search path = ['/home/andreyex/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /usr/lib/python3.6/site-packages/ansible executable location = /usr/bin/ansible python version = 3.6.8 (default, Dec 5 2019, 15:45:45) [GCC 8.3.1 20191121 (Red Hat 8.3.1-5)]
?????????? ?????????? ?????? ? ansible
?? ????? ??????? ?? ????????????? ?????? ?????????????, ???????????? ????? ? ?????????? Ansible. ?????? ?????????? ????? ??????????!
?????????? ??????? ¿Ansible? ??????? ??????????, ??????? ????? ???????????? ??? ??????? ????? ?????? ?? ????? ??? ?????????? ?????????? ?????. ??????? ?????????? ??????? Ansible??????? ?????? ??????????:
ansible host_pattern -m module_name -a "module_options"
????? ??????? ?????? ??????, ??? ??????? ?????????? ??????? ¿Ansible? ?????? ????????? ??! ????, ???????????? ? ????????? ????????? ?????????? ???????:
[andreyex@control plays]$ ansible node1 -m command -a "uptime" Enter passphrase for key '/home/andreyex/.ssh/id_rsa': node1 | CHANGED | rc=0 >> 18:53:01 up 5 days, 18:03, 1 user, load average: 0.00, 0.01, 0.00
??? ???? ?????????? ?????? ??? ??????? ????? sssh, ? ????? ???? ?????????? ????? ?????????? ?????? nodo1!
??, ?????????, ??? ?????????? ?? ????; ?????? ansible? ??? ?????????? ???????????? ?????????? ???????, ??????? ????? ??????????????? ¿API ansible? ?????????? ansible??? libro de jugadas ansible.
????????? ?????? ? ???? ?? ?????? ???????, ??????? ????? ?????????? Ansible. ?? ?????? ????????? ??????? ansible-doc-l, ????? ??????? ?????? ???? ????????? ??????? Ansible:
[andreyex@control plays]$ ansible-doc -l | wc -l 3387
? ????????? ????? ??????? 3387 ??????? Ansible, ? ?? ?????????? ????????????? ? ?????? ????! ?? ?????? ??????? ????? ????????? ??????, ??????? ?????? ?????????, ? ??????? ????? ?????????? ?????? Ansible.
???? ? ??? ??? ?????? ??????? ??????-?????? ssh (??? ? ? ????); ????? ??? ??????? ????????? agente ssh, ????? ??????? ??????? ??????? ????, ????????? ? ??????? ????????? ????? ?????? ???, ????? Ansible???????? ??????? ?????? ? ????? ?????????? ???????:
[andreyex@control plays]$ eval `ssh-agent` Agent pid 218750 [andreyex@control plays]$ ssh-add Enter passphrase for /home/andreyex/.ssh/id_rsa: Identity added: /home/andreyex/.ssh/id_rsa (andreyex@control)
???????????? ??????????
?? ?????? ?????????, ????? ?? Ansible???????????? ?? ???? ????? ?????????? ?????, ?????? ??? ?????????? ? ????? ????????? ???????; ??? ????? ?? ?????? ???????????? ?????? hacer ping? ??????? ??? ?????????? ????? ????????? ???????:
[andreyex@control plays]$ ansible all -m ping node4 | SUCCESS => { "ansible_facts": { "discovered_interpreter_python": "/usr/bin/python" }, "changed": false, "ping": "pong" } node3 | SUCCESS => { "ansible_facts": { "discovered_interpreter_python": "/usr/libexec/platform-python" }, "changed": false, "ping": "pong" } node1 | SUCCESS => { "ansible_facts": { "discovered_interpreter_python": "/usr/libexec/platform-python" }, "changed": false, "ping": "pong" } node2 | SUCCESS => { "ansible_facts": { "discovered_interpreter_python": "/usr/libexec/platform-python" }, "changed": false, "ping": "pong" }
??? ?? ?????? ??????, ÉXITO ?? ??????. ??????? ???????, ??? ?????? ¿Ping ansible? ????? ??????? ?????????. ????????? ??????? Ansible????????? ?????????, ? ????????? ???, ??? ? ? ?????? ? ????????? Linux.
???????????? ?? ??????? ansible
???? ?? ??? ???????, ??? ??? ?????? ????? ??????? ? Ansible; ?? ?? ???????, ??? ??? ????????????. Ansible????? ?????? ???????????????, ? ??? ??? ????? ??????? ?? ????? ?????????? ?????????.
???? ?? ?????? ??????, ??? ???????????? ???????????? ?????? Ansible, ?? ?????? ????????? ansible-doc? ????????? ????? ??????.
?????????, ?? ?????? ?????????? ??????? ?????? hacer ping? ??????? ??? ?????????????, ?????????:
[andreyex@control plays]$ ansible-doc ping
????????? ??????? ???????????? ?????? silbido.
??? ?????? ???????????? ?? ??????? ??????? ?????? ??????? ?? ??, ?? ????? ?? ????? ?????-???? ?????? ???? ????????? (
. ? ???? ?????? ??? ???????????? ?????, ??????? ?? ?????? ???????.
????? ????, ???? ?? ?????????? ?? ?????, ?? ??????? ????????? ??????? ????, ??? ????????? ?????????? ??????? ??? ??????? Ansible (??????? ?? ??????? ?????).
??????? ?????? caparazón ?????? ??????? crudo
???? ??? ?????? Ansible, ??????? ???? ????? ?????? ???? ? ??????; ???:
- dominio
- shell
- crudo
??? ??? ?????? ????????? ????? ? ??? ?? ????; ??? ????????? ??????? ?? ?????????? ?????. ?? ???? ??????? ???????, ??????? ????????? ??? ??????.
?? ?? ?????? ???????????? ??????? ??? ??????????????? ? ???????dominio. ???????, ????????? ?????????? ??????? ??????? ? ??????:
[andreyex@control plays]$ ansible node2 -m command -a "lscpu | head -n 5" node2 | FAILED | rc=1 >> lscpu: invalid option -- 'n' Try 'lscpu --help' for more information.non-zero return code
??? ??????, ??? ??????dominio?? ???????????? ?????? ??? ???????????????. ?????? ????? ?? ?????? ???????????? ??????shell, ???? ?????? ???????????? ?????? ??? ???????????????. ????????? ?? ?? ??????? ??? ???, ?? ?? ???? ??? ?????????? ?????? ??? ??????shell :
[andreyex@control plays]$ ansible node2 -m shell -a "lscpu | head -n 5" node2 | CHANGED | rc=0 >> Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Byte Order: Little Endian CPU(s): 1 On-line CPU(s) list: 0
??????? ??? ????! ?? ??????? ????????? ?????? ???? ????? ?????? ??????? lscpu?? nodo2.
Ansible?????????? ??????? ¿SSH? Pitón?? ???????, ????? ??????? ??? ?????. ?????? ??????????????? ?????? ?????? ?????????? ¿SSH? ??????? ?????????? ?????? Ansible. ????? ???????, ???? ??????????????? ?????? ????? ??????? ??????? ?? ?????????? ????, ???? ???? pitón?? ?????????? (?? ???????????? ????).
?? ??????? ???? ??????? ????? pitón?? nodo4 (????????????, ?? ??????? ????? ???????????????), ??????? ?? ????? ?????????? ??????? ????, ??? ??????????, ???? ?? ????????? ??????? ??? ????????? ?????? ?? ????, ?? ??????? ?? ?????????? pitón:
root@node4:/usr/bin# mkdir hide root@node4:/usr/bin# mv python* hide/
?????? ?????????, ??? ??????????, ???? ? ?????? ¿Ansible ad-hoc? ????????? ??? ????????? ???????, ?????????? ?? nodo4:
[andreyex@control plays]$ ansible node4 -m shell -a "whoami" node4 | FAILED! => { "ansible_facts": { "discovered_interpreter_python": "/usr/bin/python" }, "changed": false, "module_stderr": "Shared connection to node4 closed.rn", "module_stdout": "/bin/sh: 1: /usr/bin/python: not foundrn", }
[andreyex@control plays]$ ansible node4 -m command -a "cat /etc/os-release" node4 | FAILED! => { "ansible_facts": { "discovered_interpreter_python": "/usr/bin/python" }, "changed": false, "module_stderr": "Shared connection to node4 closed.rn", "module_stdout": "/bin/sh: 1: /usr/bin/python: not foundrn", "msg": "The module failed to execute correctly, you probably need to set the interpreter.nSee stdout/stderr for the exact error", "rc": 127 }
?? ??????? ??????! ?????? ?? ????????? ????????? ?? ?? ??????; ?? ?? ???? ??? ?? ????? ???????????? ??????????????? ??????:
[andreyex@control plays]$ ansible node4 -m raw -a "cat /etc/os-release" node4 | CHANGED | rc=0 >> NAME="Ubuntu" VERSION="18.04.5 LTS (Bionic Beaver)" ID=ubuntu ID_LIKE=debian PRETTY_NAME="Ubuntu 18.04.5 LTS" VERSION_ID="18.04" HOME_URL="https://www.ubuntu.com/" SUPPORT_URL="https://help.ubuntu.com/" BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/" PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy" VERSION_CODENAME=bionic UBUNTU_CODENAME=bionic Shared connection to node4 closed.
??? ??????, ??????????????? ?????? ??? ???????????? ??????? ?? ????, ??????? ?????????? ??????. ?????? ?? ??????? ? ??????? ??????????, ??????? ?? ??????? ?? nodo4:
root@node4:/usr/bin/hide# mv * ..
?? ??????? ??? ??????? ????, ????? ?????????? ????????? ??????? ????????????? ???? ???????:
?????????? ??????? ??????? | ?? | ?? | ?? |
????????? ??????? ? ???????????????? | ??? | ?? | ?? |
????????? ??????? ??? Pitón | ??? | ??? | ?? |
??????! ??? ??????? ??? ? ????? ??????? ?????????? ?? Ansible.