summaryrefslogtreecommitdiff
path: root/test/integration/roles/test_apt/tasks/apt.yml
blob: 5d331b192da47294bbd892d08917cdfc66015d27 (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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139


# UNINSTALL 'python-apt'
#  The `apt` module has the smarts to auto-install `python-apt`.  To test, we
#  will first uninstall `python-apt`.
- name: check python-apt with dpkg
  shell: dpkg -s python-apt
  register: dpkg_result
  ignore_errors: true

- name: uninstall python-apt with apt
  apt: pkg=python-apt state=absent purge=yes
  register: apt_result
  when: dpkg_result|success

# UNINSTALL 'hello'
#   With 'python-apt' uninstalled, the first call to 'apt' should install
#   python-apt.
- name: uninstall hello with apt
  apt: pkg=hello state=absent purge=yes
  register: apt_result

- name: check hello with dpkg
  shell: dpkg --get-selections | fgrep hello
  failed_when: False
  register: dpkg_result

- name: verify uninstallation of hello
  assert:
    that:
        - "'changed' in apt_result"
        - "dpkg_result.rc == 1"

# UNINSTALL AGAIN
- name: uninstall hello with apt
  apt: pkg=hello state=absent purge=yes
  register: apt_result

- name: verify no change on re-uninstall
  assert:
    that:
        - "not apt_result.changed"

# INSTALL
- name: install hello with apt
  apt: name=hello state=present
  register: apt_result

- name: check hello with dpkg
  shell: dpkg --get-selections | fgrep hello
  failed_when: False
  register: dpkg_result

- debug: var=apt_result
- debug: var=dpkg_result

- name: verify installation of hello
  assert:
    that:
        - "apt_result.changed"
        - "dpkg_result.rc == 0"

- name: verify apt module outputs
  assert:
    that:
        - "'changed' in apt_result"
        - "'stderr' in apt_result"
        - "'stdout' in apt_result"
        - "'stdout_lines' in apt_result"

# INSTALL AGAIN
- name: install hello with apt
  apt: name=hello state=present
  register: apt_result

- name: verify no change on re-install
  assert:
    that:
        - "not apt_result.changed"

# UNINSTALL AGAIN
- name: uninstall hello with apt
  apt: pkg=hello state=absent purge=yes
  register: apt_result

# INSTALL WITH VERSION WILDCARD
- name: install hello with apt
  apt: name=hello=2.* state=present
  register: apt_result

- name: check hello with wildcard with  dpkg
  shell: dpkg --get-selections | fgrep hello
  failed_when: False
  register: dpkg_result

- debug: var=apt_result
- debug: var=dpkg_result

- name: verify installation of hello
  assert:
    that:
        - "apt_result.changed"
        - "dpkg_result.rc == 0"

- name: check hello version
  shell: dpkg -s hello | grep Version | sed -r 's/Version:\s+([a-zA-Z0-9.-]+)\s*$/\1/'
  register: hello_version
- name: check hello architecture
  shell: dpkg -s hello | grep Architecture | sed -r 's/Architecture:\s+([a-zA-Z0-9.-]+)\s*$/\1/'
  register: hello_architecture

- name: uninstall hello with apt
  apt: pkg=hello state=absent purge=yes

- name: install deb file
  apt: deb="/var/cache/apt/archives/hello_{{ hello_version.stdout }}_{{ hello_architecture.stdout }}.deb"
  register: apt_initial

- name: install deb file again
  apt: deb="/var/cache/apt/archives/hello_{{ hello_version.stdout }}_{{ hello_architecture.stdout }}.deb"
  register: apt_secondary

- name: verify installation of hello
  assert:
    that:
        - "apt_initial.changed"
        - "not apt_secondary.changed"

- name: uninstall hello with apt
  apt: pkg=hello state=absent purge=yes

- name: force install of deb
  apt: deb="/var/cache/apt/archives/hello_{{ hello_version.stdout }}_{{ hello_architecture.stdout }}.deb" force=true
  register: dpkg_force

- name: verify installation of hello
  assert:
    that:
        - "dpkg_force.changed"