ansible when with_items – ignore one group

I’m setting up icinga & using https://github.com/Icinga/icinga2-ansible

However, it’s putting a config on the icinga server to monitor itself, which is causing

information/ConfigCompiler: Compiling config file: /etc/icinga2/conf.d/pmlgra-03.domain.conf
information/ConfigCompiler: Compiling config file: /etc/icinga2/conf.d/satellite.conf
information/ConfigCompiler: Compiling config file: /etc/icinga2/conf.d/services.conf
information/ConfigCompiler: Compiling config file: /etc/icinga2/conf.d/slave-6.domain.conf
information/ConfigCompiler: Compiling config file: /etc/icinga2/conf.d/templates.conf
information/ConfigCompiler: Compiling config file: /etc/icinga2/conf.d/timeperiods.conf
information/ConfigCompiler: Compiling config file: /etc/icinga2/conf.d/users.conf
critical/config: Error: Object 'dmlici-02.domain' of type 'Host' re-defined: in /etc/icinga2/conf.d/hosts.conf: 18:1-18:20; previous definition: in /etc/icinga2/conf.d/dmlici-02.domain.conf: 2:1-2:35
Location: in /etc/icinga2/conf.d/hosts.conf: 18:1-18:20
/etc/icinga2/conf.d/hosts.conf(16):  */
/etc/icinga2/conf.d/hosts.conf(17): 

So this ansible with_items and when fixed it. Note: My icinga server is in a group called icinga

- name: Copy Host Definitions
  template: src=hosts_template.j2
            dest={{ icinga2_hosts_dir }}/{{ hostvars[item]['inventory_hostname'] }}.conf
            owner=root 
            group=root 
            mode=0644
  with_items: groups['all']
  when: "'icinga' not in hostvars[item]['group_names']"

osx display nameserver via cmd line

[user@macmini ~]#  scutil --dns | grep 'nameserver\[[0-9]*\]'
  nameserver[0] : 209.222.18.222
  nameserver[1] : 209.222.18.218
  nameserver[0] : 209.222.18.222
  nameserver[1] : 209.222.18.218
  nameserver[0] : 209.222.18.222
  nameserver[1] : 209.222.18.218

Rename files to no longer have spaces in names

I was having a problem where the for loop split files with spaces into multiple lines.

jamess@greenscar Ace_Of_Base_-_Star_Mark_Greatest_Hits_(2008)_-_flac $ for i in `find . -type f -name "* *"`; do  echo "$i"; rename 's/\ /_/g' "$i"; done;
./CD_1/01.Happy
Nation.flac
./CD_1/02.All
That
She
Wants.flac
./CD_1/03.The
Sign.flac
./CD_1/04.Wheel
Of
Fortune.flac
...

Then I found the IFS

IFS=$'\n'; for i in `find . -type f -name '* *.flac'`; do  echo "$i"; rename 's/\ /_/g' "$i"; done; unset IFS

And she works.

jamess@greenscar sorted $ IFS=$'\n'; for i in `find . -type f -name '* *.flac'`; do  echo "$i"; rename 's/\ /_/g' "$i"; done; unset IFS
./ACDC/2008_-_Warning!_High_Voltage_-_Greatest_Hits/CD1_-_Brian_Johnson/01 - Thunderstruck.flac
./ACDC/2008_-_Warning!_High_Voltage_-_Greatest_Hits/CD1_-_Brian_Johnson/02 - Shoot To Thrill.flac
./ACDC/2008_-_Warning!_High_Voltage_-_Greatest_Hits/CD1_-_Brian_Johnson/03 - Big Gun.flac
./ACDC/2008_-_Warning!_High_Voltage_-_Greatest_Hits/CD1_-_Brian_Johnson/04 - Fire Your Guns.flac
./ACDC/2008_-_Warning!_High_Voltage_-_Greatest_Hits/CD1_-_Brian_Johnson/05 - You Shook Me All Night Long.flac
./ACDC/2008_-_Warning!_High_Voltage_-_Greatest_Hits/CD1_-_Brian_Johnson/06 - Heatseeker.flac
./ACDC/2008_-_Warning!_High_Voltage_-_Greatest_Hits/CD1_-_Brian_Johnson/07 - Back In Black.flac
./ACDC/2008_-_Warning!_High_Voltage_-_Greatest_Hits/CD1_-_Brian_Johnson/08 - Who Made Who.flac
./ACDC/2008_-_Warning!_High_Voltage_-_Greatest_Hits/CD1_-_Brian_Johnson/09 - Hard As A Rock.flac
./ACDC/2008_-_Warning!_High_Voltage_-_Greatest_Hits/CD1_-_Brian_Johnson/10 - Hells Bells.flac
./ACDC/2008_-_Warning!_High_Voltage_-_Greatest_Hits/CD1_-_Brian_Johnson/11 - Moneytalks.flac
...

ffmpeg on osx to convert flac to Apple Lossless (’cause itune$ won’t support flac)

References:
http://www.renevolution.com/how-to-install-ffmpeg-on-mac-os-x/
http://sound.stackexchange.com/questions/26633/free-batch-conversion-from-flac-to-apple-lossless-alac

  1. Install brew
  2. Install ffmpeg

    user@box dir $ brew install ffmpeg --with-fdk-aac --with-ffplay --with-freetype --with-frei0r --with-libass --with-libvo-aacenc --with-libvorbis --with-libvpx --with-opencore-amr --with-openjpeg --with-opus --with-rtmpdump --with-schroedinger --with-speex --with-theora --with-tools
    
  3. Convert all flac files

    for f in `find . -type f -name *.flac`; do ffmpeg -i "$f"  -vf "crop=((in_w/2)*2):((in_h/2)*2)" -c:a alac "${f%.flac}.m4a"; done
    

Self signed root cert with multdomain cert & sha-256

Self signed root cert with multdomain cert & sha-256
—-
Prep by creating dirs

mkdir -p /Users/user/Documents/multidomain/root_cert/private/
mkdir -p /Users/user/Documents/multidomain/star_devwest_foobar_com/

Root Certs
Create Root Key

user@greenscar root_cert $ openssl req \
-x509 \
-new \
-nodes \
-days 3650 \
-newkey rsa:2048 \
-sha256 \
-subj "/C=US/ST=California/L=San\ Jose/O=Cloud\ Cruiser\ Inc./CN=*.foobar.com" \
-keyout /Users/user/Documents/multidomain/root_cert/private/root_ca.key

Create Self Signed Root Cert

openssl req \
-x509 \
-sha256 \
-new \
-nodes \
-days 3650 \
-key /Users/user/Documents//SHA-256/root_cert/private/root_ca.key \
-subj "/C=US/ST=California/L=San\ Jose/O=Cloud\ Cruiser\ Inc./CN=*.foobar.com" \
-out /Users/user/Documents/multidomain/root_cert/root_ca.crt      

————————————————
Per environment certs
CD to cert dir

user@greenscar star_devwest_foobar_com $ cd /Users/user/Documents/multidomain/star_devwest_foobar_com

Create Private Key

openssl genrsa \
-out /Users/user/Documents/multidomain/star_devwest_foobar_com/star_devwest_foobar_com.key \
2048

Generate CSR

user@greenscar SHA-256 $ cd /Users/user/Documents/multidomain/star_devwest_foobar_com
openssl req -new \
-config /Users/user/Documents/multidomain/foobar.com.cnf \
-key /Users/user/Documents/multidomain/star_devwest_foobar_com/star_devwest_foobar_com.key \
-sha256 \
-out /Users/user/Documents/multidomain/star_devwest_foobar_com/star_devwest_foobar_com.csr \
-subj "/C=US/ST=California/L=San\ Jose/O=FooBar\ Inc./CN=devwest.foobar.com" 

Create files with all domains you want supported

echo "subjectAltName=DNS:devwest.foobar.com,DNS:*.devwest.foobar.com">cert_extensions

Checkout our new CSR
openssl req -text -noout -in star_devwest_foobar_com.csr

Sign cert via self signed root cert

openssl x509 -req \
-in /Users/user/Documents/multidomain/star_devwest_foobar_com/star_devwest_foobar_com.csr \
-CA /Users/user/Documents/multidomain/root_cert/root_ca.crt \
-CAkey /Users/user/Documents/multidomain/root_cert/private/root_ca.key \
-CAcreateserial \
-sha256 \
-extfile cert_extensions \
-out /Users/user/Documents/multidomain/star_devwest_foobar_com/star_devwest_foobar_com.crt \
-days 3650

Upload Cert

user@greenscar star_devwest_foobar_com $ aws iam delete-server-certificate --server-certificate-name star_devwest_foobar_com
user@greenscar star_devwest_foobar_com $  aws iam upload-server-certificate --server-certificate-name star_devwest_foobar_com  --certificate-body file://star_devwest_foobar_com.crt --private-key file://star_devwest_foobar_com.key

Coolscan 4000 on Windows 7

My Nikon Coolscan 4000 is the best thing I ever purchased, allowing me to scan 20 years of negatives high quality into my computer. However, with Nikon discontinuing support after Windows XP, when I found some negatives I had not scanned, I was quite upset. I was then lucky enough to run into this great instruction set: http://www.colorneg.com/XP/Vista/7/driver-for-64-Bit-Windows/Coolscan/Nikon-Scan/

To quote (in case his site ever goes down):

To get started download Nikon Scan 4.03 for Windows Vista 32 bit. Install the software on your 64 bit Windows 7 or Windows 8. Next we need to create a driver for your scanner that is 64 bit compatible. To do so create a new folder anywhere on your system you feel comfortable with. Depending on the scanner model you own copy the two files “NKScnUSD.dll” and “Nks1394.inf” or respectively “NksUSB.inf” which are to be found under “C:\Program Files (x86)\Common Files\Nikon\Driver\Scan1394” or “C:\Program Files (x86)\Common Files\Nikon\Driver\ScanUSB” into that folder. Open “Nks1394.inf” or respectively “NksUSB.inf” in a text editor of your choice to replace its contents. To do so click into the text box below and press Ctrl+A followed by Ctrl+C to copy the code. Next enter your text editor and press Ctrl+A followed by Ctrl+V to paste the code into the *.inf file.

;========================= Begin of scanners.inf ===============================
; scanners.inf - Windows Still Image Setup File
[Version]
Signature="$CHICAGO$"
Class=Image
ClassGUID={6bdd1fc6-810f-11d0-bec7-08002be2092f}
Provider=%Provider%
DriverVer=1/1/2009,1.0
[Manufacturer]
%Mfg%=Models,ntamd64
[Models]
; USB scanners
"Nikon LS-40" = USBScanner,USB\Vid_04b0&Pid_4000
"Nikon LS-50" = USBScanner,USB\Vid_04b0&Pid_4001
"Nikon LS-5000" = USBScanner,USB\Vid_04b0&Pid_4002
; Firewire scanners
"Firewire Scanner" = SBP2Scanner,SBP2\GenScanner
"Nikon SUPER COOLSCAN 4000 ED" = SBP2Scanner_NIKON,SBP2\NIKON___&LS-4000_ED______&CMDSETID104D8
"Nikon SUPER COOLSCAN 8000 ED" = SBP2Scanner_NIKON,SBP2\NIKON___&LS-8000_ED______&CMDSETID104D8
"Nikon SUPER COOLSCAN 9000 ED" = SBP2Scanner_NIKON,SBP2\NIKON___&LS-9000_ED______&CMDSETID104D8
;---------------- Duplicated from [Models]
[Models.ntamd64]
; USB scanners
"Nikon LS-40" = USBScanner,USB\Vid_04b0&Pid_4000
"Nikon LS-50" = USBScanner,USB\Vid_04b0&Pid_4001
"Nikon LS-5000" = USBScanner,USB\Vid_04b0&Pid_4002
; Firewire scanners
"Firewire Scanner" = SBP2Scanner,SBP2\GenScanner
"Nikon SUPER COOLSCAN 4000 ED" = SBP2Scanner_NIKON,SBP2\NIKON___&LS-4000_ED______&CMDSETID104D8
"Nikon SUPER COOLSCAN 8000 ED" = SBP2Scanner_NIKON,SBP2\NIKON___&LS-8000_ED______&CMDSETID104D8
"Nikon SUPER COOLSCAN 9000 ED" = SBP2Scanner_NIKON,SBP2\NIKON___&LS-9000_ED______&CMDSETID104D8
;---------------- USBScanner -------------------------
[USBScanner]
Include=sti.inf
Needs=STI.USBSection
SubClass=StillImage
DeviceType=1
DeviceSubType=1
Capabilities=0
[USBScanner.Services]
Include=sti.inf
Needs=STI.USBSection.Services
;---------------- SBP2Scanner ------------------------
[SBP2Scanner]
Include=sti.inf
Needs=STI.SBP2Section
SubClass=StillImage
DeviceType=1
DeviceSubType=2
Capabilities=0
[SBP2Scanner_NIKON]
Include=sti.inf
Needs=STI.SBP2Section
SubClass=StillImage
DeviceType=1
DeviceSubType=2
Capabilities=0
AddReg=NK1394SCN.AddReg
CopyFiles=NK1394SCN.CopyUSDFiles
[SBP2Scanner.Services]
Include=sti.inf
Needs=STI.SBP2Section.Services
[SBP2Scanner_NIKON.Services]
Include=sti.inf
Needs=STI.SBP2Section.Services
[NK1394SCN.AddReg]
HKR,,HardwareConfig,1,2
HKR,,DevLoader,,*NTKERN
HKR,,NTMPDriver,,"scsiscan.sys"
HKR,DeviceData,ICMProfile,1,0,0
HKR,,USDClass,,"{07C71AC0-FA90-11d3-B409-00C04F87578E}"
HKCR,CLSID\{07C71AC0-FA90-11d3-B409-00C04F87578E},,,"Nikon STI USD"
HKCR,CLSID\{07C71AC0-FA90-11d3-B409-00C04F87578E}\InProcServer32,,,%11%\NKSCNUSD.DLL
HKCR,CLSID\{07C71AC0-FA90-11d3-B409-00C04F87578E}\InProcServer32,ThreadingModel,,"Both"
[SourceDisksNames]
1=%DiskName%,,
[SourceDisksFiles]
NKSCNUSD.dll=1
[DestinationDirs]
NK1394SCN.CopyUSDFiles=11
[NK1394SCN.CopyUSDFiles]
NKSCNUSD.dll,,,32
;-----------------------------------------------------
[Strings]
Provider="steelchn@gmail.com"
Mfg="DIY Software"
DiskName="Nikon Scan 4 CD-ROM"
;========================= End of scanners.inf ===============================

Save the file. Turn on your scanner and connect it to your computer. Go to Window’s Control Panel and select System > Device Manager. On Windows 8 first follow the instructions at the end of this page which eventually take you to the Device Manager, too.
On Device Manager’s device list your scanner is located in the imaging devices category. The corresponding entry will be named “Firewire Scanner” or something like that. Right click this entry and select “Update Driver Software”. Next select “Browse My Computer” and specify the folder you created before. A warning message will be displayed which you will need to disregard, telling the system to go on with the installation. Afterwards your scanner should be listed under its correct name like “Nikon SUPER COOLSCAN 8000 ED”. When you start Nikon Scan 4.03 after doing this it will detect your scanner and you should be good to go.

boto and load autoscaling groups

In boto, get_all_groups has a max return of 100. to get past that, you use tokens:

asconn = boto.ec2.autoscale.connect_to_region(self.region_name)
# This will load all groups.
# Source: http://stackoverflow.com/questions/29317526/how-can-i-retrieve-more-than-50-autoscaling-groups-via-python-boto
all_groups = []
rs = asconn.get_all_groups()
all_groups.extend(rs)
while rs.next_token:
    rs = asconn.get_all_groups(next_token=rs.next_token)
    all_groups.extend(rs)
for asg in all_groups:
    print self.stack_name + " = " + asg.name