Debian Codegraph @

ansible_collections/community/general/tests/integration/targets/jenkins_credential/tasks/pre.yml

raw
1 # Copyright (c) Ansible Project
2 # GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
3 # SPDX-License-Identifier: GPL-3.0-or-later
4
5 - name: Include Jenkins user variables
6 include_vars: "{{ role_path }}/vars/credentials.yml"
7
8 - name: Make sure Jenkins is ready
9 uri:
10 url: http://localhost:8080/login
11 status_code: 200
12 return_content: false
13 timeout: 30
14 register: result
15 retries: 10
16 delay: 5
17 until: result.status == 200
18
19 - name: Get Jenkins crumb and save cookie
20 shell: |
21 curl -s -c cookies.txt -u FishLegs:MeatLug http://localhost:8080/crumbIssuer/api/json > crumb.json
22 args:
23 executable: /bin/bash
24
25 - name: Read crumb value
26 set_fact:
27 crumb_data: "{{ lookup('file', 'crumb.json') | from_json }}"
28
29 - name: Create Jenkins folder 'test'
30 shell: |
31 curl -b cookies.txt -u {{ jenkins_username }}:{{ jenkins_password }} \
32 -H "{{ crumb_data.crumbRequestField }}: {{ crumb_data.crumb }}" \
33 -H "Content-Type: application/xml" \
34 --data-binary @- http://localhost:8080/createItem?name=test <<EOF
35 <com.cloudbees.hudson.plugins.folder.Folder plugin="[email protected]">
36 <description>Test Folder</description>
37 <properties/>
38 </com.cloudbees.hudson.plugins.folder.Folder>
39 EOF
40 args:
41 executable: /bin/bash
42
43 - name: Create output directory
44 ansible.builtin.file:
45 path: "{{ output_dir }}"
46 state: directory
47 mode: "0755"
48
49 - name: Generate private key
50 community.crypto.openssl_privatekey:
51 path: "{{ output_dir }}/private.key"
52 size: 2048
53 type: RSA
54
55 - name: Generate CSR (certificate signing request)
56 community.crypto.openssl_csr:
57 path: "{{ output_dir }}/request.csr"
58 privatekey_path: "{{ output_dir }}/private.key"
59 common_name: "dummy.local"
60
61 - name: Generate self-signed certificate
62 community.crypto.x509_certificate:
63 path: "{{ output_dir }}/cert.pem"
64 privatekey_path: "{{ output_dir }}/private.key"
65 csr_path: "{{ output_dir }}/request.csr"
66 provider: selfsigned
67
68 - name: Create PKCS#12 (.p12) file
69 community.crypto.openssl_pkcs12:
70 path: "{{ output_dir }}/certificate.p12"
71 privatekey_path: "{{ output_dir }}/private.key"
72 certificate_path: "{{ output_dir }}/cert.pem"
73 friendly_name: "dummy-cert"
74 passphrase: "12345678901234"
75
76 - name: Copy cert.pem to github.pem
77 ansible.builtin.copy:
78 src: "{{ output_dir }}/cert.pem"
79 dest: "{{ output_dir }}/github.pem"
80 remote_src: true
81
82 - name: Copy private.key to my-secret.pem
83 ansible.builtin.copy:
84 src: "{{ output_dir }}/private.key"
85 dest: "{{ output_dir }}/my-secret.pem"
86 remote_src: true
87
88 - name: Generate dummy SSH key
89 community.crypto.openssh_keypair:
90 path: "{{ output_dir }}/ssh_key"
91 type: rsa
92 size: 2048