Debian Codegraph @

ansible_collections/community/general/tests/integration/targets/alternatives/tasks/test.yml

raw
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 - debug:
7 msg: ' with_alternatives: {{ with_alternatives }}, mode: {{ mode }}'
8
9 - block:
10 - name: set alternative (using link parameter)
11 alternatives:
12 name: dummy
13 path: '/usr/bin/dummy{{ item }}'
14 link: '/usr/bin/dummy'
15 register: alternative
16
17 - name: check expected command was executed
18 assert:
19 that:
20 - 'alternative is successful'
21 - 'alternative is changed'
22 when: with_link
23
24 - block:
25 - name: set alternative (without link parameter)
26 alternatives:
27 name: dummy
28 path: '/usr/bin/dummy{{ item }}'
29 register: alternative
30
31 - name: check expected command was executed
32 assert:
33 that:
34 - 'alternative is successful'
35 - 'alternative is changed'
36 when: not with_link
37
38 - name: execute dummy command
39 shell: dummy
40 register: cmd
41
42 - name: check expected command was executed
43 assert:
44 that:
45 - 'cmd.stdout == "dummy" ~ item'
46
47 - name: 'check mode (manual: alternatives file existed, it has been updated)'
48 shell: 'head -n1 {{ alternatives_dir }}/dummy | grep "^manual$"'
49 when: ansible_facts.os_family != 'RedHat' or with_alternatives or item != 1
50
51 - name: 'check mode (auto: alternatives file didn''t exist, it has been created)'
52 shell: 'head -n1 {{ alternatives_dir }}/dummy | grep "^auto$"'
53 when: ansible_facts.os_family == 'RedHat' and not with_alternatives and item == 1
54
55 - name: check that alternative has been updated
56 command: "grep -Pzq '/bin/dummy{{ item }}\\n' '{{ alternatives_dir }}/dummy'"