Skip to content

Instantly share code, notes, and snippets.

View noonedeadpunk's full-sized avatar

Dmitriy Rabotyagov noonedeadpunk

View GitHub Profile
@noonedeadpunk
noonedeadpunk / timedelta.yml
Last active April 20, 2023 11:23
Calculate a difference in time from current one using plain ansible
- hosts: localhost
tasks:
- name:
vars:
# Should be in format supported by to_time_unit filer:
# https://docs.ansible.com/ansible/latest/collections/community/general/docsite/filter_guide_working_with_times.html
date_difference: "6month"
# Should be in format of python strftime
# https://docs.python.org/3/library/datetime.html#strftime-and-strptime-format-codes
result_format: '%Y-%m-%d %H:%M'
@noonedeadpunk
noonedeadpunk / current_overcommit_from_nova.py
Last active September 28, 2022 15:26
Get data about current overcommit per hypervisor from OpenStack
#!/usr/bin/python3
import os
from openstack import connect
from pprint import pprint
def main():
conn = connect()
allocation_ratios = {
hv.name: {
"CPU": round(hv.vcpus_used / hv.vcpus, 2),
@noonedeadpunk
noonedeadpunk / README.rst
Last active August 6, 2020 13:47
Mattermost upgrade

In order to use that script, there are some pre-requirements:

1 You're supposed to move content of mattermosts' special directories (config, logs, plugins, client/plugins, and data) to $mattermost_special_dir

2 You should make /opt/mattermost to be a symlink to the real mattermost directory - /opt/mattermost-XX.XX.X/mattermost, where XX.XX.X is current MM version

3 For MM upgrade just run ./upgrade_mattermost.sh YY.YY.Y, where YY.YY.Y is new MM version to be run.

@noonedeadpunk
noonedeadpunk / diff
Created June 24, 2020 15:58
SPICE console ctrl+alt+del button
/usr/share/spice-html5/spice_auto.html:
<div id="login">
<span class="logo">SPICE</span>
+ <div class="spice-send-ctrl-alt-del">
+ <button type="button" onclick="sendCtrlAltDel()">
+ Send Ctrl-Alt-Delete
+ </button>
+ </div>
</div>
@noonedeadpunk
noonedeadpunk / add_1password_server.yml
Created May 21, 2020 19:10
1Password add server and ipmi playbook
- name: Reset password
hosts: "{{ host }}"
vars:
ipmi_password: "{{ lookup('password', '/tmp/' ~ inventory_hostname ~ '_ipmipassword chars=ascii_letters,digits length=16') }}"
system_password: "{{ lookup('password', '/tmp/' ~ inventory_hostname ~ '_rootpassword chars=ascii_letters,digits,-,_,! length=20') }}"
tasks:
- name: install ipmitool
package:
name: ipmitool
state: present
@noonedeadpunk
noonedeadpunk / ipa-client-install.yml
Last active May 5, 2020 11:07
Add hosts to ipa server
---
- name: Install and configure ipa-client
hosts: "{{ hosts }}"
tasks:
- name: Install ipa-client package
package:
name: "{{ (ansible_os_family == 'Debian') | ternary('freeipa-client', 'ipa-client') }}"
state: installed
register: ipa_install
- name: Run configuration command
---
- name: Sync clock with chrony
hosts: all
tasks:
- name: disable ntp
service:
name: ntp
state: stopped
enabled: false
failed_when: false
---
- name: Create users
hosts: all
vars:
group: mygroup
user: myuser
keys_path: ./ssh_keys
tasks:
- name: Create group
group:
---
- hosts: compute_hosts
gather_facts: true
vars:
# We leave 1 full CPU as a spare one for hypervisor
cpu_spare: "{{ ansible_processor_threads_per_core }}"
cpu_quota: "{{ ansible_processor_vcpus * 100 - cpu_spare * 100 }}%"
tasks:
- name: Update machine.slice
blockinfile:
@noonedeadpunk
noonedeadpunk / gist:4a22b2dcc3b22fcc295445ed18c66247
Last active December 27, 2019 16:19
Drop rabbitmq queues without consumers
### Classis FOR ###
vhost="/"; for queue in `rabbitmqctl list_queues name consumers -p $vhost --formatter csv`; do name=`echo $queue | cut -d "," -f 1 | tr -d '"'`; consumers=`echo $queue | cut -d "," -f 2 | tr -d '"'`; if [[ "$consumers" == "0" ]]; then rabbitmqctl delete_queue $name -p $vhost ; fi; done
### Faster XARGS ###
vhost="/"; rabbitmqctl list_queues name consumers -p $vhost --formatter csv | xargs -P 20 -I {} env vhost=$vhost bash -c 'name=$(echo {} | cut -d "," -f 1); consumers=$(echo {} | cut -d "," -f 2); if [[ "$consumers" != "0" ]]; then rabbitmqctl delete_queue $name -p $vhost ; fi'