Skip to content

Instantly share code, notes, and snippets.

@agaffney
agaffney / gist:a21a80e7297788fc9978
Created September 11, 2015 21:55
nginx+lua magic to allow "docker seach" to work with a V2.1 docker registry
location /v1/search {
content_by_lua '
local cjson = require "cjson"
local args = ngx.req.get_uri_args()
local query = args["q"]
-- Create structure for V1 search endpoint output
local output = { ["num_results"] = 0, ["query"] = query, ["results"] = {} }
-- Fetch data from V2 catalog endpoint
local res = ngx.location.capture("/v2/_catalog")
-- Parse JSON and iterate over it
@agaffney
agaffney / ipaddress.rb
Created October 1, 2015 19:17
Custom ipaddress fact that ignores Docker (and other) interfaces
# The builtin ipaddress fact is very naive and will pick the IP address of the
# first (alphabetically) interface. This fact changes that behavior and only
# grabs the IP off an interface matching /^(eth|bond|vlan)\d/. This excludes
# interfaces types such as TUN, bridges, and Docker.
Facter.add("ipaddress") do
has_weight 100
setcode do
# This allows the fact to work from the commandline
begin
Facter.interfaces
@agaffney
agaffney / gist:9807fe04f4a19263392cb340b780dcaa
Created May 9, 2018 12:37
Simple example for composing complex vars by generating YAML using an inline template
---
- hosts: localhost
gather_facts: no
tasks:
- name: do some stuff
vars:
temp_var: |
{% for i in range(1, 5) %}
- {{ i }}
{% endfor %}
@agaffney
agaffney / source_env_vars.yml
Last active October 9, 2018 15:24
Ansible tasks to source remote file and return resulting env vars
- name: Source file and return env vars
shell: >
. /path/to/foo.env;
{{ ansible_python_interpreter | default('python') }} -c
'from __future__ import print_function; import os, json; print(json.dumps(dict(os.environ)))'
register: source_env_vars_output
- name: Create var from JSON
set_fact:
source_env_vars: '{{ source_env_vars_output.stdout | from_json }}'
- name: whatever
vars:
tmp_ports: |
- "20:20"
- "21:21"
{% for x in range(21100, 21111) %}
- "{{ x }}:{{ x }}"
{% endfor %}
docker_container:
...
@agaffney
agaffney / gist:0429ccc3dce6fbc5cf91ae3851b8a81c
Last active November 9, 2022 18:49
Include per-host list of roles
tasks:
- include_role:
name: '{{ host_role.name | default(host_role) }}'
tasks_from: '{{ host_role.tasks_from | default("main") }}'
apply:
tags:
- '{{ host_role.name | default(host_role) }}'
loop: '{{ host_roles }}'
loop_control:
loop_var: host_role
@agaffney
agaffney / foo.yml
Last active November 18, 2019 15:07
Example of installing a role from Galaxy and using it in the same play
- hosts: localhost
gather_facts: no
vars:
test_role: grog.debug-variable
tasks:
- command: ansible-galaxy install -p {{ playbook_dir }}/roles {{ test_role }}
- include_role:
name: '{{ test_role }}'
@agaffney
agaffney / gist:679ece1117f6e49cffe086846ec9bb2c
Last active December 14, 2022 12:56
Building/installing AWX for ARM64

NOTE: it seems that somebody else beat me to this, so I'm not going to finish this

https://qiita.com/ussvgr/items/81b88653b2845b0f1bea

Prerequisites:

  1. An ARM64 machine with Ansible and Docker installed to build the images on. This doesn't necessarily need to be the same machine that you're going to deploy AWX on. Considering using something like an AWS Graviton2-based EC2 instance to cut down on image build time
  2. A Docker registry to push the custom images to
  3. A Kubernetes cluster on ARM64 to deploy on