summaryrefslogtreecommitdiffstats
path: root/test/integration/targets/package_facts/tasks/main.yml
blob: 144fa784f70ea1649ee5d9c3cfea65ea5f63510b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# Copyright: Contributors to the Ansible project

- name: Prep package_fact tests - Debian Family
  block:
    - name: install python apt bindings - python2
      package: name="python-apt" state=present
      when: ansible_python.version.major|int == 2

    - name: install python apt bindings - python3
      package: name="python3-apt" state=present
      when: ansible_python.version.major|int == 3

    - name: Gather package facts
      package_facts:
        manager: apt

    - name: check for ansible_facts.packages exists
      assert:
        that: ansible_facts.packages is defined
  when: ansible_os_family == "Debian"

- name: Run package_fact tests - Red Hat Family
  block:
    - name: Gather package facts
      package_facts:
        manager: rpm

    - name: check for ansible_facts.packages exists
      assert:
        that: ansible_facts.packages is defined
  when: (ansible_os_family == "RedHat")

- name: Run package_fact tests - SUSE/OpenSUSE Family
  block:
    - name: install python rpm bindings - python2
      package: name="rpm-python" state=present
      when: ansible_python.version.major|int == 2

    - name: install python rpm bindings - python3
      package: name="python3-rpm" state=present
      when: ansible_python.version.major|int == 3

    - name: Gather package facts
      package_facts:
        manager: rpm

    - name: check for ansible_facts.packages exists
      assert:
        that: ansible_facts.packages is defined
  when: (ansible_os_family == "openSUSE Leap") or (ansible_os_family == "Suse")

- name: Same as those above, but based on pkg_mgr, tests aliases
  block:
    - name: Gather package facts
      package_facts:
        manager: '{{ ansible_facts["pkg_mgr"] }}'

    - name: check for ansible_facts.packages exists
      assert:
        that:
          - ansible_facts.packages is defined
          - ansible_facts.packages | length > 1
  when: ansible_facts['os_family'] in ["openSUSE Leap", "Suse", "RedHat", "Debian"]

# Check that auto detection works also
- name: Gather package facts
  package_facts:
    manager: auto

- name: check for ansible_facts.packages exists
  assert:
    that: ansible_facts.packages is defined

- name: Run package_fact tests - FreeBSD
  block:
    - name: Gather package facts
      package_facts:
        manager: pkg

    - name: check for ansible_facts.packages exists
      assert:
        that: ansible_facts.packages is defined

    - name: check there is at least one package not flagged vital nor automatic
      command: pkg query -e "%a = 0 && %V = 0" %n
      register: not_vital_nor_automatic
      failed_when: not not_vital_nor_automatic.stdout

    - vars:
        pkg_name: "{{ not_vital_nor_automatic.stdout_lines[0].strip() }}"
      block:
        - name: check the selected package is not vital
          assert:
            that:
              - 'not ansible_facts.packages[pkg_name][0].vital'
              - 'not ansible_facts.packages[pkg_name][0].automatic'

        - name: flag the selected package as vital and automatic
          command: 'pkg set --yes -v 1 -A 1 {{ pkg_name }}'

        - name: Gather package facts (again)
          package_facts:

        - name: check the selected package is flagged vital and automatic
          assert:
            that:
              - 'ansible_facts.packages[pkg_name][0].vital|bool'
              - 'ansible_facts.packages[pkg_name][0].automatic|bool'
      always:
        - name: restore previous flags for the selected package
          command: 'pkg set --yes -v 0 -A 0 {{ pkg_name }}'
  when: ansible_os_family == "FreeBSD"