Skip to content

Commit

Permalink
Add dedicated README for lookup plugins.
Browse files Browse the repository at this point in the history
  • Loading branch information
robin-checkmk committed Feb 16, 2024
1 parent a01a6d3 commit 5472f93
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Name | Description

### Lookup plugins
Click on the lookup plugin name below, to get detailed documentation about it.
For more in-depth documentation, see [this README](https://github.com/Checkmk/ansible-collection-checkmk.general/blob/main/plugins/lookup/README.md).

Name | Description | Tests
--- | --- | ---
Expand Down
57 changes: 57 additions & 0 deletions plugins/lookup/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Lookup Plugins

## Using variables for Lookup plugins
It is possible to set variables for authentication globally for lookup plugins.
This way, they do not need to be provided at task level.

### Method 1: Environment variables
```bash
export ANSIBLE_LOOKUP_CHECKMK_SERVER_URL="https://myserver"
export ANSIBLE_LOOKUP_CHECKMK_SITE=mysite
export ANSIBLE_LOOKUP_AUTOMATION_USER=automation
export ANSIBLE_LOOKUP_AUTOMATION_SECRET=mysecret
export ANSIBLE_LOOKUP_VALIDATE_CERTS=False
```

### Method 2: In `ansible.cfg`
```ini
[checkmk_lookup]
server_url = https://myserver
site = mysite
automation_user = automation
automation_secret = mysecret
validate_certs = False

```

### Method 3: In playbooks or the inventory
```yaml
- name: My Task
hosts: localhost
gather_facts: false
vars:
ansible_lookup_checkmk_server_url: "https://myserver"
ansible_lookup_checkmk_site: "mysite"
ansible_lookup_automation_user: "automation"
ansible_lookup_automation_secret: "mysecret"
ansible_lookup_validate_certs: false

tasks:
- name: Get the attributes of myhost
ansible.builtin.debug:
msg: "Attributes of myhost: {{ attributes }}"
vars:
attributes: "{{ lookup('checkmk.general.host', 'myhost', effective_attributes=True) }}"
```
### Example
The following task will work, if one of the above methods has been applied.
```yaml
- name: My Task
tasks:
- name: Get the attributes of myhost
ansible.builtin.debug:
msg: "Attributes of myhost: {{ attributes }}"
vars:
attributes: "{{ lookup('checkmk.general.host', 'myhost', effective_attributes=True) }}"
```

0 comments on commit 5472f93

Please sign in to comment.