Basit Ansible Örneği

Buradaki amacım tek bir sunucuda basit bir ansible örneği göstermek olacaktır.

Ansible aracını kuruyorum.

$ sudo apt install ansible -y

Kurduktan sonra ansible versiyonuna bakıyorum.

$ ansible --version
ansible 2.10.8
  config file = None
  configured module search path = ['/home/aynur/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3/dist-packages/ansible
  executable location = /usr/bin/ansible
  python version = 3.10.4 (main, Apr  2 2022, 09:04:19) [GCC 11.2.0]

İşlemleri ansible dizini altında yapacağım.
– Hostum bir mail sunucu ve 33.15.10.13 IP adresine sahip.

$ mkdir -p ansible/inventory/
$ cd ansible/inventory/
$ vim hosts.yml
$ cat hosts.yml 
all:
  hosts:
    test-mail:
      ansible_host: 33.15.10.13
  vars:
    ansible_user: root

SSH bilgilerini sunucuya eklememiz gerekiyor.

$ ssh-keygen
$ ssh-copy-id -i ~/.ssh/id_rsa.pub root@33.15.10.13

Hostumuzda birkaç komut çalıştırmayı deneyelim.

$ ansible -i inventory/hosts.yml -m raw -a "su - zimbra -c 'zmcontrol status'" test-mail
test-mail | CHANGED | rc=0 >>
Host mail.test.com
	amavis                  Running
	antispam                Running
	antivirus               Running
	dnscache                Running
	ldap                    Running
	logger                  Running
	mailbox                 Running
	memcached               Running
	mta                     Running
	opendkim                Running
	proxy                   Running
	service webapp          Running
	snmp                    Running
	spell                   Running
	stats                   Running
	zimbra webapp           Running
	zimbraAdmin webapp      Running
	zimlet webapp           Running
	zmconfigd               Running
Shared connection to 33.15.10.13 closed.

$ ansible -i inventory/hosts.yml -m raw -a "su - zimbra -c 'zmcontrol -v'" test-mail
test-mail | CHANGED | rc=0 >>
Release 9.0.0_ZEXTRAS_20220402.RHEL8_64_20220419075929 RHEL8_64 FOSS edition.
Shared connection to 33.15.10.13 closed.

2 Beğeni