Skip to content

Instantly share code, notes, and snippets.

@AnneTheAgile
Last active April 25, 2018 05:00
Show Gist options
  • Save AnneTheAgile/5e6666bd2e2c25890e1e to your computer and use it in GitHub Desktop.
Save AnneTheAgile/5e6666bd2e2c25890e1e to your computer and use it in GitHub Desktop.
---
# FILE: talk-battle-ansi-config
# README: Prepare a mac 10.9 machine for running battleschool by ensuring a config file/folder exists.
# USAGE: $ ansible-playbook -i ansinv ansiboot.yml # Where ansinv= Your inventory file; ansiboot.yml= This script.
# PREREQ:
# $ curl -L THIS-URL > ~/.battleschool/config.yml # TIP-Bash-Curl: L: If location redirects, go there instead.
# $ ansible all -m ping # Test that the inventory file exists and ansible works with local host.
# $ ansible workstation -m ping -i ansinv # Test that the given inventory file contains 'workstation'.
# NEXT: $ battle --ask-sudo-pass --config-file=/Users/YOURUSER/.battleschool/config.yml # Config is created by this script.
# []TODO- Ansible-Battle; IDK why Tilde is not accepted to find path for config file - especially given it defaults ok.
# URL: As of 2014-08-23S.
# https://gist.githubusercontent.com/AnneTheAgile/5e6666bd2e2c25890e1e/raw/a166f7ed2a27ea71cdca806dcab$
# https://gist.github.com/AnneTheAgile/5e6666bd2e2c25890e1e
# FUTURE: []TODO- Add Bash wrapper to get this URL content and run the [usage] step. This is how brew.sh's one-liner works.
- hosts: workstation
vars:
SSHPWD: "{{ lookup('env','MY_PWD') }}"
# TIP-Bash-Env: Put Secret passwords (use LastPass) in environment variables, ~/.bashrc. $ export MY_PWD="aSecret"
# TODO-SSH: This section is for creating SSH keys during bootstrap-2.
tasks:
- name: "BattleSchool: Create Hidden Dot Folder for config files - ~/.battleschool/."
file: path=~/.battleschool state=directory
# TODO-Ansible: IDK when to / not use shell vs command module. Bash flavor may matter.
# TIP-Ansible-Yml: Colon in Name cannot be unquoted.
- name: "BattleSchool: Create Empty Configuration file for bootstrap initialization - ~/.battleschool/config.yml."
get_url: url=https://gist.githubusercontent.com/AnneTheAgile/071ce60cc5205b133db4/raw/3a5b9f3848c00ede0aa8aa1a435ba1eccf7888fc/talk-battle-config-empty.yml
dest=~/.battleschool/config.yml
# TIP-Battle: Original author's config.yml includes numerous things; https://db.tt/aG2uyydU
# TIP-Ansible: Use only get_url, not curl nor git module for gist text files.
- name: "BattleSchool: Apply correct permissions to config file - ~/.battleschool/config.yml."
file: path=~/.battleschool/config.yml state=file mode=755
# TIP-Bash: chmod = 751 => owner=rwx, all others=rx.
# TIP-Battle: Config file must be readable and executable. => Updt; Maybe X-only is ok without Tilde.
# TIP-Bash: Chmod's numeric equivalents of text directives. URL: http://www.onlineconversion.com/html_chmod_calculator.htm
@AnneTheAgile
Copy link
Author

OSX Add Terminal to the Dock

1.[] How to as of 2010.
http://krypted.com/mac-os-x/adding-objects-to-the-dock/
Ex. Add an app;
defaults write com.apple.dock persistent-apps -array-add ‘tile-datafile-data_CFURLString/Applications/Microsoft Office 2008/Microsoft Word_CFURLStringType0’
http://code.google.com/p/dockutil
or local or traditional mcx.
or the jamf binary (if you use the casper suite for management).
This will add iSync.app ( Or any app – just change path to what you want ) to the dock, Make sure to run as current console user in ARD and that users are logged in
defaults write com.apple.dock persistent-apps -array-add “tile-datafile-data_CFURLString/Applications/iSync.app/_CFURLStringType0″;
to refresh dock:
killall -HUP Dock (run as root in ARD)
lucidsystems April 4, 2012 - 2:45 am | Permalink
You may also be interested in additemtodock : http://www.lucidsystems.tk/tools/additemtodock/
2.[] GUI Preferences for the Dock, with Defaults write equivalents.
http://www.tekrevue.com/tip/the-complete-guide-to-customizing-mac-os-xs-dock-with-terminal/
3.[] AppleScript to add a Terminal Dock icon, even one with special command.
http://superuser.com/questions/260594/osx-add-dock-icon-for-dedicated-terminal-command
tell application "Terminal" to do script "mutt"
Save as application anywhere you want, then drag from there to the Dock.
4.[] DMG installer get from MacStore, normally invisible ; $2 app and a writeup about it.
http://jacobsalmela.com/tag/automation/
http://jacobsalmela.com/product/save-app-store-pkgs/
5.[] Login to GUI via CLI
https://github.com/jacobsalmela/login-user-to-gui-via-cli
Simulates keystrokes to log a user into the GUI from the login window.
This is useful in computer labs where you may need to log in a user to test out software or settings. Instead of typing in usernames/passwords manually at each computer, just send one of the commands via ARD and log them all in at once!
How it Works
OS X has access for assistive devices, which allows buttons to be pressed and keystrokes to be simulated. These features can be used via AppleScript GUI Scripting.
6.[] GUI post current info about the Mac.
http://projects.tynsoe.org/en/geektool/index.php

@AnneTheAgile
Copy link
Author

Julian Date CYWW Workweek TBA Code idea

1.[] Python; Three month Quarter outlook with Euro work week#’s.
http://www.macosxtips.co.uk/geeklets/productivity/calendar-3-months-european-week/
https://gist.github.com/tschloss/6207461
Python script that prints a 3-month calendar (previous, current, next month) WITH calendar weeks. The current day is highlighted. No parameters currently. INTENDED USE: Geeklet for Geek-Tool.
2.[] Ruby; FizzBuzz and fun things, organized as Gists. Idea/?
https://gist.github.com/mxcl?page=2

@AnneTheAgile
Copy link
Author

OSX Finder “SideBar”: Add Home and MyComputer

1.[] Events are used to update the info;
http://cocoadev.com/SideBarContent
~/Library/Preferences/com.apple.sidebarlists.plist
2.[] Defaults write to add back a few things
https://github.com/ymendel/dotfiles/blob/master/osx/finder.defaults
show external drives, removable media
defaults write com.apple.finder ShowExternalHardDrivesOnDesktop -bool true
defaults write com.apple.finder ShowRemovableMediaOnDesktop -bool true
3.[] LIST of what User wants to configure customize all; Scripting Configurations and Preferences - no replies, he did some already.
https://discussions.apple.com/thread/6430038?start=0&tstart=0
4.[] General procedure for plist update sidebarlists.plist. Does not seem applicable to my case. Their case was to get a list of Servers available, e.g. the school’s remote location.
https://groups.google.com/forum/#!topic/macenterprise/Ks-zHlY3h5I
5.[] Plists can be converted, with PLUtil, into XML1 and JSON1.
http://stackoverflow.com/questions/6066350/command-line-tool-for-converting-plist-to-json
[]Fix typo there, think the one suffix is read.
6.[] GUI App to edit instead of using ‘defaults’ command; fix for old tools didn’t know that there is now a message system that needs callback.
http://www.tempel.org/PrefsEditor
7.[] Restoring icons, everyone agrees can delete prefs; they are quite robust.
http://apple.stackexchange.com/questions/108299/how-to-reset-default-sidebar-favourites-icons-in-finder

@AnneTheAgile
Copy link
Author

OSX Prereq of Xcode and CommandLine Tools in order to be able to Compile

1.[] New xcode-select install option still uses GUI, unless add Applescript; otherwise hdiutil can attach and then delete, plus GUI prompt.
http://apple.stackexchange.com/questions/107307/how-can-i-install-the-command-line-tools-completely-from-the-command-line
applescript I wrote:
https://gist.github.com/brysgo/9007731
do shell script "xcode-select --install"
do shell script "sleep 1"

tell application "System Events"
tell process "Install Command Line Developer Tools"
keystroke return
click button "Agree" of window "License Agreement"
end tell
end tell
2.[] About the new OSX 10.9 Command line tool installer which is included, so now easier to get GCC and avoid the heavy Xcode download, if not desired.
http://osxdaily.com/2014/02/12/install-command-line-tools-mac-os-x/
3.[] OSX Apple website requires a userid ; the above [1] does not.
http://py-translate.readthedocs.org/en/latest/users/install_osx/
py-translate is a CLI Tool for Google Translate written in Python

HomeBrew Ruby Formulae and Bash Self-Installer

1.[] Example Go Language formula for brew.
https://github.com/Homebrew/homebrew/blob/master/Library/Formula/go.rb
2.[] Tutorial installing Xcode, HomeBrew, Git, RVM, Ruby Rails ; updated 2014.0929
http://www.moncefbelyamani.com/how-to-install-xcode-homebrew-git-rvm-ruby-on-mac/
Common Homebrew warnings and errors, and how to get rid of them
3.[] Deploy HomeBrew thru Casper (idk) & Make own Installer PKG DMG from a Brew Formula.
https://jamfnation.jamfsoftware.com/discussion.html?id=6999
Installer scripts are simple too, just run a file called "postinstall" - no deployment issues, right?
https://github.com/timsutton/brew-pkg
4.[] The HomeBrew one-line installer code is very clever and its source code is in a branch called /go/, i.e. Git-URL/Org/Project/BranchName/FilePath
Homebrew/legacy-homebrew#31825
5.[] Path moved,
https://github.com/Homebrew/homebrew/blob/go/install
puts <<-EOS
Whoops, the Homebrew installer has moved! Please instead run:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Also, please ask wherever you got this link from to update it to the above.
Thanks!
EOS
6.[] Can go to here; direct content but NOT the repo, since can’t go ‘up’.
https://raw.githubusercontent.com/Homebrew/install/master/install
7.[] Custom install location and Uninstall HomeBrew.
https://github.com/Homebrew/homebrew/wiki/Installation
8.[] Old 2011 Uninstall Homebrew by MXCL user, BUT is referenced today 2014-Oct by the FAQ.
https://gist.github.com/mxcl/1173223
https://github.com/Homebrew/homebrew/wiki/FAQ
Why does Homebrew insist I install to /usr/local with such vehemence?
It’s safe
Apple has left this directory for us. Which means there is no /usr/local directory by default, so there is no need to worry about messing up existing tools.
Can I install my own stuff to /usr/local?
Yes, brew is designed to not get in your way so you can use it how you like.
Install your own stuff, but be aware that if you install common libraries, like libexpat yourself, it may cause trouble when trying to build certain Homebrew formula. As a result brew doctor will warn you about this.
Thus it’s probably better to install your own stuff to the Cellar and then brew link it. Like so:
$ cd foo-0.1
$ brew diy
./configure —prefix=/usr/local/Cellar/foo/0.1
$ ./configure —prefix=/usr/local/Cellar/foo/0.1
[snip]
$ make && make install
$ brew link foo
Linking /usr/local/Cellar/foo/0.1… 17 symlinks created
9.[] ROR Setup with Brew inc. PostGreSql or MySql DB. //cursing alert
https://gorails.com/setup/osx/10.9-mavericks
GoRails ; We're sharing everything we know about how to write great quality code
Join the GoRails mailing list to learn more about what great code looks like, why it is great, and how you can write great code yourself that you will enjoy working with.
10.[] HomeBrew Doctor to fix certain problems and cleanup: brew update; brew doctor.
https://github.com/Homebrew/homebrew/wiki/troubleshooting
11.[] Update; Homebrew Branch is now a separate repo in the org for Install script.
Homebrew/legacy-homebrew#31825
there is now a separate repo. Code is here;
https://github.com/Homebrew/install/blob/master/install
The way to find it is to go to the organization=Homebrew and search for 'install' in their repp's.
The command to run it is as above and as always, if not run as a shell command, navigating produces an error in the web browser.
https://raw.githubusercontent.com/Homebrew/install/master/install"
12.[] Homebrew how to install on homepage as of 2014-10-04.
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Misc

1.[] LastPass is very convenient to have installed ASAP.
https://lastpass.com/
2.[] May need to have Signon Login credentials for Apple/Developer handy.
https://developer.apple.com/
3.[] WWDC 2014 Videos, no descriptions, dates though.
https://developer.apple.com/videos/wwdc/2014/
https://developer.apple.com/wwdc/schedule/
4.[] Must click to see all the Descriptions WWDC Apple 2014.06.
https://developer.apple.com/wwdc/schedule/sessions/
Accessibility on iOS
Frameworks
iOS offers unmatched accessibility support that can help you reach a wider audience. Join us for an exploration of the features that iOS offers for users with specific needs, in areas such as vision, hearing, movement, and learning. Learn how to leverage existing and new UIAccessibility APIs in iOS 8, including expanded support for low vision users, to ensure that your app's features are available to all users.
5.[] R-Language running C++: RCpp, Given Clang.
http://seananderson.ca/2013/11/18/rcpp-mavericks.html
6.[] Cursing on GoRails, asked to remove.
https://gorails.com/about
https://gorails.com/setup/osx/10.9-mavericks

@AnneTheAgile
Copy link
Author

Easy to get Adium, the reference app to install.
https://github.com/spencergibb/battleschool/blob/44d53439400b4078e3041013b1f9ee5995fb33bf/test/test_app_dmg.sh
https://github.com/spencergibb/ansible-osx/blob/master/adium.yml

# Might not need sudo, was there from prior try
$ sudo ansible-playbook -vv -i ~/ansinv -M /usr/share/battleschool/library/  ~/.battleschool/playbooks/adium.yml 
Password:

PLAY [workstation] ************************************************************ 

GATHERING FACTS *************************************************************** 
<localhost> REMOTE_MODULE setup
ok: [localhost]

TASK: [say-tof] *************************************************************** 
ok: [localhost] => {
    "msg": "~HOME/.battleschool/playbooks/Adium.yml= Starting!"
}

TASK: [install Firefox] ******************************************************* 
<localhost> REMOTE_MODULE mac_pkg pkg_type=app url=http://sourceforge.net/projects/adium/files/Adium_1.5.9.dmg/download archive_type=dmg archive_path=Adium.app
changed: [localhost] => {"changed": true, "msg": "installed package /Applications/Adium.app", "version": "N/A"}

TASK: [say-eof] *************************************************************** 
ok: [localhost] => {
    "msg": "~HOME/.battleschool/playbooks/Adium.yml= Ended!"
}

PLAY RECAP ******************************************************************** 
localhost                  : ok=4    changed=1    unreachable=0    failed=0   

$ ls -Flah /Applications/Adium.app/
total 0
drwxr-xr-x   3 root  admin   102B Dec  3  2013 ./
drwxrwxr-x+ 37 root  admin   1.2K Oct  4 20:52 ../
drwxr-xr-x   9 root  admin   306B Dec  3  2013 Contents/

$ pwd
/Users/annemoroney/ansible

$ cat ~/.battleschool/playbooks/adium.yml 
# exemplar
# https://github.com/spencergibb/battleschool/blob/44d53439400b4078e3041013b1f9ee5995fb33bf/test/test_app_dmg.sh

---
- hosts: workstation
  vars:
    THISAPP: Adium
  tasks:
    - name: say-tof
      debug: msg="~HOME/.battleschool/playbooks/{{THISAPP}}.yml= Starting!"

    - name: install Firefox
      mac_pkg: pkg_type=app
               url=http://sourceforge.net/projects/adium/files/Adium_1.5.9.dmg/download
               archive_type=dmg archive_path={{THISAPP}}.app
      sudo: yes

    - name: say-eof
      debug: msg="~HOME/.battleschool/playbooks/{{THISAPP}}.yml= Ended!"

# Tip: Ansible MSG can NOT have COLONs inside, but Tilde and Slash (forward, reverse sort of) ok.
# Tip: Ansible Playbook.YML CAN have a comment as line1 - does not need be the 3 dashes.
# WAS CURL          url=curl http://mozilla.mirrors.tds.net/pub/mozilla.org/firefox/releases/latest/ma$
               # url="ftp://ftp.mozilla.org/pub/mozilla.org/firefox/releases/32.0.3/mac/en-US/us/$

The setup info.

$ ansible all -i ~/ansinv -m ping
localhost | success >> {
    "changed": false, 
    "ping": "pong"
}

$ # NB confusion on location of ansible but so far ok ; i.e. have both local/devel and the pip
$ which ansible
/usr/local/bin/ansible
$ pip show ansible

---
Name: ansible
Version: 1.7.2
Location: /Library/Python/2.7/site-packages
Requires: paramiko, jinja2, PyYAML, setuptools, pycrypto

$ # NB names differ; battle vs battle school
$ pip show battle
$ pip show battleschool

---
Name: battleschool
Version: 0.3.6
Location: /Library/Python/2.7/site-packages
Requires: ansible, jinja2, pyyaml
$ which battle
/usr/local/bin/battle


1.[] Ansible Verbose output -v option or -vvv; or debug module.
http://serverfault.com/questions/531891/how-do-i-enable-additional-debugging-output-from-ansible-and-vagrant
2.[] Conditionally execute a task depending on category of Ansible variable.
http://grokbase.com/t/gg/ansible-project/148jmn57w3/ansible-calling-a-playbook-inside-a-playbook-with-vars-prompt-giving-error-error-vars-prompt-is-not-a-legal-parameter-in-an-ansible-task-or-handler
3.[] NOT DONE yet, more complex test.
https://github.com/spencergibb/battleschool/blob/44d53439400b4078e3041013b1f9ee5995fb33bf/test/testconfig/playbooks/playbook.yml
4.[] FIND for mac_pkg
https://github.com/spencergibb/battleschool/search?p=2&q=mac_pkg&type=Code&utf8=✓
5.[] Say hi to all machines; can reverse the order of args.
http://docs.ansible.com/intro_getting_started.html
6.[] Ansible module must have its first line telling the type of language, else get odd failures; if get this failure and you were running a yml playbook, that's because it is not a module!
http://stackoverflow.com/questions/19527867/how-should-script-output-be-formatted-for-ansible-reporting

target_host | FAILED => module is missing interpreter line
# one fix
ansible target_hosts -m script.sh

7.[] Example Shell Bash Ansible module.
http://jpmens.net/2012/07/05/shell-scripts-as-ansible-modules/
8.[] PIP documentation; List=Tell ALL (no args read) related installed; Show X=Details for one; Search=Find on remote all with such words; List --outdated to hunt for new
http://pip.readthedocs.org/en/latest/user_guide.html#listing-packages
9.[] Pip Update
http://stackoverflow.com/questions/2720014/upgrading-all-packages-with-pip

$ pip search ansible
ansible                   - Radically simple IT automation
  INSTALLED: 1.7.2 (latest)
ansigenome                - A tool to help you gather information and manage your Ansible roles.
mist.ansible              - Ansible modules for the mist.io service
augploy                   - AUGmentum dePLOYment automation tool, powered by ansible
ansible-vagrant           - Simple helper to use ansible with vagrant
mr.awsome.ansible         - A plugin for mr.awsome providing integration with Ansible.
tory_client               - client tools for the tory ansible inventory
ploy_ansible              - Plugin to integrate Ansible with ploy.
ansible-role-manager      - A tool for installing and managing Ansible roles, playbooks & modules.
ansiblator                - Ansiblator - makes Ansible api more pythonic
org_wayround_pyeditor     - Simple extansible editor with projects and outline
ansible-lint              - checks playbooks for practices and behaviour that could potentially be improved
suitable                  - Suitable is a thin wrapper around the Ansible API.
ansible-tower-cli         - A CLI tool for Ansible Tower.
ansible-inventory-grapher - Creates graphs representing ansible inventory
ansible-shell             - Interactive shell for ansible
supervisorclusterctl      - supervisorclusterctl is a cmd line tool that allows to control a cluster of processes by
                            utilizing Supervisor and Ansible.
datemike                  - Create Ansible tasks, plays, and playbooks in pure Python
arpm                      - ansible package manager command line tool
playbook_assistant        - Simple utility for Ansible playbook creation and download
futen                     - Conversion script to Ansible inventory file from OpenSSH configuration


$ pip list --outdated
altgraph (Current: 0.10.1 Latest: 0.12)
bdist-mpkg (Current: 0.4.4 Latest: 0.5.0)
Could not find any downloads that satisfy the requirement bonjour-py
Some externally hosted files were ignored (use --allow-external bonjour-py to allow).
macholib (Current: 1.5 Latest: 1.7)
matplotlib (Current: 1.1.1 Latest: 1.4.0)
modulegraph (Current: 0.10.1 Latest: 0.12)
numpy (Current: 1.6.2 Latest: 1.9.0)
py2app (Current: 0.7.1 Latest: 0.9)
//ETC

Bash Tips
1.[] Be sure to run export after changing the Path!
http://www.troubleshooters.com/linux/prepostpath.htm
PATH=$PATH:/data/myscripts
export PATH
2.[] Simple way to edit path is just use editor with output to a file!
http://stackoverflow.com/questions/370047/what-is-the-most-elegant-way-to-remove-a-path-from-the-path-variable-in-bash

echo ${PATH} > t1
vi t1
export PATH=`cat t1`

@AnneTheAgile
Copy link
Author

1.[] Modules don't need Paths, shouldn't need them.
https://groups.google.com/forum/#!topic/ansible-project/i_BFBfeZ4Ys
2.[] Nice Example , clearly shows all needed folder structures ; Tells Years of each Config mgmt tool intro inc. Juju.
http://tomoconnor.eu/blogish/getting-started-ansible/#.VDCPOlZ0UfE
3.[] Might need Recursive Sub-Git ; IDK WHY; might have been by mistake I did that.
http://docs.ansible.com/developing_modules.html#testing-modules
4.[] Running play books, another ex. Ubuntu.
https://www.digitalocean.com/community/tutorials/how-to-create-ansible-playbooks-to-automate-system-configuration-on-ubuntu

@AnneTheAgile
Copy link
Author

BUG? Do need Sudo prefix.

$ ansible-playbook -vv -i ~/ansinv -M /usr/share/battleschool/library/  ~/.battleschool/playbooks/adium.yml 

PLAY [workstation] ************************************************************ 

GATHERING FACTS *************************************************************** 
<localhost> REMOTE_MODULE setup
ok: [localhost]

TASK: [say-tof] *************************************************************** 
ok: [localhost] => {
    "msg": "~HOME/.battleschool/playbooks/Adium.yml= Starting!"
}

TASK: [install Firefox] ******************************************************* 
<localhost> REMOTE_MODULE mac_pkg pkg_type=app url=http://sourceforge.net/projects/adium/files/Adium_1.5.9.dmg/download archive_type=dmg archive_path=Adium.app
failed: [localhost] => {"failed": true, "parsed": false}
[sudo via ansible, key=bzhjymtqnhzygnqgteaneeyeesiqwbfg] password: 


FATAL: all hosts have already failed -- aborting

PLAY RECAP ******************************************************************** 
           to retry, use: --limit @/Users/HOME/adium.retry

localhost                  : ok=2    changed=0    unreachable=0    failed=1   

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment