Hi
I have success with the following ansible script to license a single machine.
Summary: Retrieve Machine ID > submit User/Password/Machine ID/Activation code ... then submit license back to the machine to license the software.
What modules would work well for a multi machine senario using jenkins?
I looked at loops, include_roles, include_files, etc.
Any help appreciated.
---
- hosts: localhost
connection: local
gather_facts: true
vars:
myip: "{{ lookup('env','MYIP') }}"
myurl: http://{{ myip }}/service/discoverable/dir
mypassword: "{{ lookup('env','PW') }}"
target_connection: http://{{ myip }}/service/license-session
activation_code: "{{ lookup('env','ACTIVATION') }}"
location_description: "{{ lookup('env','LOCATION_DESCRIPTION') }}"
jenkins_workspace: "{{ lookup('env','WORKSPACE') }}"
tasks:
- name: Retrieve xxxx MID
uri:
url: "{{ myurl | mandatory }}"
force_basic_auth: yes
user: admin
password: "{{ mypassword | mandatory }}"
timeout: 20
register: machineid
- name: DEBUG Retrieve xxxx MachineID
debug:
msg: "{{ machineid.json.orchids[0].mid }}"
- name: Post to retrieve Licence code
uri:
url: "{{ activation_url | mandatory }}"
method: POST
body: "activation_code={{ activation_code | mandatory }}\
&machine_id={{ machineid.json.orchids[0].mid | mandatory }}\
&location_description={{ location_description | mandatory }}\
&headless=1"
return_content: yes
status_code: 200
headers:
Content-Type: "application/x-www-form-urlencoded"
register: lic_code
- name: FAIL If the provided activation code has already been used
fail:
msg: "ERROR The provided activation code has already been used."
when: "'The provided activation code has already been used.' in lic_code.content"
- name: DEBUG Post to retrieve Licence code
debug:
msg: "{{ lic_code.content }}"
- name: "Create file {{ jenkins_workspace}}/lic_code.content.json"
copy:
dest: "{{ jenkins_workspace }}/lic_code.content.json"
content: |
"{{ lic_code.content }}"
- name: Replace Remove unecessary characters
replace:
path: "{{ jenkins_workspace}}/lic_code.content.json"
regexp: '^"|"$'
replace: ''
backup: yes
register: rep_rem
- name: DEBUG Replace Remove unecessary characters
debug:
msg: "{{ rep_rem }}"
- name: Activate Orchid license
uri:
url: "{{ target_connection }}"
method: POST
user: admin
password: "{{ mypassword }}"
body: "{{ lookup('file','{{ jenkins_workspace }}/lic_code.content.json') }}"
force_basic_auth: yes
status_code: 201
body_format: json
register: act_orchid
- name: DEBUG Activate Orchid license
debug:
msg: "{{ act_orchid }}"