From f6899ebe6abfefa27cee3e61d671a3240faa17da Mon Sep 17 00:00:00 2001 From: Jien Huang Date: Thu, 30 Nov 2023 09:53:47 +0000 Subject: [PATCH] Chrome (#8) * init * passed molecule test * add matrix * asserted --- .github/workflows/main.yml | 1 + .github/workflows/release.yml | 13 ++++++------ galaxy.yml | 2 +- molecule/chrome/converge.yml | 9 ++++++++ molecule/chrome/molecule.yml | 31 +++++++++++++++++++++++++++ molecule/chrome/verify.yml | 25 ++++++++++++++++++++++ roles/chrome/README.md | 39 ++++++++++++++++++++++++++++++++++ roles/chrome/defaults/main.yml | 4 ++++ roles/chrome/meta/main.yml | 39 ++++++++++++++++++++++++++++++++++ roles/chrome/tasks/main.yml | 34 +++++++++++++++++++++++++++++ 10 files changed, 189 insertions(+), 8 deletions(-) create mode 100644 molecule/chrome/converge.yml create mode 100644 molecule/chrome/molecule.yml create mode 100644 molecule/chrome/verify.yml create mode 100644 roles/chrome/README.md create mode 100644 roles/chrome/defaults/main.yml create mode 100644 roles/chrome/meta/main.yml create mode 100644 roles/chrome/tasks/main.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index da9b53c..3d75c5a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -30,6 +30,7 @@ jobs: - apache-ant - jfrog - nodejs + - chrome steps: - name: Checkout uses: actions/checkout@v2 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 6a84212..bb931e7 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -3,7 +3,7 @@ name: release # Controls when the workflow will run on: - # Triggers the workflow on push + # Triggers the workflow on push push: branches: [main] @@ -12,10 +12,9 @@ jobs: deploy: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - - name: Deploy the collection - uses: artis3n/ansible_galaxy_collection@v2 - with: - api_key: ${{ secrets.GALAXY_TOKEN }} + - uses: actions/checkout@v2 + - name: Deploy the collection + uses: artis3n/ansible_galaxy_collection@v2 + with: + api_key: ${{ secrets.GALAXY_TOKEN }} diff --git a/galaxy.yml b/galaxy.yml index 7f265f4..d8c63da 100644 --- a/galaxy.yml +++ b/galaxy.yml @@ -10,7 +10,7 @@ namespace: merative name: spm_toolbox # The version of the collection. Must be compatible with semantic versioning -version: 1.1.0 +version: 1.1.1 # The path to the Markdown (.md) readme file. This path is relative to the root of the collection readme: README.md diff --git a/molecule/chrome/converge.yml b/molecule/chrome/converge.yml new file mode 100644 index 0000000..fecfcd7 --- /dev/null +++ b/molecule/chrome/converge.yml @@ -0,0 +1,9 @@ +--- +- name: Converge + hosts: all + + collections: + - merative.spm_toolbox + + roles: + - chrome diff --git a/molecule/chrome/molecule.yml b/molecule/chrome/molecule.yml new file mode 100644 index 0000000..6f38516 --- /dev/null +++ b/molecule/chrome/molecule.yml @@ -0,0 +1,31 @@ +--- +driver: + name: docker + provider: + name: docker + +lint: | + set -e + yamllint . + +platforms: + - name: rockylinux8 + image: rockylinux:8 + dockerfile: ../_resources/Dockerfile.j2 + pre_build_image: False + privileged: True + volume_mounts: + - "/sys/fs/cgroup:/sys/fs/cgroup:rw" + command: "/usr/sbin/init" + environment: + container: docker + +provisioner: + name: ansible + log: true + config_options: + defaults: + stderr_callback: debug + stdout_callback: debug + env: + ANSIBLE_FORCE_COLOR: 'true' diff --git a/molecule/chrome/verify.yml b/molecule/chrome/verify.yml new file mode 100644 index 0000000..f194a7b --- /dev/null +++ b/molecule/chrome/verify.yml @@ -0,0 +1,25 @@ +--- +# This is an example playbook to execute Ansible tests. + +- name: Verify + hosts: all + + pre_tasks: + - name: Check if chrome installed + stat: + path: "/usr/bin/google-chrome" + register: chrome_check + + - name: Check if chromedriver installed + stat: + path: "/usr/local/chromedriver" + register: chromedriver_installed + + tasks: + - name: Check that chrome exists + assert: + that: chrome_check.stat.exists + + - name: Check chromedriver installed + assert: + that: chromedriver_installed.stat.exists diff --git a/roles/chrome/README.md b/roles/chrome/README.md new file mode 100644 index 0000000..4bccddd --- /dev/null +++ b/roles/chrome/README.md @@ -0,0 +1,39 @@ +# chrome + +The `chrome` role downloads chrome and chromedriver appropriate for the OS. + +## Requirements + +None + +## Role Variables + +| Property Name | Default value | +| ----------------- | ------------- | +| `chrome_owner` | `root` | +| `chrome_group` | `root` | + +The chrome always use `$latest` version for Linux platforms to download the latest available binary. + +## Dependencies + +None + +## Example Playbook + +``` +--- +- name: Install Chrome + hosts: all + + collections: + - merative.spm_toolbox + + roles: + - chrome + +``` + +## License + +MIT diff --git a/roles/chrome/defaults/main.yml b/roles/chrome/defaults/main.yml new file mode 100644 index 0000000..d5dc5b2 --- /dev/null +++ b/roles/chrome/defaults/main.yml @@ -0,0 +1,4 @@ +--- +chrome_owner: 'root' +chrome_group: 'root' +chromedriver_version: '114.0.5735.90' # https://chromedriver.storage.googleapis.com/114.0.5735.90/chromedriver_linux64.zip diff --git a/roles/chrome/meta/main.yml b/roles/chrome/meta/main.yml new file mode 100644 index 0000000..dd38fa0 --- /dev/null +++ b/roles/chrome/meta/main.yml @@ -0,0 +1,39 @@ +--- +galaxy_info: + author: SPM DevOps Team + description: Download Chrome and Chromedriver appropriate for the OS. + company: Merative + + # 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 + + license: MIT + + min_ansible_version: 2.9 + + # + # 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: EL + versions: + - '7' + - '8' + + 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. diff --git a/roles/chrome/tasks/main.yml b/roles/chrome/tasks/main.yml new file mode 100644 index 0000000..cc2068c --- /dev/null +++ b/roles/chrome/tasks/main.yml @@ -0,0 +1,34 @@ +--- +- name: Install required packages (wget) + package: + name: + - wget + state: latest + +- name: Download and Install Linux chromedriver + get_url: + url: "https://chromedriver.storage.googleapis.com/{{ chromedriver_version }}/chromedriver_linux64.zip" + dest: '/usr/local/chromedriver' + owner: "{{ chrome_owner }}" + group: "{{ chrome_group }}" + mode: '0755' + +- name: Install Chrome + become: yes + become_user: root + shell: | + wget https://dl.google.com/linux/linux_signing_key.pub + rpm --import linux_signing_key.pub + wget https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm + dnf -y install google-chrome-stable_current_x86_64.rpm + register: script_res + changed_when: "'changed' in script_res.stdout" + +- name: Remove installation files + file: + path: "{{ item }}" + state: absent + with_items: + - linux_signing_key.pub + - google-chrome-stable_current_x86_64.rpm + changed_when: false