sudo apt-add-repository -y ppa:ansible/ansible
sudo apt-get update
sudo apt-get install -y ansible
/etc/ansible/ansible.cfg
/etc/ansible/hosts
nasledovne:
[proto02-beta]
10.0.20.2
[proto02-beta:vars]
ansible_user=simona
ansible_ssh_private_key_file=~/.ssh/privateKey
ansible_password
, ale heslo sa odporúča zašifrovať a uložiť do Vault súboru.
---
- hosts: proto02-beta
become: yes
tasks:
- name: Nainštaluj potrebné balíčky
apt: name={{ item }} state=present
with_items:
- netplan.io
- iptables-persistent
- name: Nastav sieť
copy:
dest: "/etc/netplan/configuration.cfg"
content: |
network:
ethernets:
ens3:
addresses: [10.0.0.20/24]
gateway4: 10.0.0.1
nameservers: [10.0.0.1]
- name: Aplikuj nastavenia
command: netplan apply
- name: Zmeň nastavenia pre ssh
lineinfile:
dest: "/etc/ssh/ssh_config"
regexp: 'GSSAPIAuthentication'
line: 'GSSAPIAuthentication no'
present: yes
- name: naištaluj potrebné balíčky
apt: name={{ item }} state=present
with_items:
- netplan.io
- iptables-persistent
- name: Aplikuj netplan konfiguráciu
command: netplan apply
register: netplan_result
- name: Reštartuj networkd
service: name=networkd state=restarted
when: "'Invalid YAML' not in netplan_result.stdout"
- name: Reštartuj systém
reboot:
changed_when, failed_when, ignore_errors
ansible-playbook playbook.yml
my_role/
defaults/
files/
handlers/
meta/
tasks/
templates/
tests/
vars/
playbook.yml:
---
- hosts: myserver
roles:
my_role
ansible-galaxy init my_role
ansible myserver -s -a "apt install netplan.io"
ansible myserver -s -m apt -a "name=netplan.io state=present"
rkt
(podobný Dockeru).
etcd
), takže namiesto toho, aby bola konfigurácia doručená na všetky serveri, si každý server iba prečíta konfiguráciu na princípe kľúč-hodnota.
fleet
.