Skip to content

Instantly share code, notes, and snippets.

@tomwwright
Last active July 30, 2018 06:58
Show Gist options
  • Select an option

  • Save tomwwright/85f522fb919d23d1c473e9a481b9b7f8 to your computer and use it in GitHub Desktop.

Select an option

Save tomwwright/85f522fb919d23d1c473e9a481b9b7f8 to your computer and use it in GitHub Desktop.
ansibled:logentries:tasks:logs
# POST to Logentries and create the new log, note:
# - provide our API key in the `x-api-key` header
# - Logentries API responds with a 201, so that is a successful response (status_code)
# - provide our Logset id so that our new log will be created in it
- name: create Log in Logentries if it doesn't exist - {{ item }}
uri:
url: https://rest.logentries.com/management/logs
headers:
x-api-key: "{{ logentries_api_key }}"
method: POST
body_format: json
body:
log:
name: "{{ item | lower }}"
logs_info: []
user_data: {}
source_type: token
logsets_info:
- id: "{{ logentries_logset.id }}"
status_code: 200,201
return_content: yes
register: create_log_info
# scrape the Logentries response for the new log token -- for use later
- name: save the Log token (new log)
set_fact:
logentries_log_tokens: "{{ logentries_log_tokens | default({}) | combine({ item: create_log_info.json.log.tokens[0] }) }}"
# update our Log id dictionary
- name: save the Log id (new log)
set_fact:
logentries_log_ids: "{{ logentries_log_ids | default({}) | combine({ item: create_log_info.json.log.id }) }}"
# GET from Logentries for existing log details, note:
# - provide our API key in the `x-api-key` header
# - Logentries API responds with a 201, so that is a successful response (status_code)
- name: look up Log in Logentries if it does exist - {{ item }}
uri:
url: https://rest.logentries.com/management/logs/{{ logentries_log_ids[item] }}
headers:
x-api-key: "{{ logentries_api_key }}"
method: GET
return_content: yes
register: lookup_log_info
when: logentries_log_ids[item] is defined
# scrape the Logentries response for the log token -- for use later
- name: save the Log token (existing log)
set_fact:
logentries_log_tokens: "{{ logentries_log_tokens | default({}) | combine({ item: lookup_log_info.json.log.tokens[0] }) }}"
when: logentries_log_ids[item] is defined
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment