-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_jenkins_credentials.yml
45 lines (42 loc) · 1.38 KB
/
create_jenkins_credentials.yml
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
- name: Create Jenkins Credentials
hosts: all
become: False
gather_facts: True
tasks:
- name: Get Jenkins Crumb
uri:
url: "{{ JENKINS_CRUMB_URL }}"
user: "{{ JENKINS_USERNAME }}"
password: "{{ JENKINS_PASSWORD }}"
force_basic_auth: yes
return_content: yes
status_code: 200
register: jenkins_crumb
until: jenkins_crumb.status == 200
retries: 10
delay: 5
- name: create the creds file
ini_file:
state: present
path: "{{ JENKINS_AWS_CRED_PATH }}"
section: "{{ item.section }}"
option: "{{ item.option }}"
value: "{{ item.value }}"
no_log: "{{ JENKINS_NO_LOG }}"
with_items: "{{ CRED_CONTENT }}"
- name: Create Credentials
shell: |
curl --header 'Jenkins-Crumb:{{ jenkins_crumb.json.crumb }}' \
--header 'Cookie:{{ jenkins_crumb.set_cookie }}' \
-X POST {{ item.url }} \
{% if item.type == "json" %}
--data-urlencode 'json={{ item.body.yaml | to_nice_json }}'
{% elif item.type == "file" %}
--form secret=@{{ item.file_path }} \
--form 'json={{ item.body.yaml | to_nice_json }}'
{% endif %}
become: False
no_log: "{{ JENKINS_NO_LOG }}"
args:
executable: "/bin/bash"
with_items: "{{ JENKINS_CREDENTIALS }}"