Skip to content

Instantly share code, notes, and snippets.

@tadeboro
tadeboro / playbook.yaml
Created September 23, 2020 15:58
with_flattened test
---
- hosts: localhost
gather_facts: false
tasks:
- name: Test
shell: echo {{ item }}
with_flattened:
- [ a, b, c ]
- [ d, e ]
@tadeboro
tadeboro / input.j2
Created September 11, 2020 09:28
Templatng NGINX config
server {
{% for location in nginx_extra_basic_location_options %}
{{ location }};
{% endfor %}
}
@tadeboro
tadeboro / demo.sh
Created September 3, 2020 19:12
ansible-argspec-gen demo
# Installation
python3 -m venv venv
. venv/bin/activate
pip install ansible-argspec-gen[base]
# Dry run with diagnostics
ansible-argspec-gen --diff --dry-run sample.py
echo $? # Will report back 1
# Perform changes
@tadeboro
tadeboro / ansible-output.txt
Created August 2, 2020 20:27
ansible-test units output using pytest 6.0.1
$ ansible-test units --python 3.8 tests/unit/modules/test_asset.py
WARNING: PyYAML will be slow due to installation without libyaml support for interpreter: /home/tadej/xlab/sensu/venvt/bin/python
Unit test with Python 3.8
================================================= test session starts =================================================
platform linux -- Python 3.8.3, pytest-6.0.1, py-1.9.0, pluggy-0.13.1
rootdir: /home/tadej/xlab/sensu/ansible_collections/sensu/sensu_go/tests/unit/modules, configfile: ../../../../../../venvt/lib64/python3.8/site-packages/ansible_test/_data/pytest.ini
plugins: xdist-1.34.0, forked-1.3.0, mock-3.2.0
gw0 [0] / gw1 [0] / gw2 [0] / gw3 [0] / gw4 [0] / gw5 [0] / gw6 [0] / gw7 [0]
======================================================= ERRORS ========================================================
@tadeboro
tadeboro / test__set_cwd.py
Created May 8, 2020 22:00
Testing AnsibleModule._set_cwd method
# -*- coding: utf-8 -*-
# (c) 2020, Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
import pytest
@tadeboro
tadeboro / setup.sh
Created April 28, 2020 11:01
Test setup for community.vmware collection
#!/bin/bash
mkdir vmware && cd vmware
mkdir -p collections/ansible_collections/community
git clone \
--depth=1 \
https://github.com/ansible-collections/vmware.git \
collections/ansible_collections/community/vmware
@tadeboro
tadeboro / test.sh
Created March 27, 2020 11:50
LOcal git clone
#!/bin/bash
rm -rf x.git y
git init --bare x.git
git clone x.git y
cd y
echo bla > bla.txt
@tadeboro
tadeboro / playbook.yaml
Created March 25, 2020 09:46
Making sure all lines match certain regex
---
- name: Test
hosts: localhost
gather_facts: false
tasks:
- name: Dummy data
shell: echo -e "1 a\n1 b\n1 c\n"
register: result
$ ansible-test units tests/unit/test_x.py
...
========================================== FAILURES ===========================================
________________________________________ test_my_stuff ________________________________________
[gw0] linux -- Python 3.7.6 /tmp/python-8s1dwmns-ansible/python
def test_my_stuff():
> assert dict(a=3) == dict(b=2)
E AssertionError
tests/unit/test_x.py:2: AssertionError
@tadeboro
tadeboro / redfish-debug.md
Last active August 1, 2019 07:56
Manually inspecting Redfish API responses

Redfish API debugging

Debugging the Redfish API is relatively easy since JSON is at least partially human-readable (programmer-readable maybe? ;).

Manually inspecting Redfish responses

Inspect the Redfish API responses using curl is relatively simple. We start by running this: