summaryrefslogtreecommitdiff
path: root/test/integration/targets/apt_repository/tasks/mode.yaml
blob: 0de6ca14aeae25440f94a3d2ac2275e685785d18 (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
---

# These tests are likely slower than they should be, since each
# invocation of apt_repository seems to end up querying for
# lots (all?) configured repos.

- set_fact:
    test_repo_spec: "deb http://apt.postgresql.org/pub/repos/apt/ {{ ansible_distribution_release }}-pgdg main"
    test_repo_path: /etc/apt/sources.list.d/apt_postgresql_org_pub_repos_apt.list

- include: mode_cleanup.yaml

- name: Add GPG key to verify signatures
  apt_key:
    id: 7FCC7D46ACCC4CF8
    keyserver: keyserver.ubuntu.com

- name: Mode specified as yaml literal 0600
  apt_repository:
    repo: "{{ test_repo_spec }}"
    state: present
    mode: 0600
  register: mode_given_results

- name: Gather mode_given_as_literal_yaml stat
  stat:
    path: "{{ test_repo_path }}"
  register: mode_given_yaml_literal_0600

- name: Show mode_given_yaml_literal_0600
  debug:
    var: mode_given_yaml_literal_0600

- include: mode_cleanup.yaml

- name: Assert mode_given_yaml_literal_0600 is correct
  assert:
    that: "mode_given_yaml_literal_0600.stat.mode == '0600'"

- name: No mode specified
  apt_repository:
    repo: "{{ test_repo_spec }}"
    state: present
    mode: 0644
  register: no_mode_results

- name: Gather no mode stat
  stat:
    path: "{{ test_repo_path }}"
  register: no_mode_stat

- name: Show no mode stat
  debug:
    var: no_mode_stat

- include: mode_cleanup.yaml

- name: Assert no_mode_stat is correct
  assert:
    that: "no_mode_stat.stat.mode == '0644'"

- name: Mode specified as string 0600
  apt_repository:
    repo: "{{ test_repo_spec }}"
    state: present
    mode: "0600"
  register: mode_given_string_results

- name: Gather mode_given_string stat
  stat:
    path: "{{ test_repo_path }}"
  register: mode_given_string_stat

- name: Show mode_given_string_stat
  debug:
    var: mode_given_string_stat

- include: mode_cleanup.yaml

- name: Mode specified as string 600
  apt_repository:
    repo: "{{ test_repo_spec }}"
    state: present
    mode: "600"
  register: mode_given_string_600_results

- name: Gather mode_given_600_string stat
  stat:
    path: "{{ test_repo_path }}"
  register: mode_given_string_600_stat

- name: Show mode_given_string_stat
  debug:
    var: mode_given_string_600_stat

- include: mode_cleanup.yaml

- name: Assert mode is correct
  assert:
    that: "mode_given_string_600_stat.stat.mode == '0600'"

- name: Mode specified as yaml literal 600
  apt_repository:
    repo: "{{ test_repo_spec }}"
    state: present
    mode: 600
  register: mode_given_short_results

- name: Gather mode_given_yaml_literal_600 stat
  stat:
    path: "{{ test_repo_path }}"
  register: mode_given_yaml_literal_600

- name: Show mode_given_yaml_literal_600
  debug:
    var: mode_given_yaml_literal_600

- include: mode_cleanup.yaml

# a literal 600 as the mode will fail currently, in the sense that it
# doesn't guess and consider 600 and 0600 to be the same, and will instead
# intepret literal 600 as the decimal 600 (and thereby octal 1130).
# The literal 0600 can be interpreted as octal correctly. Note that
# a decimal 644 is octal 420. The default perm is 0644 so a mis intrpretation
# of 644 was previously resulting in a default file mode of 0420.
# 'mode: 600' is likely not what a user meant but there isnt enough info
# to determine that. Note that a string arg of '600' will be intrepeted as 0600.
# See https://github.com/ansible/ansible/issues/16370
- name: Assert mode_given_yaml_literal_600 is correct
  assert:
    that: "mode_given_yaml_literal_600.stat.mode == '1130'"