1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00
community.general/tests/integration/targets/gem/tasks/main.yml

222 lines
6.1 KiB
YAML
Raw Normal View History

####################################################################
# WARNING: These are designed specifically for Ansible tests #
# and should not be used as examples of how to write Ansible roles #
####################################################################
2020-03-09 10:11:07 +01:00
# test code for the gem module
# (c) 2014, James Tanner <tanner.jc@gmail.com>
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
- include_vars: '{{ item }}'
with_first_found:
- files:
- '{{ ansible_distribution }}-{{ ansible_distribution_major_version }}.yml'
- '{{ ansible_distribution }}-{{ ansible_distribution_version }}.yml'
- '{{ ansible_os_family }}.yml'
- 'default.yml'
paths: '../vars'
- name: Install dependencies for test
package:
name: "{{ item }}"
state: present
loop: "{{ test_packages }}"
when: ansible_distribution != "MacOSX"
- name: Install a gem
gem:
name: gist
state: present
register: install_gem_result
ignore_errors: yes
# when running as root on Fedora, '--install-dir' is set in the os defaults which is
# incompatible with '--user-install', we ignore this error for this case only
- name: fail if failed to install gem
fail:
msg: "failed to install gem: {{ install_gem_result.msg }}"
when:
- install_gem_result is failed
- not (ansible_user_uid == 0 and "User --install-dir or --user-install but not both" not in install_gem_result.msg)
- block:
- name: List gems
command: gem list
register: current_gems
- name: Ensure gem was installed
assert:
that:
- install_gem_result is changed
- current_gems.stdout is search('gist\s+\([0-9.]+\)')
- name: Remove a gem
gem:
name: gist
state: absent
register: remove_gem_results
- name: List gems
command: gem list
register: current_gems
- name: Verify gem is not installed
assert:
that:
- remove_gem_results is changed
- current_gems.stdout is not search('gist\s+\([0-9.]+\)')
when: not install_gem_result is failed
# install gem in --no-user-install
- block:
- name: Install a gem with --no-user-install
gem:
name: gist
state: present
user_install: no
register: install_gem_result
- name: List gems
command: gem list
register: current_gems
- name: Ensure gem was installed
assert:
that:
- install_gem_result is changed
- current_gems.stdout is search('gist\s+\([0-9.]+\)')
- name: Remove a gem
gem:
name: gist
state: absent
register: remove_gem_results
- name: List gems
command: gem list
register: current_gems
- name: Verify gem is not installed
assert:
that:
- remove_gem_results is changed
- current_gems.stdout is not search('gist\s+\([0-9.]+\)')
when: ansible_user_uid == 0
# Check cutom gem directory
- name: Install gem in a custom directory with incorrect options
gem:
name: gist
state: present
install_dir: "{{ remote_tmp_dir }}/gems"
2020-03-09 10:11:07 +01:00
ignore_errors: yes
register: install_gem_fail_result
- debug:
var: install_gem_fail_result
tags: debug
- name: Ensure previous task failed
assert:
that:
- install_gem_fail_result is failed
- install_gem_fail_result.msg == 'install_dir requires user_install=false'
- name: Install a gem in a custom directory
gem:
name: gist
state: present
user_install: no
install_dir: "{{ remote_tmp_dir }}/gems"
2020-03-09 10:11:07 +01:00
register: install_gem_result
- name: Find gems in custom directory
find:
paths: "{{ remote_tmp_dir }}/gems/gems"
2020-03-09 10:11:07 +01:00
file_type: directory
contains: gist
register: gem_search
- name: Ensure gem was installed in custom directory
assert:
that:
- install_gem_result is changed
- gem_search.files[0].path is search('gist-[0-9.]+')
ignore_errors: yes
- name: Remove a gem in a custom directory
gem:
name: gist
state: absent
user_install: no
install_dir: "{{ remote_tmp_dir }}/gems"
2020-03-09 10:11:07 +01:00
register: install_gem_result
- name: Find gems in custom directory
find:
paths: "{{ remote_tmp_dir }}/gems/gems"
2020-03-09 10:11:07 +01:00
file_type: directory
contains: gist
register: gem_search
- name: Ensure gem was removed in custom directory
assert:
that:
- install_gem_result is changed
- gem_search.files | length == 0
gem_module: Add bindir option (#2837) (#2851) * gem_module: Add bindir option This option allows to specify directory to install executables, e.g. `/home/user/bin` or `/home/user/.local/bin`. This comes especially handy when used with user_install option as the default path of executables is not in PATH. * Update changelogs/fragments/gem_module_add_bindir_option.yml Co-authored-by: Ajpantuso <ajpantuso@gmail.com> * gem_module: Integration tests for bindir option * gem_module: Update Integration tests for bindir option * gem_module: Update Integration tests for bindir option Make sure gist is not installed system-wide prior the tests * Revert "gem_module: Update Integration tests for bindir option" This reverts commit 04eec6db27aa90d2b23ead7941aeb5889a7c6437. * Do not check "install_gem_result is changed" for ansible develop on openSUSE * Revert "Do not check "install_gem_result is changed" for ansible develop on openSUSE" This reverts commit 48ecb27889a6d86b91eb70a5b1432a5649846b99. * gem_module: Use --norc to avoid surprises Run install and uninstall actions with `--norc`. This way ansible has more control over the way gems are installed. * Revert "gem_module: Use --norc to avoid surprises" This reverts commit 66f40bcfe684ba306759a0fdc028a21ba73ba1dd. * gem_module: bindir - Ignore openSUSE Leap * Update plugins/modules/packaging/language/gem.py Co-authored-by: Felix Fontein <felix@fontein.de> * gem_module: Use --norc to avoid surprises Run install and uninstall actions with `--norc` when supported (rubygems >= 2.5.2). This way ansible has more control over the way gems are installed. * Try distutils.version instead of packaging * ver is an list, not string * ver is not list either but tuple * Update changelogs/fragments/gem_module_add_bindir_option.yml Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com> * ver can be None (when can this happen?) * gem: Add norc option * Apply suggestions from code review Co-authored-by: Felix Fontein <felix@fontein.de> * Update plugins/modules/packaging/language/gem.py Co-authored-by: Felix Fontein <felix@fontein.de> * Use tuples to compare versions * Apply suggestions from code review Co-authored-by: Amin Vakil <info@aminvakil.com> * Update plugins/modules/packaging/language/gem.py Co-authored-by: Amin Vakil <info@aminvakil.com> * lost norc option check is back * Move handling norc option to separate function * cosmetic * fix for the previos commit * Apply suggestions from code review Co-authored-by: Felix Fontein <felix@fontein.de> * Cache result of get_rubygems_version Co-authored-by: Ajpantuso <ajpantuso@gmail.com> Co-authored-by: Felix Fontein <felix@fontein.de> Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com> Co-authored-by: Amin Vakil <info@aminvakil.com> (cherry picked from commit ce35d8809474d2a1dee1f2cefd5416c491b97594) Co-authored-by: Stanislav German-Evtushenko <ginermail@gmail.com>
2021-06-21 12:41:40 +02:00
# Custom directory for executables (--bindir)
- name: Install gem with custom bindir
gem:
name: gist
state: present
bindir: "{{ remote_tmp_dir }}/custom_bindir"
gem_module: Add bindir option (#2837) (#2851) * gem_module: Add bindir option This option allows to specify directory to install executables, e.g. `/home/user/bin` or `/home/user/.local/bin`. This comes especially handy when used with user_install option as the default path of executables is not in PATH. * Update changelogs/fragments/gem_module_add_bindir_option.yml Co-authored-by: Ajpantuso <ajpantuso@gmail.com> * gem_module: Integration tests for bindir option * gem_module: Update Integration tests for bindir option * gem_module: Update Integration tests for bindir option Make sure gist is not installed system-wide prior the tests * Revert "gem_module: Update Integration tests for bindir option" This reverts commit 04eec6db27aa90d2b23ead7941aeb5889a7c6437. * Do not check "install_gem_result is changed" for ansible develop on openSUSE * Revert "Do not check "install_gem_result is changed" for ansible develop on openSUSE" This reverts commit 48ecb27889a6d86b91eb70a5b1432a5649846b99. * gem_module: Use --norc to avoid surprises Run install and uninstall actions with `--norc`. This way ansible has more control over the way gems are installed. * Revert "gem_module: Use --norc to avoid surprises" This reverts commit 66f40bcfe684ba306759a0fdc028a21ba73ba1dd. * gem_module: bindir - Ignore openSUSE Leap * Update plugins/modules/packaging/language/gem.py Co-authored-by: Felix Fontein <felix@fontein.de> * gem_module: Use --norc to avoid surprises Run install and uninstall actions with `--norc` when supported (rubygems >= 2.5.2). This way ansible has more control over the way gems are installed. * Try distutils.version instead of packaging * ver is an list, not string * ver is not list either but tuple * Update changelogs/fragments/gem_module_add_bindir_option.yml Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com> * ver can be None (when can this happen?) * gem: Add norc option * Apply suggestions from code review Co-authored-by: Felix Fontein <felix@fontein.de> * Update plugins/modules/packaging/language/gem.py Co-authored-by: Felix Fontein <felix@fontein.de> * Use tuples to compare versions * Apply suggestions from code review Co-authored-by: Amin Vakil <info@aminvakil.com> * Update plugins/modules/packaging/language/gem.py Co-authored-by: Amin Vakil <info@aminvakil.com> * lost norc option check is back * Move handling norc option to separate function * cosmetic * fix for the previos commit * Apply suggestions from code review Co-authored-by: Felix Fontein <felix@fontein.de> * Cache result of get_rubygems_version Co-authored-by: Ajpantuso <ajpantuso@gmail.com> Co-authored-by: Felix Fontein <felix@fontein.de> Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com> Co-authored-by: Amin Vakil <info@aminvakil.com> (cherry picked from commit ce35d8809474d2a1dee1f2cefd5416c491b97594) Co-authored-by: Stanislav German-Evtushenko <ginermail@gmail.com>
2021-06-21 12:41:40 +02:00
norc: yes
user_install: no # Avoid conflicts between --install-dir and --user-install when running as root on CentOS / Fedora / RHEL
register: install_gem_result
- name: Get stats of gem executable
stat:
path: "{{ remote_tmp_dir }}/custom_bindir/gist"
gem_module: Add bindir option (#2837) (#2851) * gem_module: Add bindir option This option allows to specify directory to install executables, e.g. `/home/user/bin` or `/home/user/.local/bin`. This comes especially handy when used with user_install option as the default path of executables is not in PATH. * Update changelogs/fragments/gem_module_add_bindir_option.yml Co-authored-by: Ajpantuso <ajpantuso@gmail.com> * gem_module: Integration tests for bindir option * gem_module: Update Integration tests for bindir option * gem_module: Update Integration tests for bindir option Make sure gist is not installed system-wide prior the tests * Revert "gem_module: Update Integration tests for bindir option" This reverts commit 04eec6db27aa90d2b23ead7941aeb5889a7c6437. * Do not check "install_gem_result is changed" for ansible develop on openSUSE * Revert "Do not check "install_gem_result is changed" for ansible develop on openSUSE" This reverts commit 48ecb27889a6d86b91eb70a5b1432a5649846b99. * gem_module: Use --norc to avoid surprises Run install and uninstall actions with `--norc`. This way ansible has more control over the way gems are installed. * Revert "gem_module: Use --norc to avoid surprises" This reverts commit 66f40bcfe684ba306759a0fdc028a21ba73ba1dd. * gem_module: bindir - Ignore openSUSE Leap * Update plugins/modules/packaging/language/gem.py Co-authored-by: Felix Fontein <felix@fontein.de> * gem_module: Use --norc to avoid surprises Run install and uninstall actions with `--norc` when supported (rubygems >= 2.5.2). This way ansible has more control over the way gems are installed. * Try distutils.version instead of packaging * ver is an list, not string * ver is not list either but tuple * Update changelogs/fragments/gem_module_add_bindir_option.yml Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com> * ver can be None (when can this happen?) * gem: Add norc option * Apply suggestions from code review Co-authored-by: Felix Fontein <felix@fontein.de> * Update plugins/modules/packaging/language/gem.py Co-authored-by: Felix Fontein <felix@fontein.de> * Use tuples to compare versions * Apply suggestions from code review Co-authored-by: Amin Vakil <info@aminvakil.com> * Update plugins/modules/packaging/language/gem.py Co-authored-by: Amin Vakil <info@aminvakil.com> * lost norc option check is back * Move handling norc option to separate function * cosmetic * fix for the previos commit * Apply suggestions from code review Co-authored-by: Felix Fontein <felix@fontein.de> * Cache result of get_rubygems_version Co-authored-by: Ajpantuso <ajpantuso@gmail.com> Co-authored-by: Felix Fontein <felix@fontein.de> Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com> Co-authored-by: Amin Vakil <info@aminvakil.com> (cherry picked from commit ce35d8809474d2a1dee1f2cefd5416c491b97594) Co-authored-by: Stanislav German-Evtushenko <ginermail@gmail.com>
2021-06-21 12:41:40 +02:00
register: gem_bindir_stat
- name: Ensure gem executable was installed in custom directory
assert:
that:
- install_gem_result is changed
- gem_bindir_stat.stat.exists and gem_bindir_stat.stat.isreg
- name: Remove gem with custom bindir
gem:
name: gist
state: absent
bindir: "{{ remote_tmp_dir }}/custom_bindir"
gem_module: Add bindir option (#2837) (#2851) * gem_module: Add bindir option This option allows to specify directory to install executables, e.g. `/home/user/bin` or `/home/user/.local/bin`. This comes especially handy when used with user_install option as the default path of executables is not in PATH. * Update changelogs/fragments/gem_module_add_bindir_option.yml Co-authored-by: Ajpantuso <ajpantuso@gmail.com> * gem_module: Integration tests for bindir option * gem_module: Update Integration tests for bindir option * gem_module: Update Integration tests for bindir option Make sure gist is not installed system-wide prior the tests * Revert "gem_module: Update Integration tests for bindir option" This reverts commit 04eec6db27aa90d2b23ead7941aeb5889a7c6437. * Do not check "install_gem_result is changed" for ansible develop on openSUSE * Revert "Do not check "install_gem_result is changed" for ansible develop on openSUSE" This reverts commit 48ecb27889a6d86b91eb70a5b1432a5649846b99. * gem_module: Use --norc to avoid surprises Run install and uninstall actions with `--norc`. This way ansible has more control over the way gems are installed. * Revert "gem_module: Use --norc to avoid surprises" This reverts commit 66f40bcfe684ba306759a0fdc028a21ba73ba1dd. * gem_module: bindir - Ignore openSUSE Leap * Update plugins/modules/packaging/language/gem.py Co-authored-by: Felix Fontein <felix@fontein.de> * gem_module: Use --norc to avoid surprises Run install and uninstall actions with `--norc` when supported (rubygems >= 2.5.2). This way ansible has more control over the way gems are installed. * Try distutils.version instead of packaging * ver is an list, not string * ver is not list either but tuple * Update changelogs/fragments/gem_module_add_bindir_option.yml Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com> * ver can be None (when can this happen?) * gem: Add norc option * Apply suggestions from code review Co-authored-by: Felix Fontein <felix@fontein.de> * Update plugins/modules/packaging/language/gem.py Co-authored-by: Felix Fontein <felix@fontein.de> * Use tuples to compare versions * Apply suggestions from code review Co-authored-by: Amin Vakil <info@aminvakil.com> * Update plugins/modules/packaging/language/gem.py Co-authored-by: Amin Vakil <info@aminvakil.com> * lost norc option check is back * Move handling norc option to separate function * cosmetic * fix for the previos commit * Apply suggestions from code review Co-authored-by: Felix Fontein <felix@fontein.de> * Cache result of get_rubygems_version Co-authored-by: Ajpantuso <ajpantuso@gmail.com> Co-authored-by: Felix Fontein <felix@fontein.de> Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com> Co-authored-by: Amin Vakil <info@aminvakil.com> (cherry picked from commit ce35d8809474d2a1dee1f2cefd5416c491b97594) Co-authored-by: Stanislav German-Evtushenko <ginermail@gmail.com>
2021-06-21 12:41:40 +02:00
norc: yes
user_install: no # Avoid conflicts between --install-dir and --user-install when running as root on CentOS / Fedora / RHEL
register: install_gem_result
- name: Get stats of gem executable
stat:
path: "{{ remote_tmp_dir }}/custom_bindir/gist"
gem_module: Add bindir option (#2837) (#2851) * gem_module: Add bindir option This option allows to specify directory to install executables, e.g. `/home/user/bin` or `/home/user/.local/bin`. This comes especially handy when used with user_install option as the default path of executables is not in PATH. * Update changelogs/fragments/gem_module_add_bindir_option.yml Co-authored-by: Ajpantuso <ajpantuso@gmail.com> * gem_module: Integration tests for bindir option * gem_module: Update Integration tests for bindir option * gem_module: Update Integration tests for bindir option Make sure gist is not installed system-wide prior the tests * Revert "gem_module: Update Integration tests for bindir option" This reverts commit 04eec6db27aa90d2b23ead7941aeb5889a7c6437. * Do not check "install_gem_result is changed" for ansible develop on openSUSE * Revert "Do not check "install_gem_result is changed" for ansible develop on openSUSE" This reverts commit 48ecb27889a6d86b91eb70a5b1432a5649846b99. * gem_module: Use --norc to avoid surprises Run install and uninstall actions with `--norc`. This way ansible has more control over the way gems are installed. * Revert "gem_module: Use --norc to avoid surprises" This reverts commit 66f40bcfe684ba306759a0fdc028a21ba73ba1dd. * gem_module: bindir - Ignore openSUSE Leap * Update plugins/modules/packaging/language/gem.py Co-authored-by: Felix Fontein <felix@fontein.de> * gem_module: Use --norc to avoid surprises Run install and uninstall actions with `--norc` when supported (rubygems >= 2.5.2). This way ansible has more control over the way gems are installed. * Try distutils.version instead of packaging * ver is an list, not string * ver is not list either but tuple * Update changelogs/fragments/gem_module_add_bindir_option.yml Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com> * ver can be None (when can this happen?) * gem: Add norc option * Apply suggestions from code review Co-authored-by: Felix Fontein <felix@fontein.de> * Update plugins/modules/packaging/language/gem.py Co-authored-by: Felix Fontein <felix@fontein.de> * Use tuples to compare versions * Apply suggestions from code review Co-authored-by: Amin Vakil <info@aminvakil.com> * Update plugins/modules/packaging/language/gem.py Co-authored-by: Amin Vakil <info@aminvakil.com> * lost norc option check is back * Move handling norc option to separate function * cosmetic * fix for the previos commit * Apply suggestions from code review Co-authored-by: Felix Fontein <felix@fontein.de> * Cache result of get_rubygems_version Co-authored-by: Ajpantuso <ajpantuso@gmail.com> Co-authored-by: Felix Fontein <felix@fontein.de> Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com> Co-authored-by: Amin Vakil <info@aminvakil.com> (cherry picked from commit ce35d8809474d2a1dee1f2cefd5416c491b97594) Co-authored-by: Stanislav German-Evtushenko <ginermail@gmail.com>
2021-06-21 12:41:40 +02:00
register: gem_bindir_stat
- name: Ensure gem executable was removed from custom directory
assert:
that:
- install_gem_result is changed
- not gem_bindir_stat.stat.exists