Skip to content

Instantly share code, notes, and snippets.

Avatar
🇺🇦

Gonéri Le Bouder goneri

🇺🇦
View GitHub Profile
View cloudtrail-trace-vm-creation.py
#!/usr/bin/env python3
import boto3
from datetime import datetime
client = boto3.client("cloudtrail")
import json
instances = {}
View vcenter-find-required-permissions.py
#!/usr/bin/env python3
# Identify the minimal subset of permission required for a given Ansible playbook
# License: GPLv3+
# Copyright: Gonéri Le Bouder <goneri@lebouder.net>
from pyVmomi import vim
from pyVim.connect import SmartConnect, SmartConnectNoSSL, Disconnect
import os
import subprocess
View ansible-venv.fish
#!/usr/bin/env fish
# License: GPLv3+
# Usage:
# To start a venv with the default python3 and Ansible devel:
# . ~/bin/ansible-venv.fish
#
# To start a venv with a specific version:
# . ~/bin/ansible-venv.fish 3.4 stable-2.9
# See: https://goneri.lebouder.net/2021/06/02/ansible-collections-and-venv/
View firewalld-list-zones
#!/bin/bash
for i in $(ls /sys/class/net/); do
echo -n "${i}: "
firewall-cmd --get-zone-of-interface=${i}
done
View test_venv.sh
#!/bin/bash
function test_venv() {
cmd=$1
venv_dir=$(mktemp -d)
tmp_dir=$(mktemp -d)
if ! $cmd ${venv_dir} > /dev/null 2>&1; then
return
@goneri
goneri / vcenter_curl_rest_api.sh
Last active Mar 16, 2022
vcenter_curl_rest_api.sh
View vcenter_curl_rest_api.sh
#!/bin/bash
set -x
server='https://vcenter.test'
password=$(crudini --get /tmp/inventory-vmware_rest 'vmware_rest:vars' 'vcenter_password')
session_id=$(curl -q --http1.1 -X POST -k -u "administrator@vsphere.local:${password}" ${server}/rest/com/vmware/cis/session|jq -r .value)
function get() {
path=$1
curl -ik -H vmware-api-session-id:${session_id} -X GET ${server}$path
echo ""
View gist:73e1452f8d28e24ee88c4e7e8323713c
sudo qemu-img convert -c -p -f qcow2 -O vmdk -o subformat=streamOptimized,compat6 ubuntu-2004.qcow2 ~/tmp/ubuntu-2004.vmdk-4
scp ~/tmp/ubuntu-2004.vmdk-4 root@datastore.test:/srv/share/vms/test_vm1
ssh root@esxi1.test vmkfstools -i /vmfs/volumes/rw_datastore/test_vm1/ubuntu-2004.vmdk-4 /vmfs/volumes/rw_datastore/test_vm1/ubuntu-2004.vmdk -d thin
ssh root@dataastore.test curl -o /srv/share/vms/fedora-35.vmdk-4 https://s3.us-east-2.amazonaws.com/ansible-team-cloud-images/fedora-35.vmdk-4
ssh root@esxi.test mkdir -p /vmfs/volumes/rw_datastore/test_vm1
ssh root@esxi1.test vmkfstools -i /vmfs/volumes/local/fedora-35.vmdk-4 /vmfs/volumes/rw_datastore/test_vm1/fedora-35.vmdk -d thin
View gist:92433ccf05d1e02773d47e7c1b5bc681
#!/bin/bash
job_id=$(uuidgen)
ansible_core_ci=$(cat ~/.ansible-core-ci.key)
curl -X PUT -H "Content-Type: application/json" --data '{"config": {"platform": "azure"}, "auth": {"remote": {"key": "'${ansible_core_ci}'", "nonce": null}}, "threshold": 1}' https://ansible-core-ci.testing.ansible.com/dev/azure/${job_id}| python -c 'import yaml, sys; print(yaml.dump(yaml.safe_load(sys.stdin), default_flow_style=False))' |tee session.yaml
View gist:6afd05397390cf5a0976f3611814949a
- name: Collect the list of the existing VM
vcenter_vm_info:
register: existing_vms
until: existing_vms is not failed
- name: Turn off the VM
vcenter_vm_power:
state: stop
vm: '{{ item.vm }}'
with_items: "{{ existing_vms.value }}"
@goneri
goneri / start_kind_in_vm.sh
Last active Jul 29, 2021
Start kind in a VM (Virt-Lightning)
View start_kind_in_vm.sh
!/bin/bash
set -eux
vl start fedora-34 --memory 2000 --name kind-vm
target=$(vl status|awk '/kind-vm/ {print $4}')
public_ip=$(vl status|awk '/kind-vm/ {print $4}'|sed 's,.\+@,,')
rc_file=/tmp/k8s_rc
ssh $target '
curl -L -o /tmp/kubectl "https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl"
chmod +x /tmp/kubectl