Skip to content

Commit

Permalink
feat: docs update
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Kowallik committed Jul 23, 2024
1 parent 4fc18cc commit b2fa018
Show file tree
Hide file tree
Showing 8 changed files with 2,682 additions and 36 deletions.
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
# tmconfpy

<p align="center">
<a href="https://github.com/simonkowallik/tmconfpy/actions/workflows/ci-pipeline.yaml">
<p align="center" style="text-decoration: none;">
<a href="https://github.com/simonkowallik/tmconfpy/actions/workflows/ci-pipeline.yaml" target="_blank">
<img src="https://github.com/simonkowallik/tmconfpy/actions/workflows/ci-pipeline.yaml/badge.svg" alt="ci-pipeline">
</a>
<a href="https://codeclimate.com/github/simonkowallik/tmconfpy/test_coverage">
<a href="https://codeclimate.com/github/simonkowallik/tmconfpy/test_coverage" target="_blank">
<img src="https://api.codeclimate.com/v1/badges/3f404be294dceae16361/test_coverage" alt="test coverage">
</a>
<a href="https://hub.docker.com/r/simonkowallik/tmconfpy">
<a href="https://hub.docker.com/r/simonkowallik/tmconfpy" target="_blank">
<img src="https://img.shields.io/docker/image-size/simonkowallik/tmconfpy" alt="container image size">
</a>
<a href="https://github.com/simonkowallik/tmconfpy/releases">
<a href="https://pypi.org/project/tmconfpy" target="_blank" target="_blank">
<img src="https://img.shields.io/pypi/v/tmconfpy?color=%2334D058&label=pypi%20package" alt="Package version">
</a>
<a href="https://github.com/simonkowallik/tmconfpy/releases" target="_blank">
<img src="https://img.shields.io/github/v/release/simonkowallik/tmconfpy" alt="releases">
</a>
</p>
Expand All @@ -25,7 +28,7 @@ The TMOS configuration parser [f5-corkscrew](https://github.com/f5devcentral/f5-

Also checkout the jupyter notebook: [example/notebook.ipynb](./example/notebook.ipynb).

For more details about the relevant configuration files, data formats, tmconfpy and its ansible collection please have a look in [CONFIG-FORMATS.md](https://github.com/simonkowallik/tmconfpy/blob/main/CONFIG-FORMATS.md).
For more details about the relevant configuration files, data formats, tmconfpy and its ansible collection please have a look at the [documentation](https://simonkowallik.github.io/tmconfpy/).

## Using tmconfpy with ansible

Expand Down
73 changes: 71 additions & 2 deletions ansible_collections/simonkowallik/tmconfpy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

tmconfpy as well as the tmconfpy ansible collection aim to make BIG-IP configurations more accessible by serializing the tmconf format to python data structures.

For more details about the relevant configuration files, data formats, tmconfpy and its ansible collection please have a look in [CONFIG-FORMATS.md](https://github.com/simonkowallik/tmconfpy/blob/main/CONFIG-FORMATS.md).
For more details about the relevant configuration files, data formats, tmconfpy and its ansible collection please have a look in the [documentation](https://simonkowallik.github.io/tmconfpy/).

## Installation

Expand All @@ -31,4 +31,73 @@ In your `requirements.yml` file you can use both ways as well:

## Example Playbook

Please have a look at this [https://github.com/simonkowallik/tmconfpy/blob/main/ansible_collections/simonkowallik/tmconfpy/playbook/example-playbook.yml](example-playbook.yml).
```yaml
---
- name: "tmconfpy example playbook"
hosts: all
connection: httpapi
gather_facts: false

vars:
provider:
server: 192.0.2.245
server_port: 443
user: admin
password: admin # use vault!
validate_certs: yes
# map provider variables to collection v2 variables
ansible_host: "{{ provider.server }}"
ansible_user: "{{ provider.user }}"
ansible_httpapi_password: "{{ provider.password }}"
ansible_httpapi_port: "{{ provider.server_port }}"
ansible_network_os: f5networks.f5_bigip.bigip
ansible_httpapi_use_ssl: yes
ansible_httpapi_validate_certs: "{{ provider.validate_certs }}"
# the above is typically defined in a group_vars and host_vars and ansible-vault
# path to the configuration file on the BIG-IP
bigip_configfile: /config/bigip_user.conf

tasks:
- name: "Requirements Note"
ansible.builtin.debug:
msg: |
# This playbook requires the following:
# requirements.yml
collections:
# https://galaxy.ansible.com/ui/repo/published/f5networks/f5_bigip/
- name: f5networks.f5_bigip
type: galaxy
version: ">=3.0.0"
# https://galaxy.ansible.com/ui/repo/published/simonkowallik/tmconfpy/
- name: simonkowallik/tmconfpy
type: galaxy
version: ">=1.0.0"
- name: "Fetch {{ bigip_configfile }} in tabular format"
simonkowallik.tmconfpy.tmconf_get:
configfile: "{{ bigip_configfile }}"
format: tabular
register: tabular_config

# tabular format has 3 columns, object_path, object_name and the object itself.
# each entry in the tmconf file is a row.
- name: "Print {{ bigip_configfile }} in tabular format"
ansible.builtin.debug:
var: tabular_config.tmconf_tabular

# object format uses keys that represent the object_path and object_name. The value is the object itself.
- name: "Fetch {{ bigip_configfile }} in object format (default)"
simonkowallik.tmconfpy.tmconf_get:
configfile: "{{ bigip_configfile }}"
register: config

- name: "Print {{ bigip_configfile }} in object format (default)"
ansible.builtin.debug:
var: config.tmconf

- name: "Save tmconf to JSON file"
ansible.builtin.copy:
content: "{{ config.tmconf | to_nice_json }}"
dest: "./{{ bigip_configfile }}"

```
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,49 @@
ansible_network_os: f5networks.f5_bigip.bigip
ansible_httpapi_use_ssl: yes
ansible_httpapi_validate_certs: "{{ provider.validate_certs }}"

# the above is typically defined in a group_vars and host_vars and ansible-vault
# path to the configuration file on the BIG-IP
bigip_configfile: /config/bigip_user.conf

tasks:
- name: "Fetch bigip_user.conf tabular"
- name: "Requirements Note"
ansible.builtin.debug:
msg: |
# This playbook requires the following:
# requirements.yml
collections:
# https://galaxy.ansible.com/ui/repo/published/f5networks/f5_bigip/
- name: f5networks.f5_bigip
type: galaxy
version: ">=3.0.0"
# https://galaxy.ansible.com/ui/repo/published/simonkowallik/tmconfpy/
- name: simonkowallik/tmconfpy
type: galaxy
version: ">=1.0.0"
- name: "Fetch {{ bigip_configfile }} in tabular format"
simonkowallik.tmconfpy.tmconf_get:
configfile: /config/bigip_user.conf
configfile: "{{ bigip_configfile }}"
format: tabular
register: tabular_config

- name: "Print bigip_user.conf tabular"
# tabular format has 3 columns, object_path, object_name and the object itself.
# each entry in the tmconf file is a row.
- name: "Print {{ bigip_configfile }} in tabular format"
ansible.builtin.debug:
var: tabular_config.tmconf_tabular

- name: "Fetch bigip_user.conf"
# object format uses keys that represent the object_path and object_name. The value is the object itself.
- name: "Fetch {{ bigip_configfile }} in object format (default)"
simonkowallik.tmconfpy.tmconf_get:
configfile: /config/bigip_user.conf
configfile: "{{ bigip_configfile }}"
register: config

- name: "Print bigip_user.conf"
- name: "Print {{ bigip_configfile }} in object format (default)"
ansible.builtin.debug:
var: config.tmconf

- name: "Save tmconf to JSON file"
ansible.builtin.copy:
content: "{{ config.tmconf | to_nice_json }}"
dest: "./{{ bigip_configfile }}"
103 changes: 103 additions & 0 deletions docs/ANSIBLE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# tmconfpy - Ansible collection

## Purpose

tmconfpy as well as the tmconfpy ansible collection aim to make BIG-IP configurations more accessible by serializing the tmconf format to python data structures.

For more details about the relevant configuration files, data formats, tmconfpy and its ansible collection please have a look in the [documentation](https://simonkowallik.github.io/tmconfpy/).

## Installation

You can install the tmconfpy ansible collection either from [](Ansible Galaxy) or from github.

```shell
ansible-galaxy collection install simonkowallik.tmconfpy

ansible-galaxy collection install [email protected]:simonkowallik/tmconfpy.git#ansible_collections/simonkowallik/tmconfpy,main
```

In your `requirements.yml` file you can use both ways as well:

```yaml
---
- name: simonkowallik/tmconfpy
type: galaxy
version: 1.0.0

#- source: https://github.com/simonkowallik/tmconfpy.git#ansible_collections/simonkowallik/tmconfpy
# type: git
# version: main
```

## Example Playbook

```yaml
---
- name: "tmconfpy example playbook"
hosts: all
connection: httpapi
gather_facts: false

vars:
provider:
server: 192.0.2.245
server_port: 443
user: admin
password: admin # use vault!
validate_certs: yes
# map provider variables to collection v2 variables
ansible_host: "{{ provider.server }}"
ansible_user: "{{ provider.user }}"
ansible_httpapi_password: "{{ provider.password }}"
ansible_httpapi_port: "{{ provider.server_port }}"
ansible_network_os: f5networks.f5_bigip.bigip
ansible_httpapi_use_ssl: yes
ansible_httpapi_validate_certs: "{{ provider.validate_certs }}"
# the above is typically defined in a group_vars and host_vars and ansible-vault
# path to the configuration file on the BIG-IP
bigip_configfile: /config/bigip_user.conf

tasks:
- name: "Requirements Note"
ansible.builtin.debug:
msg: |
# This playbook requires the following:
# requirements.yml
collections:
# https://galaxy.ansible.com/ui/repo/published/f5networks/f5_bigip/
- name: f5networks.f5_bigip
type: galaxy
version: ">=3.0.0"
# https://galaxy.ansible.com/ui/repo/published/simonkowallik/tmconfpy/
- name: simonkowallik/tmconfpy
type: galaxy
version: ">=1.0.0"
- name: "Fetch {{ bigip_configfile }} in tabular format"
simonkowallik.tmconfpy.tmconf_get:
configfile: "{{ bigip_configfile }}"
format: tabular
register: tabular_config

# tabular format has 3 columns, object_path, object_name and the object itself.
# each entry in the tmconf file is a row.
- name: "Print {{ bigip_configfile }} in tabular format"
ansible.builtin.debug:
var: tabular_config.tmconf_tabular

# object format uses keys that represent the object_path and object_name. The value is the object itself.
- name: "Fetch {{ bigip_configfile }} in object format (default)"
simonkowallik.tmconfpy.tmconf_get:
configfile: "{{ bigip_configfile }}"
register: config

- name: "Print {{ bigip_configfile }} in object format (default)"
ansible.builtin.debug:
var: config.tmconf

- name: "Save tmconf to JSON file"
ansible.builtin.copy:
content: "{{ config.tmconf | to_nice_json }}"
dest: "./{{ bigip_configfile }}"

```
20 changes: 9 additions & 11 deletions CONFIG-FORMATS.md → docs/CONFIG-FORMATS.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ There are several relevant configuration files on F5 BIG-IP devices, here is a i

The tmconfpy ansible collection supports two formats to represent configurations, `object` (default) and `tabular`.

### object format

Type `object` basically means the configuration file is parsed as one big python dict. Of course a python dict can be serialized to JSON or YAML.

`object` example:
Expand All @@ -42,21 +44,17 @@ Type `object` basically means the configuration file is parsed as one big python
}
```

Type `tabular` returns a list of lists. It serializes each individual configuration object into a list with three entries `object_path` (`str`), `object_name` (`str`) and `object` (`dict`), each of the lists is then added to the main list of all objects.
### tabular format

Type `tabular` returns a list of lists. It serializes each individual configuration object into a list with three elements; `object_path` (`str`), `object_name` (`str`) and `object` (`dict`). Each of the lists is then added to the main list of all objects.

So `object_path`, `object_name` and `object` are the columns and each entry in the configuration file will be a row.

`tabular` example:

```json
[
[
"module path",
"object_name",
{ "description": "\"Object description\"", "property": "value" }
],
[
"module path",
"other_object_name",
{ "property": { "key": "value" } }
]
[ "module path", "object_name", { "description": "\"Object description\"", "property": "value" } ],
[ "module path", "other_object_name", { "property": { "key": "value" } } ]
]
```
Loading

0 comments on commit b2fa018

Please sign in to comment.