Archive

Archive for July, 2017

Ansible Galaxy

July 27, 2017 Leave a comment

Ansible Galaxy is Ansible’s official community hub for sharing Ansible roles. A role is the Ansible way of bundling automation content and making it reusable.

If you’re not familiar with the Ansible role concept, think of include files used in a programming language. An include file allows the programmer to organize code into reusable modules. Code can be organized into smaller files and grouped by subject matter or function. These discrete pieces of code can then be included as needed into larger programs like building blocks.

A role is similar. Instead of creating giant playbooks with hundreds of tasks we can use roles to organize tasks, breaking them apart into smaller more discrete units of work. But a role is more than just an include file. A role is all the tasks, variables and handlers needed to complete the unit of work. This allows a role to be completely self contained or encapsulated and completely reusable.

Using roles also allows us to think about node configuration in terms of modeling. For example, given a set of nodes that should be web servers we can simply apply a web server role to them. We don’t have to think about or write all the tasks needed to configure web servers. All the details are already encapsulated in a web server role – a role you downloaded from Galaxy.

https://galaxy.ansible.com/

Categories: ansible Tags: , ,

A Powerline style prompt for your shell

July 23, 2017 Leave a comment

For a hassle free powerline like shell. Works with bash and zsh.

* Shows some important details about the git/svn/hg/fossil branch (see below)
* Changes color if the last command exited with a failure code
* If you’re too deep into a directory tree, shortens the displayed path with an ellipsis
* Shows the current Python virtualenv environment
* It’s easy to customize and extend. See below for details.

https://github.com/banga/powerline-shell

Categories: bash, zsh Tags:

powerline-gitstatus

July 23, 2017 Leave a comment

Problem:
Git status with powerline

Solution:
https://github.com/jaspernbrouwer/powerline-gitstatus

1. pip install –user powerline-gitstatus

Follow the instructions in on site https://github.com/jaspernbrouwer/powerline-gitstatus
2. Add custom highlight groups.

vim .local/lib/python2.7/site-packages/powerline/config_files/colorschemes/default.json

Example

{
  "groups": {
    "gitstatus":                 { "fg": "gray8",           "bg": "gray2", "attrs": [] },
    "gitstatus_branch":          { "fg": "gray8",           "bg": "gray2", "attrs": [] },
    "gitstatus_branch_clean":    { "fg": "green",           "bg": "gray2", "attrs": [] },
    "gitstatus_branch_dirty":    { "fg": "gray8",           "bg": "gray2", "attrs": [] },
    "gitstatus_branch_detached": { "fg": "mediumpurple",    "bg": "gray2", "attrs": [] },
    "gitstatus_tag":             { "fg": "darkcyan",        "bg": "gray2", "attrs": [] },
    "gitstatus_behind":          { "fg": "gray10",          "bg": "gray2", "attrs": [] },
    "gitstatus_ahead":           { "fg": "gray10",          "bg": "gray2", "attrs": [] },
    "gitstatus_staged":          { "fg": "green",           "bg": "gray2", "attrs": [] },
    "gitstatus_unmerged":        { "fg": "brightred",       "bg": "gray2", "attrs": [] },
    "gitstatus_changed":         { "fg": "mediumorange",    "bg": "gray2", "attrs": [] },
    "gitstatus_untracked":       { "fg": "brightestorange", "bg": "gray2", "attrs": [] },
    "gitstatus_stashed":         { "fg": "darkblue",        "bg": "gray2", "attrs": [] },
    "gitstatus:divider":         { "fg": "gray8",           "bg": "gray2", "attrs": [] }
  }
}

3. Activate the Gitstatus segment.

vim .local/lib/python2.7/site-packages/powerline/config_files/colorschemes/default.json

Example

{
    "function": "powerline_gitstatus.gitstatus",
    "priority": 40
}

4. Show most recent tag reachable in the current branch.

vim .local/lib/python2.7/site-packages/powerline/config_files/themes/shell/__main__.json

Example

"gitstatus": {
    "args": {
        "show_tag": true
    }
}

These are json files. Be careful with syntax. If editing existing files, remember to add the necessary commas where needed.

Source:
https://github.com/jaspernbrouwer/powerline-gitstatus

powerline-status

July 23, 2017 Leave a comment

Problem:
Installing powerline-status

Solution:
1. pip install –user powerline-status
2. Add the following to .bashrc

if [ -d "$HOME/.local/bin" ]; then
    PATH="$HOME/.local/bin:$PATH"
fi

export POWERLINE_COMMAND=powerline
powerline-daemon -q

POWERLINE_BASH_CONTINUATION=1
POWERLINE_BASH_SELECT=1
REPOSITORY_ROOT=/home/rodnee/.local/lib/python2.7/site-packages
. ${REPOSITORY_ROOT}/powerline/bindings/bash/powerline.sh

3. Source .bashrc. It may give some errors. Open up a new terminal and see if the changes have taken effect.

$ source .bashrc
bash: /home/rodnee/.local/lib/python2.7/site-packages/powerline/bindings/bash/../../../scripts/powerline-config: No such file or directory
bash: /home/rodnee/.local/lib/python2.7/site-packages/powerline/bindings/bash/../../../scripts/powerline-config: No such file or directory

Source:
http://powerline.readthedocs.io/en/master/index.html
https://github.com/powerline/powerline/issues/850

Note:
I could not get it to work with zsh. Opted for https://pseudoscripter.wordpress.com/2017/07/23/a-powerline-style-prompt-for-your-shell/ instead.

Categories: bash Tags: ,

jq – a lightweight and flexible command-line JSON processor

July 17, 2017 Leave a comment

jq is like sed for JSON data – you can use it to slice and filter and map and transform structured data with the same ease that sed, awk, grep and friends let you play with text.

jq is written in portable C, and it has zero runtime dependencies. You can download a single binary, scp it to a far away machine of the same type, and expect it to work.

jq can mangle the data format that you have into the one that you want with very little effort, and the program to do so is often shorter and simpler than you’d expect.

https://stedolan.github.io/jq/

Categories: Interesting Tags: , ,

This cell phone can make calls even without a battery

July 6, 2017 Leave a comment

“HELLO, HELLO. I am calling from a battery-free phone.” Vamsi Talla’s words in a cluttered lab at the University of Washington in Seattle are barely audible through pops and static. But the fact they can be heard at all, on a nearby Android smartphone, is revolutionary, because Talla’s own cell phone has no battery at all. It draws what little power it needs from thin air.
The prototype cell phone is the culmination of a years-long quest by Talla, a research associate at the lab of Joshua Smith, who researches computer science and electrical engineering at UW. “If you had to pick one device to make battery-free, what would you pick,” asks Smith. “A cell phone is one of the most useful objects there is. Now imagine if your battery ran out and you could still send texts and make calls.”

https://www.wired.com/story/this-cell-phone-can-make-calls-even-without-a-battery/

Categories: Interesting