1. Playbooks
Last updated
- name: install apache, php & mysql
hosts: test-servers
become: true
become_user: root
gather_facts: true
tasks:
- name: "Install Apache2"
#present is used since we are installing this package for first time
package: name=apache2 state=present
- name: "Install PHP Cli"
package: name=php-cli state=present
- name: "Install PHP Mysql"
package: name=php-mysql state=present- hosts: all
remote_user: root
tasks:
- name: "Install PIP"
apt: name=python-pip state=present
- name: "Install Python MySQL module"
pip: name=MySQL-python
- name: "Create db user noman"
mysql_user: user=noman password=aziz priv=*.*:ALL state=present
- name: "Create db ansible"
mysql_db: db=ansible state=present
- name: "Create table reg"
command: mysql -u noman -p aziz -e 'CREATE TABLE reg (name varchar(30), email varchar(30));' ansible
- name: copy
hosts: test-servers
become: true
become_true: root
gather_facts: true
tasks:
- name: "copy file"
copy: src=/home/noman/index.html dest=/var/www/html/index.html- hosts: webservers
tasks:
- name: install apache2
apt: name=apache2 update_cache=yes latest=yes
notify:
- restart apache2
handlers:
- name: restart apache2
service: name=apache2 state=restarted