Steps to create DBA user using ansible tool :-
Presteps have to be done in SOURCE (ansible) server,
[root@ansible ansible-oracle-modules-master]# cat /etc/ansible/hosts [database-servers] test
[root@ansible ansible-oracle-modules-master]# ansible all -m ping test | success >> { "changed": false, "ping": "pong" }
Presteps have to be done in TARGET (TEST database) server,
Step 1:- Install PIP package in TARGET side.
[root@test oracle]# curl "https://bootstrap.pypa.io/get-pip.py" -o "get-pip.py" % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 1604k 100 1604k 0 0 71531 0 0:00:22 0:00:22 --:--:-- 203k [root@test oracle]# python get-pip.py Collecting pip Downloading https://files.pythonhosted.org/packages/5f/25/e52d3f31441505a5f3af41213346e5b6c221c9e086a166f3703d2ddaf940/pip-18.0-py2.py3-none-any.whl (1.3MB) 100% |████████████████████████████████| 1.3MB 164kB/s Collecting wheel Downloading https://files.pythonhosted.org/packages/81/30/e935244ca6165187ae8be876b6316ae201b71485538ffac1d718843025a9/wheel-0.31.1-py2.py3-none-any.whl (41kB) 100% |████████████████████████████████| 51kB 156kB/s Installing collected packages: pip, wheel Successfully installed pip-18.0 wheel-0.31.1
Step 2:- Install and upgrade the cx_oracle package,
[root@test oracle]# pip -V pip 18.0 from /usr/lib/python2.7/site-packages/pip (python 2.7) [root@test oracle]# python -m pip install cx_Oracle --upgrade Collecting cx_Oracle Downloading https://files.pythonhosted.org/packages/3b/09/6b10675a6db7c7da1b8d23225f0a95b2a45248c56a1e8f711d59809278d3/cx_Oracle-6.4.1-cp27-cp27mu-manylinux1_x86_64.whl (590kB) 100% |████████████████████████████████| 593kB 256kB/s Installing collected packages: cx-Oracle Successfully installed cx-Oracle-6.4.1
Step 3:- Import the cx_oracle package,
[root@test oracle]# python Python 2.7.5 (default, Sep 5 2016, 02:30:38) [GCC 4.8.5 20150623 (Red Hat 4.8.5-9)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import cx_Oracle >>> exit()
SOURCE :-
Step 1:- Download oracle user from github site.Click Here
Step 2:- Move the ZIP file to ansible server.
Step 3:- Create a directory library where .yml is created.
Step 4:- Copy the oracle_user role to library directory
[root@ansible ansible-oracle-modules-master]# mkdir -p library [root@ansible ansible-oracle-modules-master]# cp oracle_user /home/ansible/Desktop/ansible-oracle-modules-master/library/
Step 5:- Modify the variables as per your environment.
[root@ansible ansible-oracle-modules-master]# cat usercreation.yml - hosts: database-servers user: root gather_facts: false vars: oracle_home: /u01/app/oracle/product/12.1.0/dbhome_1/ hostname: test.localdomain.com service_name: test.localdomain.com user: system password: oracle oracle_env: ORACLE_HOME: "{{ oracle_home }}" LD_LIBRARY_PATH: "{{ oracle_home }}/lib" dba_user: - schema: india schema_password: india state: present default_tablespace: users grants: - "dba" tasks: - name: Create DBA user oracle_user: hostname={{ hostname }} service_name={{ service_name }} mode=normal user={{ user }} password={{ password }} schema={{ item.0.schema }} schema_password={{ item.0.schema_password }} state={{ item.0.state }} default_tablespace={{ item.0.default_tablespace }} grants={{ item.1 }} environment: "{{ oracle_env }}" with_subelements: - dba_user - grants
In TARGET side,check the user in TEST database
Step 6:- Run the playbook file usercreation.yml
Output:-
[root@ansible ansible-oracle-modules-master]# ansible-playbook usercreation.yml PLAY [database-servers] ******************************************************* TASK: [Create DBA user] ******************************************************* changed: [test] => (item=({'schema_password': 'india', 'state': 'present', 'default_tablespace': 'users', 'schema': 'india'}, 'dba')) PLAY RECAP ******************************************************************** test : ok=1 changed=1 unreachable=0 failed=0
TARGET :-
Step 7 :- Check the user INDIA is created in TARGET database.
Catch Me On:- Hariprasath Rajaram
Telegram:https://t.me/joinchat/I_f4DhGF_Zifr9YZvvMkRg
LinkedIn:https://www.linkedin.com/in/hari-prasath-aa65bb19/
Facebook:https://www.facebook.com/HariPrasathdba
FB Group:https://www.facebook.com/groups/894402327369506/
FB Page: https://www.facebook.com/dbahariprasath/?
Twitter: https://twitter.com/hariprasathdba