Skip to content

Instantly share code, notes, and snippets.

View markuman's full-sized avatar
🐧
Linux Only - fail fast, move on

Markus Bergholz markuman

🐧
Linux Only - fail fast, move on
  • Lekker Energie GmbH
  • Berlin
View GitHub Profile
cat /etc/ansible/hosts
localhost ansible_connection=local ansible_python_interpreter="/home/m/.local/bin/python3.7"
[vars:all]
ansible_python_interpreter="/home/m/.local/bin/python3.7"
import requests
from ansible.errors import AnsibleError, AnsibleParserError
from ansible.plugins.lookup import LookupBase
try:
from __main__ import display
except ImportError:
from ansible.utils.display import Display
display = Display()
- name: build ec2 list
set_fact:
amazon_ranges_list: "{{ amazon_ranges_list + [{'proto': 'all', 'cidr_ip': item, 'rules_desc': 'AMAZON'}]}}"
with_items: "{{ amazon_ranges }}"
var1:
- 1
- 2
- 3
needed:
- id: 1
desc: "bla"
prot: "ja"
- id: 2
$ make tests-py3
bin/ansible-test units -v --python 3.7
Unit test with Python 3.7
Run command: pytest --boxed -r a -n auto --color yes --junit-xml test/results/junit/python3.7-units.x ...
/home/m/git/upstream-ansible/markuman-ansible/test/runner/injector/pytest:4: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
import imp
ERROR: usage: pytest.py [options] [file_or_dir] [file_or_dir] [...]
pytest.py: error: unrecognized arguments: --boxed -n test/units/
inifile: /home/m/git/upstream-ansible/markuman-ansible/tox.ini
rootdir: /home/m/git/upstream-ansible/markuman-ansible
vars:
instance_id: i-1234564542134
cpu_credit_specification: unlimited
security_group:
- default
- someother
tasks:
- name: try to modify the ec2 instance
- name: check required vars empty
fail: msg="Variable '{{ item }}' is empty"
when: vars[item] == ""
with_items: "{{ required_vars }}"
- name: check required vars null
fail: msg="Variable '{{ item }}' is null"
when: vars[item] is none
with_items: "{{ required_vars }}"
---
- hosts: localhost
connection: local
gather_facts: False
tasks:
- name: Launch the new EC2 Instance
ec2:
...
plugin: aws_ec2
regions:
- eu-central-1
- name: attach sg to instances
ec2_instance:
state: present
region: eu-central-1
instance_ids:
- i-03cdeb86644457562
security_groups:
- sg-e169308a # default
- sg-888e07e5 # something
- sg-abbd4ac1 # public smtp