Skip to content

Instantly share code, notes, and snippets.

@marvinpinto
Last active October 4, 2015 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marvinpinto/326f3f3750fac1121cf4 to your computer and use it in GitHub Desktop.
Save marvinpinto/326f3f3750fac1121cf4 to your computer and use it in GitHub Desktop.
Testing for Ansible RPM downgrading
FROM centos:6
COPY ./test_ansible.sh /
COPY ./test_playbook.yml /
RUN yum install -y \
https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm \
http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm \
git
RUN yum install -y ansible
CMD /test_ansible.sh
all: run
build:
docker build --rm -t ansibletest .
run: build
docker run -t ansibletest
PLAY [all] ********************************************************************
TASK: [Install the latest version of subversion] ******************************
changed: [localhost]
TASK: [Ensure that A version of subversion is installed] **********************
ok: [localhost]
TASK: [Install version 1.6.11-15.el6_7 of subversion] *************************
ok: [localhost]
TASK: [shell rpm -q subversion] ***********************************************
changed: [localhost]
TASK: [Ensure that version 1.6.11-15.el6_7 is actually installed] *************
ok: [localhost]
TASK: [Downgrade the subversion version to 1.6.11-14.el6] *********************
changed: [localhost]
TASK: [shell rpm -q subversion] ***********************************************
changed: [localhost]
TASK: [Ensure that version 1.6.11-14.el6 is actually installed] ***************
ok: [localhost]
TASK: [Ensure that A version of subversion is installed] **********************
ok: [localhost]
TASK: [Install the latest version of subversion] ******************************
changed: [localhost]
TASK: [Install the latest version of python-requests] *************************
changed: [localhost]
TASK: [Ensure that A version of python-requests is installed] *****************
ok: [localhost]
TASK: [Install version 2.6.0-3.el6 of python-requests] ************************
ok: [localhost]
TASK: [shell rpm -q python-requests] ******************************************
changed: [localhost]
TASK: [Ensure that version 2.6.0-3.el6 is actually installed] *****************
ok: [localhost]
TASK: [Downgrade the python-requests version to 1.1.0-4.el6.centos] ***********
changed: [localhost]
TASK: [shell rpm -q python-requests] ******************************************
changed: [localhost]
TASK: [Ensure that version 1.1.0-4.el6.centos is actually installed] **********
ok: [localhost]
TASK: [Ensure that A version of python-requests is installed] *****************
ok: [localhost]
TASK: [Install the latest version of python-requests] *************************
changed: [localhost]
TASK: [Install the latest version of ganglia-gmond-python] ********************
changed: [localhost]
TASK: [Ensure that A version of ganglia-gmond-python is installed] ************
ok: [localhost]
TASK: [Install version 3.7.1-2.el6 of ganglia-gmond-python] *******************
ok: [localhost]
TASK: [shell rpm -q ganglia-gmond-python] *************************************
changed: [localhost]
TASK: [Ensure that version 3.7.1-2.el6 is actually installed] *****************
ok: [localhost]
TASK: [Downgrade the ganglia-gmond-python version to 3.1.7-3.el6.rf] **********
changed: [localhost]
TASK: [shell rpm -q ganglia-gmond-python] *************************************
changed: [localhost]
TASK: [Ensure that version 3.1.7-3.el6.rf is actually installed] **************
ok: [localhost]
TASK: [Ensure that A version of ganglia-gmond-python is installed] ************
ok: [localhost]
TASK: [Install the latest version of ganglia-gmond-python] ********************
changed: [localhost]
TASK: [Install the newest available versions of subversion, python-requests, and ganglia-gmond-python] ***
ok: [localhost] => (item=subversion-1.6.11-15.el6_7,python-requests-2.6.0-3.el6,ganglia-gmond-python-3.7.1-2.el6)
TASK: [shell rpm -q subversion] ***********************************************
changed: [localhost]
TASK: [Ensure that version 1.6.11-15.el6_7 of subversion is actually installed] ***
ok: [localhost]
TASK: [shell rpm -q python-requests] ******************************************
changed: [localhost]
TASK: [Ensure that version 2.6.0-3.el6 of python-requests is actually installed] ***
ok: [localhost]
TASK: [shell rpm -q ganglia-gmond-python] *************************************
changed: [localhost]
TASK: [Ensure that version 3.7.1-2.el6 of ganglia-gmond-python is actually installed] ***
ok: [localhost]
TASK: [Demonstrate that downgrading does not work for lists of packages] ******
ok: [localhost] => (item=subversion-1.6.11-14.el6,python-requests-1.1.0-4.el6.centos,ganglia-gmond-python-3.1.7-3.el6.rf)
TASK: [shell rpm -q subversion] ***********************************************
changed: [localhost]
TASK: [Ensure that version 1.6.11-15.el6_7 of subversion is actually installed] ***
ok: [localhost]
TASK: [shell rpm -q python-requests] ******************************************
changed: [localhost]
TASK: [Ensure that version 2.6.0-3.el6 of python-requests is actually installed] ***
ok: [localhost]
TASK: [shell rpm -q ganglia-gmond-python] *************************************
changed: [localhost]
TASK: [Ensure that version 3.7.1-2.el6 of ganglia-gmond-python is actually installed] ***
ok: [localhost]
PLAY RECAP ********************************************************************
localhost : ok=44 changed=21 unreachable=0 failed=0
#!/bin/bash
rm -rf /tmp/ansible-modules-core
cd /tmp
git clone https://github.com/marvinpinto/ansible-modules-core.git
cd ansible-modules-core
git checkout -f origin/allow-rpm-downgrading
# Delete all the other modules I'm not working on
rm -rf cloud
rm -rf commands
rm -rf database
rm -rf files
rm -rf inventory
rm -rf network
rm -rf source_control
rm -rf system
rm -rf utilities
rm -rf web_infrastructure
rm -rf windows
rm -rf packaging/language
rm -rf packaging/os/apt*
rm -rf packaging/os/package.py
rm -rf packaging/os/rhn*
rm -rf packaging/os/redhat*
rm -rf packaging/os/rpm*
cd /tmp
echo "localhost ansible_connection=local" > /hosts.ini
export ANSIBLE_LIBRARY=/tmp/ansible-modules-core
ansible-playbook -i /hosts.ini /test_playbook.yml
---
- hosts: all
gather_facts: no
tasks:
#######################################
# Testing using the subversion package
#######################################
- name: 'Install the latest version of subversion'
yum: name="subversion" state=latest
- name: 'Ensure that A version of subversion is installed'
yum: name="subversion" state=present
- name: 'Install version 1.6.11-15.el6_7 of subversion'
yum: name="subversion-1.6.11-15.el6_7" state=installed
- shell: 'rpm -q subversion'
register: query_result
- name: 'Ensure that version 1.6.11-15.el6_7 is actually installed'
assert:
that:
- "'1.6.11-15.el6_7' in query_result.stdout"
- name: 'Downgrade the subversion version to 1.6.11-14.el6'
yum: name="subversion-1.6.11-14.el6" state=installed
- shell: 'rpm -q subversion'
register: query_result
- name: 'Ensure that version 1.6.11-14.el6 is actually installed'
assert:
that:
- "'1.6.11-14.el6' in query_result.stdout"
- name: 'Ensure that A version of subversion is installed'
yum: name="subversion" state=present
- name: 'Install the latest version of subversion'
yum: name="subversion" state=latest
############################################
# Testing using the python-requests package
############################################
- name: 'Install the latest version of python-requests'
yum: name="python-requests" state=latest
- name: 'Ensure that A version of python-requests is installed'
yum: name="python-requests" state=present
- name: 'Install version 2.6.0-3.el6 of python-requests'
yum: name="python-requests-2.6.0-3.el6" state=installed
- shell: 'rpm -q python-requests'
register: query_result
- name: 'Ensure that version 2.6.0-3.el6 is actually installed'
assert:
that:
- "'2.6.0-3.el6' in query_result.stdout"
- name: 'Downgrade the python-requests version to 1.1.0-4.el6.centos'
yum: name="python-requests-1.1.0-4.el6.centos" state=installed
- shell: 'rpm -q python-requests'
register: query_result
- name: 'Ensure that version 1.1.0-4.el6.centos is actually installed'
assert:
that:
- "'1.1.0-4.el6.centos' in query_result.stdout"
- name: 'Ensure that A version of python-requests is installed'
yum: name="python-requests" state=present
- name: 'Install the latest version of python-requests'
yum: name="python-requests" state=latest
#################################################
# Testing using the ganglia-gmond-python package
#################################################
- name: 'Install the latest version of ganglia-gmond-python'
yum: name="ganglia-gmond-python" state=latest
- name: 'Ensure that A version of ganglia-gmond-python is installed'
yum: name="ganglia-gmond-python" state=present
- name: 'Install version 3.7.1-2.el6 of ganglia-gmond-python'
yum: name="ganglia-gmond-python-3.7.1-2.el6" state=installed
- shell: 'rpm -q ganglia-gmond-python'
register: query_result
- name: 'Ensure that version 3.7.1-2.el6 is actually installed'
assert:
that:
- "'3.7.1-2.el6' in query_result.stdout"
- name: 'Downgrade the ganglia-gmond-python version to 3.1.7-3.el6.rf'
yum: name="ganglia-gmond-python-3.1.7-3.el6.rf" state=installed
- shell: 'rpm -q ganglia-gmond-python'
register: query_result
- name: 'Ensure that version 3.1.7-3.el6.rf is actually installed'
assert:
that:
- "'3.1.7-3.el6.rf' in query_result.stdout"
- name: 'Ensure that A version of ganglia-gmond-python is installed'
yum: name="ganglia-gmond-python" state=present
- name: 'Install the latest version of ganglia-gmond-python'
yum: name="ganglia-gmond-python" state=latest
##############################
# Multiple package-list tests
##############################
- name: 'Install the newest available versions of subversion, python-requests, and ganglia-gmond-python'
yum:
name: "{{ item }}"
state: installed
with_items:
- "subversion-1.6.11-15.el6_7"
- "python-requests-2.6.0-3.el6"
- "ganglia-gmond-python-3.7.1-2.el6"
- shell: 'rpm -q subversion'
register: query_result
- name: 'Ensure that version 1.6.11-15.el6_7 of subversion is actually installed'
assert:
that:
- "'1.6.11-15.el6_7' in query_result.stdout"
- shell: 'rpm -q python-requests'
register: query_result
- name: 'Ensure that version 2.6.0-3.el6 of python-requests is actually installed'
assert:
that:
- "'2.6.0-3.el6' in query_result.stdout"
- shell: 'rpm -q ganglia-gmond-python'
register: query_result
- name: 'Ensure that version 3.7.1-2.el6 of ganglia-gmond-python is actually installed'
assert:
that:
- "'3.7.1-2.el6' in query_result.stdout"
- name: 'Demonstrate that downgrading does not work for lists of packages'
yum:
name: "{{ item }}"
state: installed
with_items:
- "subversion-1.6.11-14.el6"
- "python-requests-1.1.0-4.el6.centos"
- "ganglia-gmond-python-3.1.7-3.el6.rf"
- shell: 'rpm -q subversion'
register: query_result
- name: 'Ensure that version 1.6.11-15.el6_7 of subversion is actually installed'
assert:
that:
- "'1.6.11-15.el6_7' in query_result.stdout"
- shell: 'rpm -q python-requests'
register: query_result
- name: 'Ensure that version 2.6.0-3.el6 of python-requests is actually installed'
assert:
that:
- "'2.6.0-3.el6' in query_result.stdout"
- shell: 'rpm -q ganglia-gmond-python'
register: query_result
- name: 'Ensure that version 3.7.1-2.el6 of ganglia-gmond-python is actually installed'
assert:
that:
- "'3.7.1-2.el6' in query_result.stdout"
@marvinpinto
Copy link
Author

Please see ansible/ansible-modules-core#2199 for full context on what this gist is all about!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment