Skip to content

Instantly share code, notes, and snippets.

@lxdcn lxdcn/oracle-rpm.yml
Created Oct 23, 2015

Embed
What would you like to do?
Vagrant Auto Provision Ansible script to install Oracle XE on RPM based Linux
# -*- mode: python -*-
---
- hosts: all
vars:
oracle_root_password: oracle
oracle_normal_username: sa
oracle_normal_password: sa
oracle_install_file_dir_base: /vagrant
tasks:
- name: install dependencies for Oracle XE
sudo: yes
yum: name={{ item }} state=latest
with_items: [unzip, glibc, make, binutils, gcc, libaio, bc]
- stat: path={{ oracle_install_file_dir_base }}/oracle-xe-11.2.0-1.0.x86_64.rpm.zip
register: oracle_install_zip
- name: fail the play if the zip is not found
fail: msg="Need oracle-xe-11.2.0-1.0.x86_64.rpm.zip in current dir"
when: oracle_install_zip.stat.exists == False
- name: Unzip oracle xe package
sudo: no
unarchive: src={{ oracle_install_file_dir_base }}/oracle-xe-11.2.0-1.0.x86_64.rpm.zip dest={{ oracle_install_file_dir_base }} copy=no
- name: install ansible dependencies
sudo: yes
yum: name={{ item }} state=latest
with_items: [libselinux-python]
- name: create new swap file
sudo: yes
command: dd if=/dev/zero of=/swapfile bs=1M count=2048
when: ansible_swaptotal_mb < 2048
- name: format the new swap space
sudo: yes
command: mkswap -f /swapfile
- name: add to fstab
sudo: yes
lineinfile:
dest: /etc/fstab
regexp: "swapfile"
line: "/swapfile swap swap defaults 0 0"
state: present
- name: turn on swap
sudo: yes
command: swapon -va
- name: install Oracle XE
sudo: yes
yum: name={{ oracle_install_file_dir_base }}/Disk1/oracle-xe-11.2.0-1.0.x86_64.rpm state=present
- name: change Oracle SYS password
sudo: yes
lineinfile:
dest: "{{ oracle_install_file_dir_base }}/Disk1/response/xe.rsp"
regexp: "{{ item.regexp }}"
line: "{{ item.line }}"
with_items:
- { regexp: "ORACLE_PASSWORD=<value required>", line: "ORACLE_PASSWORD={{ oracle_root_password }}" }
- { regexp: "ORACLE_CONFIRM_PASSWORD=<value required>", line: "ORACLE_CONFIRM_PASSWORD={{ oracle_root_password }}" }
- name: configure Oracle XE
sudo: yes
command: /etc/init.d/oracle-xe configure responseFile={{ oracle_install_file_dir_base }}/Disk1/response/xe.rsp
- name: set Oracle XE env
sudo: yes
lineinfile:
dest: /home/{{ ansible_ssh_user }}/.bashrc
regexp: "oracle_env"
line: ". /u01/app/oracle/product/11.2.0/xe/bin/oracle_env.sh"
state: present
- name: configure Oracle XE
sudo: no
shell: . ~/.bashrc && echo "EXEC DBMS_XDB.SETLISTENERLOCALACCESS(FALSE);" | sqlplus system/"{{ oracle_root_password }}" ; sleep 1
- name: create normal user
sudo: no
shell: . ~/.bashrc && echo "create user {{ oracle_normal_username }} identified by {{ oracle_normal_password }};" | sqlplus system/"{{ oracle_root_password }}" ; sleep 1
- name: grant normal user
sudo: no
shell: . ~/.bashrc && echo "grant CREATE SESSION, ALTER SESSION, CREATE DATABASE LINK, CREATE MATERIALIZED VIEW, CREATE PROCEDURE, CREATE PUBLIC SYNONYM, CREATE ROLE, CREATE SEQUENCE, CREATE SYNONYM, CREATE TABLE, CREATE TRIGGER, CREATE TYPE, CREATE VIEW, UNLIMITED TABLESPACE to {{ oracle_normal_username }};" | sqlplus system/"{{ oracle_root_password }}" ; sleep 1
- name: allow oracle 1521 port
sudo: yes
lineinfile: dest=/etc/sysconfig/iptables regexp="1521" insertbefore="-A INPUT -j REJECT" line="-A INPUT -m state --state NEW -m tcp -p tcp --dport 1521 -j ACCEPT"
- name: reload iptables
sudo: yes
service: name=iptables state=reloaded
@lxdcn

This comment has been minimized.

Copy link
Owner Author

lxdcn commented Oct 23, 2015

Due to task configure Oracle XE, sorry to say it's NOT idempotent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.