Debian Codegraph @

test/integration/targets/get_url/tasks/use_netrc.yml

raw
1 - name: Write out netrc
2 copy:
3 dest: "{{ remote_tmp_dir }}/netrc"
4 content: |
5 machine {{ httpbin_host }}
6 login foo
7 password bar
8
9 - name: Test with netrc forced Basic auth
10 get_url:
11 url: https://{{ httpbin_host }}/basic-auth/foo/bar
12 headers:
13 Authorization: Bearer foobar
14 dest: "{{ remote_tmp_dir }}/msg.txt"
15 environment:
16 NETRC: "{{ remote_tmp_dir }}/netrc"
17
18 - name: Read msg.txt file
19 ansible.builtin.slurp:
20 src: "{{ remote_tmp_dir }}/msg.txt"
21 register: response
22
23 - name: assert Test with netrc forced Basic auth
24 assert:
25 that:
26 - (response['content'] | b64decode | from_json).user == 'foo'
27
28 - name: Test Bearer authorization is successful with use_netrc=False
29 get_url:
30 url: https://{{ httpbin_host }}/bearer
31 use_netrc: false
32 headers:
33 Authorization: Bearer foobar
34 dest: "{{ remote_tmp_dir }}/msg.txt"
35 environment:
36 NETRC: "{{ remote_tmp_dir }}/netrc"
37
38 - name: Read msg.txt file
39 ansible.builtin.slurp:
40 src: "{{ remote_tmp_dir }}/msg.txt"
41 register: response
42
43 - name: assert Test Bearer authorization is successful with use_netrc=False
44 assert:
45 that:
46 - (response['content'] | b64decode | from_json).token == 'foobar'
47
48 - name: Clean up
49 file:
50 path: "{{ item }}"
51 state: absent
52 with_items:
53 - "{{ remote_tmp_dir }}/netrc"
54 - "{{ remote_tmp_dir }}/msg.txt"