diff --git a/README.md b/README.md new file mode 100644 index 0000000..9c2137b --- /dev/null +++ b/README.md @@ -0,0 +1,72 @@ +ansible-role-oracleinstaclient +============================== + +Install oracle instant client base package and sqlplus + +Requirements +------------ + +None. + +Role Variables +-------------- + +Make sure to update all these values when updateing packages. + +```yaml +# ldpath variable, do not forget to update when changing versions! +oic_pkg_version: "19.8" +oic_ld_library_path: "/usr/lib/oracle/{{ oic_pkg_version }}/client64/lib" +oic_package_base_url: "https://download.oracle.com/otn_software/linux/instantclient/19800" +oic_package_dest: "/tmp" + +# oracle instant client database connection parameters +oic_databases: + - sid: TEST + host: testdb.mydbserver.com + port: 2322 + service_name: TEST + +# oic packages +oic_install_packages: + - { pkg_name: "oracle-instantclient19.8-basic-19.8.0.0.0-1.x86_64.rpm", pkg_hash: "sha256:c42159e5466c661cc85d7a4d062e98aa06dc84251eea9de10ba2ddf2a7ea37cd" } + - { pkg_name: "oracle-instantclient19.8-sqlplus-19.8.0.0.0-1.x86_64.rpm", pkg_hash: "sha256:436f74965d27894ce67242d6d155c41e3a561e959bf2ce8ba027931a29d63700" } + +``` + +Dependencies +------------ + +None. + +Example Playbook +---------------- + +```yaml +--- + +- name: oracle instant client test play + hosts: all + become: true + vars: + oic_install_packages: + - { pkg_name: "oracle-instantclient19.8-basic-19.8.0.0.0-1.x86_64.rpm", pkg_hash: "sha256:c42159e5466c661cc85d7a4d062e98aa06dc84251eea9de10ba2ddf2a7ea37cd" } + - { pkg_name: "oracle-instantclient19.8-sqlplus-19.8.0.0.0-1.x86_64.rpm", pkg_hash: "sha256:436f74965d27894ce67242d6d155c41e3a561e959bf2ce8ba027931a29d63700" } + oic_databases: + - sid: TEST + host: testdb.mydbserver.com + port: 2322 + service_name: TEST + roles: + - oracle_instant_client +``` + +License +------- + +GPLv3 + +Author Information +------------------ + +Aaron (aaron@0x29a.ch) diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100644 index 0000000..a50a0cd --- /dev/null +++ b/defaults/main.yml @@ -0,0 +1,30 @@ +--- + +# oracle instant client ldpath variable +oic_pkg_version: "19.8" +oic_ld_library_path: "/usr/lib/oracle/{{ oic_pkg_version }}/client64/lib" +oic_package_base_url: "https://download.oracle.com/otn_software/linux/instantclient/19800" +oic_package_dest: "/tmp" + +# oracle instant client paths for env +oic_subdirectory: "/usr/lib/oracle/{{ oic_pkg_version }}/client64" +oic_config_path: "{{ oic_subdirectory }}/lib/network/admin" +oic_bin_path: "{{ oic_subdirectory }}/bin" + +# oracle instant client user and group +oic_user: oracle +oic_user_id: 11000 +oic_group: oinstall +oic_group_id: 11000 + +# oracle instant client database connection parameters +oic_databases: + - sid: TEST + host: testdb.mytestdb.com + port: 2322 + service_name: TEST + +# oralce instant client installed packages +oic_install_packages: + - { pkg_name: "oracle-instantclient19.8-basic-19.8.0.0.0-1.x86_64.rpm", pkg_hash: "sha256:c42159e5466c661cc85d7a4d062e98aa06dc84251eea9de10ba2ddf2a7ea37cd" } + - { pkg_name: "oracle-instantclient19.8-sqlplus-19.8.0.0.0-1.x86_64.rpm", pkg_hash: "sha256:436f74965d27894ce67242d6d155c41e3a561e959bf2ce8ba027931a29d63700" } diff --git a/handlers/main.yml b/handlers/main.yml new file mode 100644 index 0000000..8fe2bf3 --- /dev/null +++ b/handlers/main.yml @@ -0,0 +1,7 @@ +--- + +- name: "run ldconfig" + command: "/sbin/ldconfig" + args: + creates: "/sbin/ldconfig" + become: True diff --git a/meta/main.yml b/meta/main.yml new file mode 100644 index 0000000..227ad9c --- /dev/null +++ b/meta/main.yml @@ -0,0 +1,53 @@ +galaxy_info: + author: your name + description: your role description + company: your company (optional) + + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + + # Choose a valid license ID from https://spdx.org - some suggested licenses: + # - BSD-3-Clause (default) + # - MIT + # - GPL-2.0-or-later + # - GPL-3.0-only + # - Apache-2.0 + # - CC-BY-4.0 + license: license (GPL-2.0-or-later, MIT, etc) + + min_ansible_version: 2.9 + + # If this a Container Enabled role, provide the minimum Ansible Container version. + # min_ansible_container_version: + + # + # Provide a list of supported platforms, and for each platform a list of versions. + # If you don't wish to enumerate all versions for a particular platform, use 'all'. + # To view available platforms and versions (or releases), visit: + # https://galaxy.ansible.com/api/v1/platforms/ + # + # platforms: + # - name: Fedora + # versions: + # - all + # - 25 + # - name: SomePlatform + # versions: + # - all + # - 1.0 + # - 7 + # - 99.99 + + galaxy_tags: [] + # List tags for your role here, one per line. A tag is a keyword that describes + # and categorizes the role. Users find roles by searching for tags. Be sure to + # remove the '[]' above, if you add tags to this list. + # + # NOTE: A tag is limited to a single word comprised of alphanumeric characters. + # Maximum 20 tags per role. + +dependencies: [] + # List your role dependencies here, one per line. Be sure to remove the '[]' above, + # if you add dependencies to this list. + \ No newline at end of file diff --git a/tasks/config.yaml b/tasks/config.yaml new file mode 100644 index 0000000..6a911d5 --- /dev/null +++ b/tasks/config.yaml @@ -0,0 +1,34 @@ +--- + +- name: ensure oracle instant client group exists + group: + state: present + name: "{{ oic_group }}" + gid: "{{ oic_group_id }}" + +- name: ensure oracle instant client user exists + user: + state: present + name: "{{ oic_user }}" + uid: "{{ oic_user_id }}" + group: "{{ oic_group }}" + +- name: ensure network/admin subdirectory exists + file: + path: "{{ oic_config_path }}" + state: directory + owner: root + group: root + +- name: update the $PATH variable for oracle binaries + copy: + dest: /etc/profile.d/custom-path.sh + content: 'PATH=$PATH:{{ oic_bin_path }}' + +- name: push tnsnames.ora + template: + src: tnsnames.ora.j2 + dest: "{{ oic_config_path }}/tnsnames.ora" + mode: 0655 + owner: "{{ oic_user }}" + group: "{{ oic_group }}" diff --git a/tasks/fetch.yaml b/tasks/fetch.yaml new file mode 100644 index 0000000..38fe410 --- /dev/null +++ b/tasks/fetch.yaml @@ -0,0 +1,8 @@ +--- + +- name: fetch oracle instant client artifacts + get_url: + url: "{{ oic_package_base_url }}/{{ item.pkg_name }}" + dest: "{{ oic_package_dest }}" + checksum: "{{ item.pkg_hash }}" + loop: "{{ oic_install_packages }}" diff --git a/tasks/install.yaml b/tasks/install.yaml new file mode 100644 index 0000000..c41773c --- /dev/null +++ b/tasks/install.yaml @@ -0,0 +1,21 @@ +--- + +- name: install dependencies + yum: + name: "{{ item }}" + state: present + loop: "{{ oic_dependencies }}" + +- name: install oracle instan client packages + yum: + name: "{{ oic_package_dest }}/{{ item.pkg_name }}" + state: present + loop: "{{ oic_install_packages }}" + +- name: make sure oracle client is in the library path + lineinfile: + dest: "/etc/ld.so.conf.d/oracle-instantclient.conf" + line: "{{ oic_ld_library_path }}" + insertbefore: "BOF" + create: True + notify: "run ldconfig" diff --git a/tasks/main.yaml b/tasks/main.yaml new file mode 100644 index 0000000..29ca418 --- /dev/null +++ b/tasks/main.yaml @@ -0,0 +1,24 @@ +--- + +- name: load variables based on distribution type + include_vars: '{{ item }}' + with_first_found: + - '{{ ansible_distribution }}_{{ ansible_distribution_major_version }}.yaml' + - '{{ ansible_os_family }}.yaml' + tags: + - 'oic_vars' + +- name: import fetching tasks + import_tasks: fetch.yaml + tags: + - 'oic_fetch' + +- name: import installation tasks + import_tasks: install.yaml + tags: + - 'oic_install' + +- name: impost configuration tasks + import_tasks: config.yaml + tags: + - 'oic_config' diff --git a/templates/tnsnames.ora.j2 b/templates/tnsnames.ora.j2 new file mode 100644 index 0000000..2617cb9 --- /dev/null +++ b/templates/tnsnames.ora.j2 @@ -0,0 +1,24 @@ +{% if oic_databases is defined %} +{% for db in oic_databases %} +{{ db.sid }} = + (DESCRIPTION = + (ADDRESS = + (PROTOCOL = TCP) + (HOST = {{ db.host }}) + (PORT = {{ db.port }}) + ) + (CONNECT_DATA= + (SERVICE_NAME={{ db.service_name }}) + ) + ) +{% endfor %} +{% endif %} + +{% if oic_listener_host is defined and oic_listener_port is defined %} +LISTENER = + (ADDRESS = + (PROTOCOL = TCP) + (HOST = {{ oic_listener_host }}) + (PORT = {{ oic_listener_port }}) + ) +{% endif %} diff --git a/tests/inventory b/tests/inventory new file mode 100644 index 0000000..878877b --- /dev/null +++ b/tests/inventory @@ -0,0 +1,2 @@ +localhost + diff --git a/tests/test.yml b/tests/test.yml new file mode 100644 index 0000000..97d63e0 --- /dev/null +++ b/tests/test.yml @@ -0,0 +1,5 @@ +--- +- hosts: localhost + remote_user: root + roles: + - ansible-role-oracleinstantclient diff --git a/vars/RedHat_7.yaml b/vars/RedHat_7.yaml new file mode 100644 index 0000000..20a42f1 --- /dev/null +++ b/vars/RedHat_7.yaml @@ -0,0 +1,4 @@ +--- + +oic_dependencies: + - libaio diff --git a/vars/RedHat_8.yaml b/vars/RedHat_8.yaml new file mode 100644 index 0000000..28fc75d --- /dev/null +++ b/vars/RedHat_8.yaml @@ -0,0 +1,7 @@ +--- + +# To install and use oracle instant client you'll need libnsl on rhel8 which is not listed as dependency. +# See: https://access.redhat.com/solutions/4975641 +oic_dependencies: + - libnsl + - libaio