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

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   

@AnneTheAgile
Copy link
Author

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