ansible - doag deutsche oracle-anwendergruppe … · our company. 3 16.11.2016 ansible for oracle...
TRANSCRIPT
BASEL BERN BRUGG DÜSSELDORF FRANKFURT A.M. FREIBURG I.BR. GENEVA
HAMBURG COPENHAGEN LAUSANNE MUNICH STUTTGART VIENNA ZURICH
AnsibleFor Oracle DBAs
Alexander HofstetterTrivadis GmbH Munich
@lxDBA
About me
Consultant, Trivadis GmbH, Munich
Working with Oracle since 2005
Since 2008 Oracle DBA
Focus areas
– High Availability
– SLA Management
– Migration & Upgrades
16.11.2016 Ansible for Oracle DBAs2
Our company.
Ansible for Oracle DBAs3 16.11.2016
Trivadis is a market leader in IT consulting, system integration, solution engineering
and the provision of IT services focusing on and
technologies
in Switzerland, Germany, Austria and Denmark. We offer our services in the following
strategic business fields:
Trivadis Services takes over the interacting operation of your IT systems.
O P E R A T I O N
COPENHAGEN
MUNICH
LAUSANNE
BERN
ZURICH
BRUGG
GENEVA
HAMBURG
DÜSSELDORF
FRANKFURT
STUTTGART
FREIBURG
BASEL
VIENNA
With over 600 specialists and IT experts in your region.
Ansible for Oracle DBAs4 16.11.2016
14 Trivadis branches and more than
600 employees
200 Service Level Agreements
Over 4,000 training participants
Research and development budget:
CHF 5.0 million
Financially self-supporting and
sustainably profitable
Experience from more than 1,900
projects per year at over 800
customers
Agenda
Ansible for Oracle DBAs5 16.11.2016
1. What is Ansible?
2. Installation
3. Structure and Architecture
4. Use cases for Oracle DBAs
5. Conclusions
What is Ansible (company)
Ansible for Oracle DBAs7 16.11.2016
Founded 2013 by Michael DeHaan and Said Ziouani
Ansible Tower
Consulting
Maintain and develop Ansible Software
Bought by Red Hat in 2015
What is Ansible (software)
Ansible for Oracle DBAs8 16.11.2016
Open Source Project created in 2012 by Michael DeHaan
Automation engine
Agentless
Easy to use
Powerful
Installation and requirements
Ansible for Oracle DBAs11 16.11.2016
Installation (Control Machine)
– Use the source
– OS package manager
– PIP (Python package manager)
Python 2.6 or 2.7
– Ansible 2.2 allows Python 3
Windows not supported yet
Requirements managed nodes
Ansible for Oracle DBAs12 16.11.2016
A network communication
– default is ssh for Unix / Linux
– uses PowerShell Remoting for Windows
(ansible_connection: winrm)
Python >= 2.4
If Python < 2.5 you need python-simplejson
– can be installed with the raw Module
Installation
Ansible for Oracle DBAs13 16.11.2016
# Source
$ git clone git://github.com/ansible/ansible.git --recursive
# OS package manager
$ yum install ansible
$ apt-get install ansible
# Python package manager
$ pip install ansible
Architecture Overview
Ansible for Oracle DBAs15 16.11.2016
Playbook
Play 1 Group1
Play 2 all
Task 1
Task 2
Task 3
Task 1
…
ModuleA
ModuleB
ModuleA
ModuleC
Inventory
Server 1
Server 5
[Group1]
Server 1
Server 2
Server 3
[Group2]
Server 4
Server 5
Server 1
Server 2
Server 3
Inventory
Ansible for Oracle DBAs16 16.11.2016
Inventory
Server 1
Server 5
[Group1]
Server 1
Server 2
Server 3
[Group2]
Server 4
Server 5
Inventory
Ansible for Oracle DBAs17 16.11.2016
Two types of inventories
– Static inventory
– Dynamic inventory
Default is a static host file
Using proxies is possible
Host file
Ansible for Oracle DBAs18 16.11.2016
$ cat /etc/ansible/hosts
custom_alias ansible_host=192.168.100.11
192.168.100.23
[ora-prod]
p-db01.trivadis.com ansible_port=22 ansible_user=hofstetter
p-db02.trivadis.com ansible_port=22 ansible_user=hofstetter
[ora-test]
t-db[01-11].trivadis.com
[ora-cc]
repodb.trivadis.com
Host file (Proxy Example One Line Command)
Ansible for Oracle DBAs19 16.11.2016
hostname ansible_host=destination_host_ip ansible_user=hostuser
ansible_ssh_private_key_file=~/.ssh/serverkey/id.pem
ansible_ssh_common_args=
'-o ProxyCommand="ssh -W %h:%p -q [email protected]"'
Module
Ansible for Oracle DBAs20 16.11.2016
Playbook
Play 1 Group1
Play 2 all
Task 1
Task 2
Task 3
Task 1
…
ModuleA
ModuleB
ModuleA
ModuleC
Module
Ansible for Oracle DBAs21 16.11.2016
Two types of modules delivered by Ansible
– Core
– Extras
Core Modules maintained by Ansible
Extras Modules are popular Modules delivered by the community
Custom Modules
Architecture Overview
Ansible for Oracle DBAs22 16.11.2016
Playbook
Play 1 Group1
Play 2 all
Task 1
Task 2
Task 3
Task 1
…
s
e
r
i
a
l
ModuleA
ModuleB
ModuleA
ModuleC
Inventory
Server 1
Server 5
[Group1]
Server 1
Server 2
Server 3
[Group2]
Server 4
Server 5
p
a
r
a
l
l
e
l
Server 1
Server 2
Server 3
Playbooks
Ansible for Oracle DBAs23 16.11.2016
Written in YAML
Usage of Jinja2 as a Template Language
Contain One or More Plays
– Each Play run on a specific Host / Group
Serial execution
Playbook Example
Ansible for Oracle DBAs24 16.11.2016
---
- hosts: webservers
tasks:
- name: ensure apache is at the latest version
yum: name=httpd state=latest
- name: write the apache config file
template: src=/srv/httpd.j2 dest=/etc/httpd.conf
- hosts: databases
tasks:
- name: ensure postgresql is at the latest version
yum: name=postgresql state=latest
- name: ensure that postgresql is started
service: name=postgresql state=started
Playbook example (2)
Ansible for Oracle DBAs25 16.11.2016
$ cat ping.yml
---
- hosts: ora-test
tasks:
- name: ping hosts
ping:
- name: shell test
shell: uptime
register: shell_test
- name: debug shell_test
debug: var=shell_test verbosity=2
Terminal Output
Ansible for Oracle DBAs26 16.11.2016
$ ansible-playbook -i hosts ping.yml -v
Using /etc/ansible/ansible.cfg as config file
PLAY [ora-test]
****************************************************************
TASK [setup]
*******************************************************************
ok: [testdb15.trivadis.com]
ok: [testdb13.trivadis.com]
ok: [testdb11.trivadis.com]
ok: [testdb12.trivadis.com]
Terminal Output (2)
Ansible for Oracle DBAs27 16.11.2016
TASK [ping hosts] **************************************************************
ok: [testdb11.trivadis.com] => {"changed": false, "ping": "pong"}
ok: [testdb12.trivadis.com] => {"changed": false, "ping": "pong"}
ok: [testdb13.trivadis.com] => {"changed": false, "ping": "pong"}
ok: [testdb15.trivadis.com] => {"changed": false, "ping": "pong"}
TASK [shell test] **************************************************************
changed: [testdb11.trivadis.com] => {"changed": true, "cmd": "uptime" ...
"stdout_lines": [" 21:31:39 up 104 days, 23:17
changed: [testdb13.trivadis.com] => {"changed": true, "cmd": "uptime" ...
"stdout_lines": [" 21:31:39 up 104 days, 23:22
changed: [testdb15.trivadis.com] => {"changed": true, "cmd": "uptime" ...
"stdout_lines": [" 21:31:39 up 7 days, 11:09
changed: [testdb12.trivadis.com] => {"changed": true, "cmd": "uptime" ...
"stdout_lines": [" 21:31:39 up 7 days, 10:42
Terminal Output (3)
Ansible for Oracle DBAs28 16.11.2016
TASK [debug shell_test] ********************************************************
skipping: [testdb11.trivadis.com] => {"changed": false, "skipped": true,
"skipped_reason": "Verbosity threshold not met."}
skipping: [testdb13.trivadis.com] => {"changed": false, "skipped": true,
"skipped_reason": "Verbosity threshold not met."}
skipping: [testdb12.trivadis.com] => {"changed": false, "skipped": true,
"skipped_reason": "Verbosity threshold not met."}
skipping: [testdb15.trivadis.com] => {"changed": false, "skipped": true,
"skipped_reason": "Verbosity threshold not met."}
PLAY RECAP *********************************************************************
testdb11.trivadis.com : ok=3 changed=1 unreachable=0 failed=0
testdb12.trivadis.com : ok=3 changed=1 unreachable=0 failed=0
testdb13.trivadis.com : ok=3 changed=1 unreachable=0 failed=0
testdb15.trivadis.com : ok=3 changed=1 unreachable=0 failed=0
Ad-hoc command
Ansible for Oracle DBAs29 16.11.2016
-m -i
Server 1
Server 5
[Group1]
Server 1
Server 2
Server 3
[Group2]
Server 4
Server 5
p
a
r
a
l
l
e
l
Server 1
Server 2
Server 3
Group1
Module
Ad-Hoc Command
Ansible for Oracle DBAs30 16.11.2016
Single Module Execution
ansible -i <Hostfile> -m <module> <target host/group/all>
ansible -i /etc/ansible/hosts_demo -m ping all
Reusage of Tasks / Plays?
Ansible for Oracle DBAs31 16.11.2016
Playbook
Play 1 Group1
Play 2 all
Task 1
Task 2
Task 3
Task 1
…
s
e
r
i
a
l
ModuleA
ModuleB
ModuleA
ModuleC
Inventory
Server 1
Server 5
[Group1]
Server 1
Server 2
Server 3
[Group2]
Server 4
Server 5
p
a
r
a
l
l
e
l
Server 1
Server 2
Server 3
Role
Roles
Ansible for Oracle DBAs32 16.11.2016
Contain one or more tasks
Reusage
Roles included in Playbook
Role structure can be created due Ansible Galaxy init command
Ansible for Oracle DBAs33 16.11.2016
$ cd roles/
$ ansible-galaxy init new_role
- new_role was created successfully
$ tree new_role/
new_role/
├── defaults
│ └── main.yml
├── files
├── handlers
│ └── main.yml
├── meta
│ └── main.yml
├── README.md
├── tasks
│ └── main.yml
├── templates
├── tests
│ ├── inventory
│ └── test.yml
└── vars
└── main.yml
Variables
Ansible for Oracle DBAs34 16.11.2016
role defaults
inventory vars
inventory group_vars
inventory host_vars
playbook group_vars
playbook host_vars
host facts
play vars
play vars_prompt
play vars_files
registered vars
set_facts
role and include vars
block vars (only for tasks in block)
task vars (only for the task)
extra vars (always win precedence)
Automatic Relink Example
Ansible for Oracle DBAs37 16.11.2016
---
- hosts: test-db
roles:
- role: shutdown_oracle
- role: yum_update_all
- role: restart_server
- role: relink_rdbms
- role: relink_gi
- role: startup_oracle
Roles
Ansible for Oracle DBAs38 16.11.2016
Role shutdown_oracle:
---
### Only run one of these two tasks depending if you run
### a service or use just a start stop script
- name: shutdown oracle stack
shell: /u00/app/oracle/local/dba/bin/oracle_start_stop.sh stop
tasks:
- name: stop and disable service
service: name=oracle enabled=no state=stopped
become: true
become_user: root
Role yum_update_all:
Ansible for Oracle DBAs39 16.11.2016
---
- name: yum update all packages
yum: name=* state=latest
shutdown_server
Ansible for Oracle DBAs40 16.11.2016
---
- name: restart machine
shell: sleep 2 && shutdown -r now "Ansible updates triggered"
async: 1
poll: 0
ignore_errors: true
### local_action is in one line!
- name: waiting for server to come back
local_action: wait_for port=22 host="{{ ansible_ssh_host |
default(inventory_hostname) }}" search_regex=OpenSSH delay=10
relink_rdbms
Ansible for Oracle DBAs41 16.11.2016
---
- name: get RDBMS Home
shell: awk 'BEGIN{ FS=":" } !/^#.*/ && /.*:.*:.*/ { print $2 }'
/etc/oratab | grep -i rdbms |sort -u
register: oracle_home
- name: relink RDBMS
become: true
become_user: oracle
shell: export ORACLE_HOME={{ item }}; $ORACLE_HOME/bin/relink all
with_items:
- "{{ oracle_home.stdout_lines }}"
relink_gi (part 1)
Ansible for Oracle DBAs42 16.11.2016
---
- name: get Gridinfrastructure Home
shell: awk 'BEGIN{ FS=":" } !/^#.*/ && /.*:.*:.*/ { print $2 }'
/etc/oratab | grep -i -E 'asm|grid' |sort -u
register: grid_home
- name: Unlock Grid Infrastructure
shell: export ORACLE_HOME={{ item }}; /usr/bin/perl
$ORACLE_HOME/crs/install/rootcrs.pl -unlock
with_items:
- "{{ grid_home.stdout_lines }}"
relink_gi (part 2)
Ansible for Oracle DBAs43 16.11.2016
- name: relink Grid Home
become: true
become_user: grid
shell: export ORACLE_HOME={{ item }}; $ORACLE_HOME/bin/relink
with_items:
- "{{ grid_home.stdout_lines }}"
- name: Lock Grid Infrastructure
shell: export ORACLE_HOME={{ item }}; /usr/bin/perl
$ORACLE_HOME/crs/install/rootcrs.pl -patch
with_items:
- "{{ grid_home.stdout_lines }}"
startup_oracle
Ansible for Oracle DBAs44 16.11.2016
---
### Only run one of these two tasks depending if you run
### a service or use just a start stop script
- name: startup oracle stack
shell: /u00/app/oracle/local/dba/bin/oracle_start_stop.sh start
tasks:
- name: start and enable service
service: name=oracle enabled=yes state=started
become: true
become_user: root
Conclusion
Ansible for Oracle DBAs46 16.11.2016
Many DBA tasks can be automated
No built-in Oracle modules
Working with sqlplus output is challenging
Easy to learn basics
No special developing skills necessary
Good documentation ( docs.ansible.com )
Addional Information
Ansible for Oracle DBAs47 16.11.2016
Documentation:
http://docs.ansible.com/
YAML:
http://docs.ansible.com/ansible/YAMLSyntax.html
Modules by category:
http://docs.ansible.com/ansible/modules_by_category.html
All Modules:
http://docs.ansible.com/ansible/list_of_all_modules.html
Any questions…?
Alexander Hofstetter
Tel: +49 89 99 27 59 302
16.11.2016 Ansible for Oracle DBAs48