1) добавляем официальный репозитории
sudo
apt-add-repository ppa:ansible/ansible -y
2) обновляем список репозиториев и устанавливаем
sudo apt
update
apt install
ansible
ansible
--version
3) генерируем ключи
ssh-keygen
-t rsa -b 4096 -C "nurlan"
4) копируем ключи на удаленные сервера.
ssh-copy-id
root@192.168.1.1
ssh-copy-id
root@192.168.1.2
5)добавляем хосты в /etc/ansible/hosts
[test]
192.168.1.1
192.168.1.2
6) конфиг ansible.cfg
inventory = /etc/ansible/hosts
library = /usr/share/my_modules/
module_utils = /usr/share/my_module_utils/
forks = 5
poll_interval = 15
sudo_user = root
transport = smart
remote_port = 22
module_lang = C
module_set_locale = False
error_on_missing_handler = True
timeout = 60
remote_user = root
log_path = /var/log/ansible.log
deprecation_warnings = False
library = /usr/share/my_modules/
module_utils = /usr/share/my_module_utils/
forks = 5
poll_interval = 15
sudo_user = root
transport = smart
remote_port = 22
module_lang = C
module_set_locale = False
error_on_missing_handler = True
timeout = 60
remote_user = root
log_path = /var/log/ansible.log
deprecation_warnings = False
7)пробуем проверить ОЗУ на группе хостов
ansible -m shell -a 'free -m' test
192.168.1.1 | SUCCESS | rc=0 >> total used free shared buffers cached Mem: 2006 328 1677 0 41 87 -/+ buffers/cache: 200 1805 Swap: 2047 0 2047 192.168.1.2 | SUCCESS | rc=0 >> total used free shared buffers cached Mem: 2006 1215 790 23 196 676 -/+ buffers/cache: 342 1663 Swap: 1635 0 1635
8) останавливаем postfix на группе хостов
ansible -s -m service -a 'name=postfix state=stopped' test
значения state:
state |
| started /stopped are idempotent actions that will not run commands unless necessary. restarted will always bounce the service. reloaded will always reload. At least one of state and enabled are required. Note that reloaded will start the service if it is not already started, even if your chosen init system wouldn't normally. |
Комментариев нет:
Отправить комментарий