| 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 |
# Add a few dummy alternatives with state = present and make sure that the |
| 7 |
# group is in 'auto' mode and the highest priority alternative is selected. |
| 8 |
- name: Add some dummy alternatives with state = present |
| 9 |
alternatives: |
| 10 |
name: dummy |
| 11 |
path: "/usr/bin/dummy{{ item.n }}" |
| 12 |
link: /usr/bin/dummy |
| 13 |
priority: "{{ item.priority }}" |
| 14 |
state: present |
| 15 |
loop: |
| 16 |
- { n: 1, priority: 50 } |
| 17 |
- { n: 2, priority: 70 } |
| 18 |
- { n: 3, priority: 25 } |
| 19 |
|
| 20 |
- name: Ensure that the link group is in auto mode |
| 21 |
shell: 'head -n1 {{ alternatives_dir }}/dummy | grep "^auto$"' |
| 22 |
|
| 23 |
# Execute current selected 'dummy' and ensure it's the alternative we expect |
| 24 |
- name: Execute the current dummy command |
| 25 |
shell: dummy |
| 26 |
register: cmd |
| 27 |
|
| 28 |
- name: Ensure that the expected command was executed |
| 29 |
assert: |
| 30 |
that: |
| 31 |
- cmd.stdout == "dummy2" |
| 32 |
|
| 33 |
# Add another alternative with state = 'selected' and make sure that |
| 34 |
# this change results in the group being set to manual mode, and the |
| 35 |
# new alternative being the selected one. |
| 36 |
- name: Add another dummy alternative with state = selected |
| 37 |
alternatives: |
| 38 |
name: dummy |
| 39 |
path: /usr/bin/dummy4 |
| 40 |
link: /usr/bin/dummy |
| 41 |
priority: 10 |
| 42 |
state: selected |
| 43 |
|
| 44 |
- name: Ensure that the link group is in manual mode |
| 45 |
shell: 'head -n1 {{ alternatives_dir }}/dummy | grep "^manual$"' |
| 46 |
|
| 47 |
- name: Execute the current dummy command |
| 48 |
shell: dummy |
| 49 |
register: cmd |
| 50 |
|
| 51 |
- name: Ensure that the expected command was executed |
| 52 |
assert: |
| 53 |
that: |
| 54 |
- cmd.stdout == "dummy4" |
| 55 |
|
| 56 |
# Set the currently selected alternative to state = 'present' (was previously |
| 57 |
# selected), and ensure that this results in the group not being set to 'auto' |
| 58 |
# mode, and the alternative is still selected. |
| 59 |
- name: Set current selected dummy to state = present |
| 60 |
alternatives: |
| 61 |
name: dummy |
| 62 |
path: /usr/bin/dummy4 |
| 63 |
link: /usr/bin/dummy |
| 64 |
state: present |
| 65 |
|
| 66 |
- name: Ensure that the link group is in auto mode |
| 67 |
shell: 'head -n1 {{ alternatives_dir }}/dummy | grep "^manual$"' |
| 68 |
|
| 69 |
- name: Execute the current dummy command |
| 70 |
shell: dummy |
| 71 |
register: cmd |
| 72 |
|
| 73 |
- name: Ensure that the expected command was executed |
| 74 |
assert: |
| 75 |
that: |
| 76 |
- cmd.stdout == "dummy4" |
| 77 |
|
| 78 |
# Set the currently selected alternative to state = 'auto' (was previously |
| 79 |
# selected), and ensure that this results in the group being set to 'auto' |
| 80 |
# mode, and the highest priority alternative is selected. |
| 81 |
- name: Set current selected dummy to state = present |
| 82 |
alternatives: |
| 83 |
name: dummy |
| 84 |
path: /usr/bin/dummy4 |
| 85 |
link: /usr/bin/dummy |
| 86 |
state: auto |
| 87 |
|
| 88 |
- name: Ensure that the link group is in auto mode |
| 89 |
shell: 'head -n1 {{ alternatives_dir }}/dummy | grep "^auto$"' |
| 90 |
|
| 91 |
- name: Execute the current dummy command |
| 92 |
shell: dummy |
| 93 |
register: cmd |
| 94 |
|
| 95 |
- name: Ensure that the expected command was executed |
| 96 |
assert: |
| 97 |
that: |
| 98 |
- cmd.stdout == "dummy2" |
| 99 |
|
| 100 |
# Remove an alternative with state = 'absent' and make sure that |
| 101 |
# this change results in the alternative being removed. |
| 102 |
- name: Remove best dummy alternative with state = absent |
| 103 |
alternatives: |
| 104 |
name: dummy |
| 105 |
path: /usr/bin/dummy2 |
| 106 |
state: absent |
| 107 |
|
| 108 |
- name: Ensure that the link group is in auto mode |
| 109 |
shell: 'grep "/usr/bin/dummy2" {{ alternatives_dir }}/dummy' |
| 110 |
register: cmd |
| 111 |
failed_when: cmd.rc == 0 |
| 112 |
|
| 113 |
- name: Execute the current dummy command |
| 114 |
shell: dummy |
| 115 |
register: cmd |
| 116 |
|
| 117 |
- name: Ensure that the expected command was executed |
| 118 |
assert: |
| 119 |
that: |
| 120 |
- cmd.stdout == "dummy1" |