DevOps 05202017 Ansible Tags Template Roles Handlers Create Database

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 20

Tag example -(To execute part of the playbook)

[user1@server1 ~]$ cp webserver.yml tag.yml

-For instance we want to execute particular task


[user1@server1 ~]$ ansible-playbook tag.yml --tags "install"
(In the above example "httpd" will be installed)
-Template (From One location to another)
[user1@server1 ~]$ cp webserver.yml template.yml

[user1@server1 ~]$ more index.html.j2


The below fill be in j2 format
Output -
Roles -
Playbooks can also include plays from other playbook files. ... Roles in Ansible build on the idea of
include files and combine them to form clean, reusable abstractions – they allow you to focus more on
the big picture and only dive down into the details when needed

-To start using "roles" we need to create dir "roles"


[user1@server1 webserver]$ mkdir roles

-We are going to create dir "webserver" in roles dir


[user1@server1 roles]$ mkdir webserver

-In the below location we are going to create 07 dir (defaults, files, handlers, meta, tasks, templates &
vars)
[user1@server1 webserver]$ pwd
/home/user1/roles/webserver

-How to create multiple dir as show below


[user1@server1 webserver]$ mkdir -p {defaults,files,handlers,meta,tasks,templates,vars}
[user1@server1 webserver]$ tree
-This is the executable playbook "role1.yml"
-Installing MYSQL using Galaxy Ansible website
- Pick the MYSQL from the web - "https://galaxy.ansible.com/bennojoy/mysql/"
- Copy the - "ansible-galaxy install bennojoy.mysql" under root.

After copying go to the next - cd /etc/ansible/roles


[user1@server1 ~]$ cd /etc/ansible/roles
[user1@server1 roles]$ ls
bennojoy.mysql
Install Mysql
yum install mysql-server
-To start service
start service - service mysqld start
mysql
show databases;
Create database test123;
USE -command
Now we have created test123 Database and now create the table "abc"
How to QUIT from mysql - \q

MYSQL - Config info

You might also like