commit ef6e10728d1a154e1e3e251691a9af294f63daff Author: Gary Kwok Date: Mon Jan 29 17:53:04 2024 +0800 v1 diff --git a/deploy_kernelcare.yml b/deploy_kernelcare.yml new file mode 100644 index 0000000..4bef0d8 --- /dev/null +++ b/deploy_kernelcare.yml @@ -0,0 +1,7 @@ +--- + +- hosts: "{{ inputHostsGroups }}" + gather_facts: false + become: yes + roles: + - kernelcare \ No newline at end of file diff --git a/hello.yml b/hello.yml new file mode 100644 index 0000000..96ac0d8 --- /dev/null +++ b/hello.yml @@ -0,0 +1,8 @@ +--- +- name: This is a hello-world example + hosts: "{{ inputHosts }}" + tasks: + - name: Create a file called '/tmp/testfile.txt' with the content 'hello world'. + copy: + content: hello world + dest: /tmp/testfile.txt \ No newline at end of file diff --git a/kernelcare_agent_uninstall.yml b/kernelcare_agent_uninstall.yml new file mode 100644 index 0000000..48579d6 --- /dev/null +++ b/kernelcare_agent_uninstall.yml @@ -0,0 +1,13 @@ +- hosts: "{{ inputHosts }}" + become: yes + tasks: + - name: unregister KernelCare agents + command: /usr/bin/kcarectl --unregister + ignore_errors: yes + args: + removes: /usr/bin/kcarectl + + - name: remove kernelcare package + package: + name: kernelcare + state: absent \ No newline at end of file diff --git a/kernelcare_dev_agent_install.yml b/kernelcare_dev_agent_install.yml new file mode 100644 index 0000000..b662574 --- /dev/null +++ b/kernelcare_dev_agent_install.yml @@ -0,0 +1,26 @@ +- hosts: "{{ inputHosts }}" + become: yes + vars: + eportal_srv: "{{ eportal_srv }}" + activation_key: "{{ activation_key }}" + tasks: + - name: Download the installation shell script + get_url: + url: "{{ eportal_srv }}/install-kernelcare" + dest: /tmp/kc-install.sh + mode: '0700' + + - name: Run the installation shell script + command: /tmp/kc-install.sh + + - name: register KernelCare agents + command: /usr/bin/kcarectl --register {{ activation_key }} + + - name: tagging + command: /usr/bin/kcarectl --tag "product:scc;env:dev" + +# - name: Start and enable kcare +# service: +# name: kcare +# state: started +# enabled: yes \ No newline at end of file diff --git a/roles/kernelcare/README.md b/roles/kernelcare/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/roles/kernelcare/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/roles/kernelcare/defaults/main.yml b/roles/kernelcare/defaults/main.yml new file mode 100644 index 0000000..3cb46a8 --- /dev/null +++ b/roles/kernelcare/defaults/main.yml @@ -0,0 +1,15 @@ +--- +# defaults file for kcare + +# Gather facts fliter (for faster) +# Only use needed facts +gfacts_fliter: + - "!all" + - distribution + - distribution_major_version + - distribution_release + - distribution_version + - os_family + - pkg_mgr + - python + - python_version \ No newline at end of file diff --git a/roles/kernelcare/files/kernelcare-2.66-1.el7.x86_64.rpm b/roles/kernelcare/files/kernelcare-2.66-1.el7.x86_64.rpm new file mode 100644 index 0000000..111d322 Binary files /dev/null and b/roles/kernelcare/files/kernelcare-2.66-1.el7.x86_64.rpm differ diff --git a/roles/kernelcare/files/pyOpenSSL-0.13.1-4.el7.x86_64.rpm b/roles/kernelcare/files/pyOpenSSL-0.13.1-4.el7.x86_64.rpm new file mode 100644 index 0000000..bfc4005 Binary files /dev/null and b/roles/kernelcare/files/pyOpenSSL-0.13.1-4.el7.x86_64.rpm differ diff --git a/roles/kernelcare/handlers/main.yml b/roles/kernelcare/handlers/main.yml new file mode 100644 index 0000000..e82eee5 --- /dev/null +++ b/roles/kernelcare/handlers/main.yml @@ -0,0 +1,25 @@ +--- +# handlers file for kernelcare + +- name: "Start KernelCare agent" + service: + name: kcare + state: started + enabled: yes + +- name: "Restart KernelCare agent" + service: + name: kcare + state: restarted + +- name: "Disable libcare.socket" + service: + name: libcare.socket + state: stopped + enabled: no + +- name: "Disable libcare.service" + service: + name: libcare.service + state: stopped + enabled: no \ No newline at end of file diff --git a/roles/kernelcare/meta/main.yml b/roles/kernelcare/meta/main.yml new file mode 100644 index 0000000..227ad9c --- /dev/null +++ b/roles/kernelcare/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/roles/kernelcare/tasks/housekeep_log.yml b/roles/kernelcare/tasks/housekeep_log.yml new file mode 100644 index 0000000..f2e35ec --- /dev/null +++ b/roles/kernelcare/tasks/housekeep_log.yml @@ -0,0 +1,10 @@ +--- +# tasks file for kernalcare + +- name: Housekeeping kcare log file or directory + ansible.builtin.file: + path: "{{ item }}" + state: absent + loop: + - /var/log/kcarectl.log + - /var/log/libcare diff --git a/roles/kernelcare/tasks/install_CentOS.yml b/roles/kernelcare/tasks/install_CentOS.yml new file mode 100644 index 0000000..d3a9620 --- /dev/null +++ b/roles/kernelcare/tasks/install_CentOS.yml @@ -0,0 +1,71 @@ +--- +# tasks file for kernalcare + +- block: + - name: Include site environment + include_vars: "{{ ansEnv }}.yml" + + - include_tasks: housekeep_log.yml + + - name: Remove packages if exists + ansible.builtin.yum: + name: "{{ item }}" + state: absent + loop: + - kernelcare + - pyOpenSSL + + - name: Download the installation shell script + ansible.builtin.get_url: + url: "{{ eportal_srv }}/install-kernelcare" + dest: /tmp/kc-install.sh + mode: '0700' + validate_certs: false + register: kc_downloadresult + + - block: + - name: Copy RPM files to target host + ansible.builtin.copy: + src: "{{ item }}" + dest: /root/ + owner: root + group: root + mode: '0755' + loop: + - kernelcare-2.66-1.el7.x86_64.rpm + - pyOpenSSL-0.13.1-4.el7.x86_64.rpm + + - name: "Customized the install script for offline install" + ansible.builtin.lineinfile: + dest: "/tmp/kc-install.sh" + regexp: "{{ item.regexp | default(omit) }}" + line: "{{ item.line }}" + insertafter: "{{ item.insertafter | default(omit) }}" + insertbefore: "{{ item.insertbefore | default(omit) }}" + state: "{{ item.state | default('present') }}" + loop: + - line: 'curl -s "$eportal_url/installer" | bash' + state: absent + - line: | + #curl -s "$eportal_url/installer" | bash + curl -L "$eportal_url/installer" -o /tmp/kc-installer.sh + sed -i 's/^PACKAGE_NAME=\${KCARE_PACKAGE_NAME:-\"kernelcare\"}/PACKAGE_NAME=\"\/root\/kernelcare-2.66-1.el7.x86_64.rpm \/root\/pyOpenSSL-0.13.1-4.el7.x86_64.rpm\"/g' /tmp/kc-installer.sh + bash /tmp/kc-installer.sh + + insertbefore: "^echo \"Updating kernelcare repo...\"" + + when: downloadMode == "offline" + + - name: Run the installation shell script + ansible.builtin.shell: /tmp/kc-install.sh + register: kc_execresult + + - name: register KernelCare agents + ansible.builtin.shell: /usr/bin/kcarectl --register "{{ activation_key }}" --tag "{{ kernelcare_tagname }}" + when: kc_execresult.changed + notify: + - "Start KernelCare agent" + - "Disable libcare.socket" + - "Disable libcare.service" + + when: ansible_distribution == "CentOS" and ansible_distribution_major_version == "7" diff --git a/roles/kernelcare/tasks/main.yml b/roles/kernelcare/tasks/main.yml new file mode 100644 index 0000000..5bdf487 --- /dev/null +++ b/roles/kernelcare/tasks/main.yml @@ -0,0 +1,21 @@ +--- +# tasks file for kernalcare + +- name: Gather facts + ansible.builtin.setup: + gather_subset: "{{ gfacts_fliter }}" + +- block: + - name: "Trigger install task if selected option is install" + include_tasks: install_CentOS.yml + when: ansOption == "install" + + - name: "Trigger uninstall task if selected option is uninstall" + include_tasks: uninstall_CentOS.yml + when: ansOption == "uninstall" + + - name: "Trigger update HTTPS task if selected option is update_https" + include_tasks: updateHTTPS_CentOS.yml + when: ansOption == "update_https" + + when: ansible_distribution == "CentOS" and ansible_distribution_major_version == "7" \ No newline at end of file diff --git a/roles/kernelcare/tasks/uninstall_CentOS.yml b/roles/kernelcare/tasks/uninstall_CentOS.yml new file mode 100644 index 0000000..63aa65d --- /dev/null +++ b/roles/kernelcare/tasks/uninstall_CentOS.yml @@ -0,0 +1,20 @@ +--- +# tasks file for kernalcare + +- block: + - name: unregister KernelCare agents + ansible.builtin.command: /usr/bin/kcarectl --unregister + ignore_errors: yes + args: + removes: /usr/bin/kcarectl + + - name: remove kernelcare package + ansible.builtin.package: + name: + - kernelcare + - libcare + state: absent + + - include_tasks: housekeep_log.yml + + when: ansible_distribution == "CentOS" and ansible_distribution_major_version == "7" \ No newline at end of file diff --git a/roles/kernelcare/tasks/updateHTTPS_CentOS.yml b/roles/kernelcare/tasks/updateHTTPS_CentOS.yml new file mode 100644 index 0000000..4276880 --- /dev/null +++ b/roles/kernelcare/tasks/updateHTTPS_CentOS.yml @@ -0,0 +1,43 @@ +--- +# tasks file for kernalcare +# Update from HTTP to HTTPS + +- block: + - name: "Check /etc/sysconfig/kcare/kcare.conf if exists" + ansible.builtin.stat: + path: "/etc/sysconfig/kcare/kcare.conf" + register: result_config + + - name: "Update to HTTPS in /etc/sysconfig/kcare/kcare.conf" + ansible.builtin.replace: + path: "/etc/sysconfig/kcare/kcare.conf" + regexp: "{{ item.regexp | default(omit) }}" + replace: "{{ item.replace | default(omit) }}" + loop: + - regexp: "^PATCH_SERVER=http" + replace: "PATCH_SERVER=https" + - regexp: "^REGISTRATION_URL=http" + replace: "REGISTRATION_URL=https" + notify: + - "Restart KernelCare agent" + when: result_config.stat.exists + + + - name: "Check /etc/yum.repos.d/kernelcare.repo if exists" + ansible.builtin.stat: + path: "/etc/yum.repos.d/kernelcare.repo" + register: result_yumrepo + + - name: "Update to HTTPS in /etc/yum.repos.d/kernelcare.repo" + ansible.builtin.replace: + path: "/etc/yum.repos.d/kernelcare.repo" + regexp: "{{ item.regexp | default(omit) }}" + replace: "{{ item.replace | default(omit) }}" + loop: + - regexp: "^baseurl=http" + replace: "baseurl=https" + - regexp: "^gpgkey=http" + replace: "gpgkey=https" + when: result_yumrepo.stat.exists + + when: ansible_distribution == "CentOS" and ansible_distribution_major_version == "7" \ No newline at end of file diff --git a/roles/kernelcare/templates/kc-install.j2 b/roles/kernelcare/templates/kc-install.j2 new file mode 100644 index 0000000..401ad3c --- /dev/null +++ b/roles/kernelcare/templates/kc-install.j2 @@ -0,0 +1,18 @@ +#!/bin/bash +set -e -o pipefail +eportal_url="{{ eportal_srv }}" + +hash curl + +export KCARE_REPO="$eportal_url/repo" +export KCARE_PATCH_SERVER="$eportal_url" +export KCARE_REGISTRATION_URL="$eportal_url/admin/api/kcare" + +#curl -s "$eportal_url/installer" | bash +curl -L "$eportal_url/installer" -o /tmp/kc-installer.sh +sed -i 's/^PACKAGE_NAME=\${KCARE_PACKAGE_NAME:-\"kernelcare\"}/PACKAGE_NAME=\"\/root\/kernelcare-2.66-1.el7.x86_64.rpm \/root\/pyOpenSSL-0.13.1-4.el7.x86_64.rpm\"/g' /tmp/kc-installer.sh +bash /tmp/kc-installer.sh + +echo "Updating kernelcare repo..." +curl -s "$eportal_url/set-kernelcare-repo" | bash +echo "Done." \ No newline at end of file diff --git a/roles/kernelcare/tests/inventory b/roles/kernelcare/tests/inventory new file mode 100644 index 0000000..878877b --- /dev/null +++ b/roles/kernelcare/tests/inventory @@ -0,0 +1,2 @@ +localhost + diff --git a/roles/kernelcare/tests/test.yml b/roles/kernelcare/tests/test.yml new file mode 100644 index 0000000..15c6854 --- /dev/null +++ b/roles/kernelcare/tests/test.yml @@ -0,0 +1,5 @@ +--- +- hosts: localhost + remote_user: root + roles: + - trunk \ No newline at end of file diff --git a/roles/kernelcare/vars/hk_prd.yml b/roles/kernelcare/vars/hk_prd.yml new file mode 100644 index 0000000..24d35a9 --- /dev/null +++ b/roles/kernelcare/vars/hk_prd.yml @@ -0,0 +1,7 @@ +--- +# vars file for Hong Kong UAT + +eportal_srv: "http://kcareprd.ecvision.com" +activation_key: "arprdkcarekey-scc" +kernelcare_tagname: "product:scc;env:prd" + diff --git a/roles/kernelcare/vars/hk_uat.yml b/roles/kernelcare/vars/hk_uat.yml new file mode 100644 index 0000000..6e920a8 --- /dev/null +++ b/roles/kernelcare/vars/hk_uat.yml @@ -0,0 +1,7 @@ +--- +# vars file for Hong Kong UAT + +eportal_srv: "http://kcareuat.ecvision.com" +activation_key: "aruatkcarekey-scc" +kernelcare_tagname: "product:scc;env:uat" + diff --git a/roles/kernelcare/vars/main.yml b/roles/kernelcare/vars/main.yml new file mode 100644 index 0000000..b02166b --- /dev/null +++ b/roles/kernelcare/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for trunk \ No newline at end of file diff --git a/roles/kernelcare/vars/office_dev.yml b/roles/kernelcare/vars/office_dev.yml new file mode 100644 index 0000000..faef187 --- /dev/null +++ b/roles/kernelcare/vars/office_dev.yml @@ -0,0 +1,6 @@ +--- +# vars file for HK Office + +eportal_srv: "http://kcaredev.ecvision.com" +activation_key: "ardevkcarekey-scc" +kernelcare_tagname: "product:scc;env:dev" \ No newline at end of file diff --git a/roles/kernelcare/vars/svl_stg.yml b/roles/kernelcare/vars/svl_stg.yml new file mode 100644 index 0000000..a129f51 --- /dev/null +++ b/roles/kernelcare/vars/svl_stg.yml @@ -0,0 +1,6 @@ +--- +# vars file for Sunnyvale Staging (usdc4uat) + +eportal_srv: "http://10.204.2.107" +activation_key: "aruatkcarekey-scc" +kernelcare_tagname: "product:scc;env:uat" \ No newline at end of file diff --git a/roles/kernelcare/vars/svl_uat.yml b/roles/kernelcare/vars/svl_uat.yml new file mode 100644 index 0000000..452a244 --- /dev/null +++ b/roles/kernelcare/vars/svl_uat.yml @@ -0,0 +1,6 @@ +--- +# vars file for Sunnyvale UAT (usdc1uat) + +eportal_srv: "http://10.204.2.107" +activation_key: "aruatkcarekey-scc" +kernelcare_tagname: "product:scc;env:uat" \ No newline at end of file