<commit_before>---
#
# Save initial state
#
- name: Retrieve a list of gpg keys are installed for package checking
  shell: 'rpm -q gpg-pubkey | sort'
  register: list_of_pubkeys

- name: Retrieve the gpg keys used to verify packages
  command: 'rpm -q --qf %{description} gpg-pubkey'
  register: pubkeys

- name: Save gpg keys to a file
  copy:
    content: "{{ pubkeys['stdout'] }}\n"
    dest: '{{ output_dir }}/pubkeys'
    mode: 0600

#
# Tests start
#
- name: download EPEL GPG key
  get_url:
    url: https://download.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-7
    dest: /tmp/RPM-GPG-KEY-EPEL-7

- name: download sl rpm
  get_url:
    url: https://download.fedoraproject.org/pub/epel/7/x86_64/Packages/s/sl-5.02-1.el7.x86_64.rpm
    dest: /tmp/sl.rpm

- name: download Mono key
  get_url:
    url: http://keyserver.ubuntu.com/pks/lookup?op=get&search=0x3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
    dest: /tmp/mono.gpg

- name: remove EPEL GPG key from keyring
  rpm_key:
    state: absent
    key: /tmp/RPM-GPG-KEY-EPEL-7

- name: check GPG signature of sl. Should fail
  shell: "rpm --checksig /tmp/sl.rpm"
  register: sl_check
  ignore_errors: yes

- name: confirm that signature check failed
  assert:
    that:
      - "'MISSING KEYS' in sl_check.stdout"
      - "sl_check.failed"

- name: remove EPEL GPG key from keyring (idempotent)
  rpm_key:
    state: absent
    key: /tmp/RPM-GPG-KEY-EPEL-7
  register: idempotent_test

- name: check idempontence
  assert:
    that: "not idempotent_test.changed"

- name: add EPEL GPG key to key ring
  rpm_key:
    state: present
    key: /tmp/RPM-GPG-KEY-EPEL-7

- name: add EPEL GPG key to key ring (idempotent)
  rpm_key:
    state: present
    key: /tmp/RPM-GPG-KEY-EPEL-7

- name: add Mono gpg key
  rpm_key:
      state: present
      key: /tmp/mono.gpg

- name: add Mono gpg key
  rpm_key:
      state: present
      key: /tmp/mono.gpg
  register: mono_indempotence

- name: verify idempotence
  assert:
    that: "not mono_indempotence.changed"

- name: check GPG signature of sl. Should return okay
  shell: "rpm --checksig /tmp/sl.rpm"
  register: sl_check

- name: confirm that signature check succeeded
  assert:
    that: "'rsa sha1 (md5) pgp md5 OK' in sl_check.stdout"

- name: remove GPG key from url
  rpm_key:
    state: absent
    key: https://download.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-7

- name: Confirm key is missing
  shell: "rpm --checksig /tmp/sl.rpm"
  register: sl_check
  ignore_errors: yes

- name: confirm that signature check failed
  assert:
    that:
      - "'MISSING KEYS' in sl_check.stdout"
      - "sl_check.failed"

- name: add GPG key from url
  rpm_key:
    state: present
    key: https://download.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-7

- name: check GPG signature of sl. Should return okay
  shell: "rpm --checksig /tmp/sl.rpm"
  register: sl_check

- name: confirm that signature check succeeded
  assert:
    that: "'rsa sha1 (md5) pgp md5 OK' in sl_check.stdout"

- name: remove all keys from key ring
  shell: "rpm -q  gpg-pubkey | xargs rpm -e"

- name: add very first key on system
  rpm_key:
    state: present
    key: https://download.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-7

- name: check GPG signature of sl. Should return okay
  shell: "rpm --checksig /tmp/sl.rpm"
  register: sl_check

- name: confirm that signature check succeeded
  assert:
    that: "'rsa sha1 (md5) pgp md5 OK' in sl_check.stdout"

#
# Cleanup
#
- name: remove all keys from key ring
  shell: "rpm -q  gpg-pubkey | xargs rpm -e"

- name: Restore the gpg keys normally installed on the system
  command: 'rpm --import {{ output_dir }}/pubkeys'
<commit_msg>Use ansible-ci-files for rpm_key test downloads.<commit_after>---
#
# Save initial state
#
- name: Retrieve a list of gpg keys are installed for package checking
  shell: 'rpm -q gpg-pubkey | sort'
  register: list_of_pubkeys

- name: Retrieve the gpg keys used to verify packages
  command: 'rpm -q --qf %{description} gpg-pubkey'
  register: pubkeys

- name: Save gpg keys to a file
  copy:
    content: "{{ pubkeys['stdout'] }}\n"
    dest: '{{ output_dir }}/pubkeys'
    mode: 0600

#
# Tests start
#
- name: download EPEL GPG key
  get_url:
    url: https://ansible-ci-files.s3.amazonaws.com/test/integration/targets/rpm_key/RPM-GPG-KEY-EPEL-7
    dest: /tmp/RPM-GPG-KEY-EPEL-7

- name: download sl rpm
  get_url:
    url: https://ansible-ci-files.s3.amazonaws.com/test/integration/targets/rpm_key/sl-5.02-1.el7.x86_64.rpm
    dest: /tmp/sl.rpm

- name: download Mono key
  get_url:
    url: https://ansible-ci-files.s3.amazonaws.com/test/integration/targets/rpm_key/mono.gpg
    dest: /tmp/mono.gpg

- name: remove EPEL GPG key from keyring
  rpm_key:
    state: absent
    key: /tmp/RPM-GPG-KEY-EPEL-7

- name: check GPG signature of sl. Should fail
  shell: "rpm --checksig /tmp/sl.rpm"
  register: sl_check
  ignore_errors: yes

- name: confirm that signature check failed
  assert:
    that:
      - "'MISSING KEYS' in sl_check.stdout"
      - "sl_check.failed"

- name: remove EPEL GPG key from keyring (idempotent)
  rpm_key:
    state: absent
    key: /tmp/RPM-GPG-KEY-EPEL-7
  register: idempotent_test

- name: check idempontence
  assert:
    that: "not idempotent_test.changed"

- name: add EPEL GPG key to key ring
  rpm_key:
    state: present
    key: /tmp/RPM-GPG-KEY-EPEL-7

- name: add EPEL GPG key to key ring (idempotent)
  rpm_key:
    state: present
    key: /tmp/RPM-GPG-KEY-EPEL-7

- name: add Mono gpg key
  rpm_key:
      state: present
      key: /tmp/mono.gpg

- name: add Mono gpg key
  rpm_key:
      state: present
      key: /tmp/mono.gpg
  register: mono_indempotence

- name: verify idempotence
  assert:
    that: "not mono_indempotence.changed"

- name: check GPG signature of sl. Should return okay
  shell: "rpm --checksig /tmp/sl.rpm"
  register: sl_check

- name: confirm that signature check succeeded
  assert:
    that: "'rsa sha1 (md5) pgp md5 OK' in sl_check.stdout"

- name: remove GPG key from url
  rpm_key:
    state: absent
    key: https://ansible-ci-files.s3.amazonaws.com/test/integration/targets/rpm_key/RPM-GPG-KEY-EPEL-7

- name: Confirm key is missing
  shell: "rpm --checksig /tmp/sl.rpm"
  register: sl_check
  ignore_errors: yes

- name: confirm that signature check failed
  assert:
    that:
      - "'MISSING KEYS' in sl_check.stdout"
      - "sl_check.failed"

- name: add GPG key from url
  rpm_key:
    state: present
    key: https://ansible-ci-files.s3.amazonaws.com/test/integration/targets/rpm_key/RPM-GPG-KEY-EPEL-7

- name: check GPG signature of sl. Should return okay
  shell: "rpm --checksig /tmp/sl.rpm"
  register: sl_check

- name: confirm that signature check succeeded
  assert:
    that: "'rsa sha1 (md5) pgp md5 OK' in sl_check.stdout"

- name: remove all keys from key ring
  shell: "rpm -q  gpg-pubkey | xargs rpm -e"

- name: add very first key on system
  rpm_key:
    state: present
    key: https://ansible-ci-files.s3.amazonaws.com/test/integration/targets/rpm_key/RPM-GPG-KEY-EPEL-7

- name: check GPG signature of sl. Should return okay
  shell: "rpm --checksig /tmp/sl.rpm"
  register: sl_check

- name: confirm that signature check succeeded
  assert:
    that: "'rsa sha1 (md5) pgp md5 OK' in sl_check.stdout"

#
# Cleanup
#
- name: remove all keys from key ring
  shell: "rpm -q  gpg-pubkey | xargs rpm -e"

- name: Restore the gpg keys normally installed on the system
  command: 'rpm --import {{ output_dir }}/pubkeys'

{'fraction_non_alphanumeric': 0.11370924639230358, 'fraction_numerical': 0.01296098343132015, 'mean_word_length': 2.933263268523384, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 11, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '930299', 'n_tokens_mistral': 2952, 'n_tokens_neox': 2832, 'n_words': 809}