| 1 |
--- |
| 2 |
# Copyright (c) Ansible Project |
| 3 |
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt) |
| 4 |
# SPDX-License-Identifier: GPL-3.0-or-later |
| 5 |
|
| 6 |
- name: Try with subcommands |
| 7 |
alternatives: |
| 8 |
name: dummymain |
| 9 |
path: '/usr/bin/dummy1' |
| 10 |
link: '/usr/bin/dummymain' |
| 11 |
subcommands: |
| 12 |
- name: dummysubcmd |
| 13 |
path: '/usr/bin/dummy2' |
| 14 |
link: '/usr/bin/dummysubcmd' |
| 15 |
register: alternative |
| 16 |
|
| 17 |
- name: Check expected command was executed |
| 18 |
assert: |
| 19 |
that: |
| 20 |
- 'alternative is changed' |
| 21 |
|
| 22 |
- name: Execute the current dummymain command |
| 23 |
command: dummymain |
| 24 |
register: cmd |
| 25 |
|
| 26 |
- name: Ensure that the expected command was executed |
| 27 |
assert: |
| 28 |
that: |
| 29 |
- cmd.stdout == "dummy1" |
| 30 |
|
| 31 |
- name: Execute the current dummysubcmd command |
| 32 |
command: dummysubcmd |
| 33 |
register: cmd |
| 34 |
|
| 35 |
- name: Ensure that the expected command was executed |
| 36 |
assert: |
| 37 |
that: |
| 38 |
- cmd.stdout == "dummy2" |
| 39 |
|
| 40 |
- name: Get dummymain alternatives output |
| 41 |
command: |
| 42 |
cmd: '{{ alternatives_command }} --display dummymain' |
| 43 |
register: result |
| 44 |
|
| 45 |
- name: Print result |
| 46 |
debug: |
| 47 |
var: result.stdout_lines |
| 48 |
|
| 49 |
- name: Subcommands are not removed if not specified |
| 50 |
alternatives: |
| 51 |
name: dummymain |
| 52 |
path: '/usr/bin/dummy1' |
| 53 |
link: '/usr/bin/dummymain' |
| 54 |
register: alternative |
| 55 |
|
| 56 |
- name: Check expected command was executed |
| 57 |
assert: |
| 58 |
that: |
| 59 |
- 'alternative is not changed' |
| 60 |
|
| 61 |
- name: Execute the current dummysubcmd command |
| 62 |
command: dummysubcmd |
| 63 |
register: cmd |
| 64 |
|
| 65 |
- name: Ensure that the expected command was executed |
| 66 |
assert: |
| 67 |
that: |
| 68 |
- cmd.stdout == "dummy2" |
| 69 |
|
| 70 |
- name: Subcommands are removed if set to an empty list |
| 71 |
alternatives: |
| 72 |
name: dummymain |
| 73 |
path: '/usr/bin/dummy1' |
| 74 |
link: '/usr/bin/dummymain' |
| 75 |
subcommands: [] |
| 76 |
register: alternative |
| 77 |
|
| 78 |
- name: Check expected command was executed |
| 79 |
assert: |
| 80 |
that: |
| 81 |
- 'alternative is changed' |
| 82 |
|
| 83 |
- name: Execute the current dummysubcmd command |
| 84 |
command: dummysubcmd |
| 85 |
register: cmd |
| 86 |
ignore_errors: true |
| 87 |
|
| 88 |
- name: Ensure that the subcommand is gone |
| 89 |
assert: |
| 90 |
that: |
| 91 |
- cmd.rc == 2 |
| 92 |
- '"No such file" in cmd.msg or "Error executing command." == cmd.msg' |
| 93 |
|
| 94 |
- name: Get dummymain alternatives output |
| 95 |
command: |
| 96 |
cmd: '{{ alternatives_command }} --display dummymain' |
| 97 |
register: result |
| 98 |
|
| 99 |
- name: Print result |
| 100 |
debug: |
| 101 |
var: result.stdout_lines |
| 102 |
|
| 103 |
- name: Install other alternative with subcommands |
| 104 |
alternatives: |
| 105 |
name: dummymain |
| 106 |
path: '/usr/bin/dummy3' |
| 107 |
link: '/usr/bin/dummymain' |
| 108 |
subcommands: |
| 109 |
- name: dummysubcmd |
| 110 |
path: '/usr/bin/dummy4' |
| 111 |
link: '/usr/bin/dummysubcmd' |
| 112 |
register: alternative |
| 113 |
|
| 114 |
- name: Check expected command was executed |
| 115 |
assert: |
| 116 |
that: |
| 117 |
- 'alternative is changed' |
| 118 |
|
| 119 |
- name: Execute the current dummymain command |
| 120 |
command: dummymain |
| 121 |
register: cmd |
| 122 |
|
| 123 |
- name: Ensure that the expected command was executed |
| 124 |
assert: |
| 125 |
that: |
| 126 |
- cmd.stdout == "dummy3" |
| 127 |
|
| 128 |
- name: Execute the current dummysubcmd command |
| 129 |
command: dummysubcmd |
| 130 |
register: cmd |
| 131 |
|
| 132 |
- name: Ensure that the expected command was executed |
| 133 |
assert: |
| 134 |
that: |
| 135 |
- cmd.stdout == "dummy4" |
| 136 |
|
| 137 |
- name: Get dummymain alternatives output |
| 138 |
command: |
| 139 |
cmd: '{{ alternatives_command }} --display dummymain' |
| 140 |
register: result |
| 141 |
|
| 142 |
- name: Print result |
| 143 |
debug: |
| 144 |
var: result.stdout_lines |
| 145 |
|
| 146 |
- name: Switch to first alternative |
| 147 |
alternatives: |
| 148 |
name: dummymain |
| 149 |
path: '/usr/bin/dummy1' |
| 150 |
register: alternative |
| 151 |
|
| 152 |
- name: Check expected command was executed |
| 153 |
assert: |
| 154 |
that: |
| 155 |
- 'alternative is changed' |
| 156 |
|
| 157 |
- name: Execute the current dummymain command |
| 158 |
command: dummymain |
| 159 |
register: cmd |
| 160 |
|
| 161 |
- name: Ensure that the expected command was executed |
| 162 |
assert: |
| 163 |
that: |
| 164 |
- cmd.stdout == "dummy1" |
| 165 |
|
| 166 |
- name: Execute the current dummysubcmd command |
| 167 |
command: dummysubcmd |
| 168 |
register: cmd |
| 169 |
ignore_errors: true |
| 170 |
|
| 171 |
- name: Ensure that the subcommand is gone |
| 172 |
assert: |
| 173 |
that: |
| 174 |
- cmd.rc == 2 |
| 175 |
- '"No such file" in cmd.msg or "Error executing command." == cmd.msg' |
| 176 |
|
| 177 |
- name: Get dummymain alternatives output |
| 178 |
command: |
| 179 |
cmd: '{{ alternatives_command }} --display dummymain' |
| 180 |
register: result |
| 181 |
|
| 182 |
- name: Print result |
| 183 |
debug: |
| 184 |
var: result.stdout_lines |
| 185 |
|
| 186 |
- name: Switch to second alternative |
| 187 |
alternatives: |
| 188 |
name: dummymain |
| 189 |
path: '/usr/bin/dummy3' |
| 190 |
register: alternative |
| 191 |
|
| 192 |
- name: Check expected command was executed |
| 193 |
assert: |
| 194 |
that: |
| 195 |
- 'alternative is changed' |
| 196 |
|
| 197 |
- name: Execute the current dummymain command |
| 198 |
command: dummymain |
| 199 |
register: cmd |
| 200 |
|
| 201 |
- name: Ensure that the expected command was executed |
| 202 |
assert: |
| 203 |
that: |
| 204 |
- cmd.stdout == "dummy3" |
| 205 |
|
| 206 |
- name: Execute the current dummysubcmd command |
| 207 |
command: dummysubcmd |
| 208 |
register: cmd |
| 209 |
|
| 210 |
- name: Ensure that the expected command was executed |
| 211 |
assert: |
| 212 |
that: |
| 213 |
- cmd.stdout == "dummy4" |
| 214 |
|
| 215 |
- name: Get dummymain alternatives output |
| 216 |
command: |
| 217 |
cmd: '{{ alternatives_command }} --display dummymain' |
| 218 |
register: result |
| 219 |
|
| 220 |
- name: Print result |
| 221 |
debug: |
| 222 |
var: result.stdout_lines |