sudo apt install software-properties-common
sudo apt-add-repository --yes --update ppa:ansible/ansible
sudo apt install ansible
/etc/ansible/ansible.cfg
/etc/ansible/hosts
[servery]
10.0.0.90
10.0.0.90:22
proto09.pv090.fi.muni.cz
[servery:vars]
ansible_ssh_private_key_file = /path
ansible_user = root
ansible_password = pass
installApache.yaml
:
---
- name: install apache2
apt: name=apache2 update_cache=yes state=latest
- name: enable mod_rewrite
apache2_module: name=rewrite state=present
notify:
- restart apache2
handlers:
- name: restart apache2
service: name=apache2 state=restarted
playbook.yaml
:
---
- hosts: servery
vars:
var1: ".fi.muni.cz"
var2: "bbb"
remote_user: root
tasks:
- include installApache.yaml
- set_fact:
domain: "proto09.pv090. {{ var1 }}"
- name: create VirtualHost devel
template: src=VirtualHosts/virtualHost.conf dest=/etc/apache2/sites-available/{{ domain }}.conf
register: upload
- name: a2ensite {{ domain }}
command: a2ensite {{ domain }}
when: upload|success
args:
creates: /etc/apache2/sites-enabled/{{ domain }}.conf
notify:
- restart apache2
handlers:
- name: restart apache2
service: name=apache2 state=restarted
ansible-playbook playbook.yaml
# playbooks
site.yml
webservers.yml
fooservers.yml
roles/
common/
tasks/
handlers/
library/
files/
templates/
vars/
defaults/
meta/
webservers/
tasks/
defaults/
meta/
---
- hosts: webservers
roles:
- { role: foo, vars: { message: "first" } }
---
dependencies:
- role: common
vars:
some_parameter: 3
- role: apache
vars:
apache_port: 80