summaryrefslogtreecommitdiff
path: root/test/integration/roles/test_filters/tasks/main.yml
blob: 1f6f0682e9d27f445921161edc7b1395796e6238 (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
# test code
# (c) 2014, Michael DeHaan <michael.dehaan@gmail.com>

# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible.  If not, see <http://www.gnu.org/licenses/>.

- name: a dummy task to test the changed and success filters
  shell: echo hi
  register: some_registered_var

- debug: var=some_registered_var

- name: Verify that we workaround a py26 json bug
  template: src=py26json.j2 dest={{output_dir}}/py26json.templated mode=0644

- name: 9851 - Verify that we don't trigger https://github.com/ansible/ansible/issues/9851
  copy:
    content: " [{{item|to_nice_json}}]"
    dest: "{{output_dir}}/9851.out"
  with_items:
  - {"k": "Quotes \"'\n"}

- name: 9851 - copy known good output into place
  copy: src=9851.txt dest={{output_dir}}/9851.txt

- name: 9851 - Compare generated json to known good
  shell: diff -w {{output_dir}}/9851.out {{output_dir}}/9851.txt
  register: diff_result_9851

- name: 9851 - verify generated file matches known good
  assert:
    that:
        - 'diff_result_9851.stdout == ""'

- name: fill in a basic template
  template: src=foo.j2 dest={{output_dir}}/foo.templated mode=0644
  register: template_result

- name: copy known good into place
  copy: src=foo.txt dest={{output_dir}}/foo.txt

- name: compare templated file to known good
  shell: diff -w {{output_dir}}/foo.templated {{output_dir}}/foo.txt
  register: diff_result

- name: verify templated file matches known good
  assert:
    that:
        - 'diff_result.stdout == ""'

- name: Verify human_readable
  tags: "human_readable"
  assert:
    that:
        - '"1.00 Bytes" == 1|human_readable'
        - '"1.00 bits" == 1|human_readable(isbits=True)'
        - '"10.00 KB" == 10240|human_readable'
        - '"97.66 MB" == 102400000|human_readable'
        - '"0.10 GB" == 102400000|human_readable(unit="G")'
        - '"0.10 Gb" == 102400000|human_readable(isbits=True, unit="G")'

- name: Verify human_to_bytes
  tags: "human_to_bytes"
  assert:
    that:
        - "{{'0'|human_to_bytes}}        == 0"
        - "{{'0.1'|human_to_bytes}}      == 0"
        - "{{'0.9'|human_to_bytes}}      == 1"
        - "{{'1'|human_to_bytes}}        == 1"
        - "{{'10.00 KB'|human_to_bytes}} == 10240"
        - "{{   '11 MB'|human_to_bytes}} == 11534336"
        - "{{  '1.1 GB'|human_to_bytes}} == 1181116006"
        - "{{'10.00 Kb'|human_to_bytes(isbits=True)}} == 10240"

- name: Verify human_to_bytes (bad string)
  tags: "human_to_bytes"
  set_fact: bad_string="{{'10.00 foo'|human_to_bytes}}"
  ignore_errors: yes
  register: _

- name: Verify human_to_bytes (bad string)
  tags: "human_to_bytes"
  assert:
    that: "{{_.failed}}"

- name: Container lookups with extract
  assert:
    that:
        - "'x' == [0]|map('extract',['x','y'])|list|first"
        - "'y' == [1]|map('extract',['x','y'])|list|first"
        - "42 == ['x']|map('extract',{'x':42,'y':31})|list|first"
        - "31 == ['x','y']|map('extract',{'x':42,'y':31})|list|last"
        - "'local' == ['localhost']|map('extract',hostvars,'ansible_connection')|list|first"
        - "'local' == ['localhost']|map('extract',hostvars,['ansible_connection'])|list|first"
  # map was added to jinja2 in version 2.7
  when: "{{ ( lookup('pipe', '{{ ansible_python[\"executable\"] }} -c \"import jinja2; print(jinja2.__version__)\"') |
              version_compare('2.7', '>=') ) }}"

- name: Test json_query filter
  assert:
    that:
      - "users | json_query('[*].hosts[].host') == ['host_a', 'host_b', 'host_c', 'host_d']"