Skip to content

Instantly share code, notes, and snippets.

@tadeboro
tadeboro / playbook.yaml
Created Sep 23, 2020
with_flattened test
View playbook.yaml
---
- hosts: localhost
gather_facts: false
tasks:
- name: Test
shell: echo {{ item }}
with_flattened:
- [ a, b, c ]
- [ d, e ]
@tadeboro
tadeboro / input.j2
Created Sep 11, 2020
Templatng NGINX config
View input.j2
server {
{% for location in nginx_extra_basic_location_options %}
{{ location }};
{% endfor %}
}
@tadeboro
tadeboro / demo.sh
Created Sep 3, 2020
ansible-argspec-gen demo
View demo.sh
# 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 Aug 2, 2020
ansible-test units output using pytest 6.0.1
View ansible-output.txt
$ 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
Testing AnsibleModule._set_cwd method
View test__set_cwd.py
# -*- 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 Apr 28, 2020
Test setup for community.vmware collection
View setup.sh
#!/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 Mar 27, 2020
LOcal git clone
View test.sh
#!/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 Mar 25, 2020
Making sure all lines match certain regex
View playbook.yaml
---
- name: Test
hosts: localhost
gather_facts: false
tasks:
- name: Dummy data
shell: echo -e "1 a\n1 b\n1 c\n"
register: result
View test-output.txt
$ 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 Aug 1, 2019
Manually inspecting Redfish API responses
View redfish-debug.md

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: