Skip to content. | Skip to navigation

Personal tools
Log in
Sections
You are here: Home

jorgenmodin.net - Blog

An opinionated short guide on how to use Ansible

Posted by admin |

Only use files that end in ".yaml". Except for the ansible.cfg, which need to be in INI format.

Playbooks


There are playbooks which configure your servers. You can have one playbook which is basically empty and is just listing what other playbooks to call, in sequence. So let's call the main playbook "manage.yaml" and the other ones "stage1.yaml", "stage2.yaml" and so on which are just listed in "manage.yaml", one after the other.

- hosts: cluster
- include: ./stages/stage1.yaml nodes=cluster



These playbooks all take their configuration variables from something called the inventory.

Inventory

The inventory can be specified on the command line with  the "-i" flag. Here is what an inventory file could look like for a testing setup:

cluster:
  hosts:
    192.168.0.79:
      name: node1
      some_app_privKey: 3132333435363738393031323334353637383930313233343536373839303131
      some_app_pubKey: 02ee99c1a7f1defbf22c5c6c58f738755836a6797e45ce569ffb80428e7d07540e
    192.168.1.86:
      name: node2
      some_app_privKey: 3132333435363738393031323334353637383930313233343536373839303132
      some_app_pubKey: 03c7a5a5f02f132b6047ee6bfc8a0b01a2b9c3f28f914fae750faf0e35b5d03e7c

  vars: # common values for all nodes, can be put per node above too, if need be
    ansible_user: user        # user name
    ansible_ssh_private_key_file: "{{ inventory_dir }}/id_rsa"
    production: False

 

The inventory is just a list of whatever data you need to deploy: Ip numbers, private keys for signing stuff, public keys, config variables and so on.

Sub playbooks - stages


Each playbook contains steps, which are done in sequence, once for each server listed in the inventory.

For each step you can do a test if the step should run at all, then test if the step is already installed, and if not run the step. The step mutates the server in some way: Installs a package, configures a config file, or copies over some files, or starts/restarts a server process. That is about it.

(stage1.yaml)

- hosts: "{{ nodes }}"

  become: true
  pre_tasks:
  - name: Update repositories cache and ensure "libpq-dev" package is installed
    apt:
      name: libpq-dev
      update_cache: yes

Problems


At first, Ansible seems to be very smooth but there are some problems mainly with syntax where you have to do a bit of googling on how to do stuff.

Here is a list of my ansible problems, to date:

Jun 30, 2017 12:35

Formatting of HTML & Javascript for Sublime Text 3 & brackets indication

Posted by admin |

This is the one I want, HTML CSS and Javascript Prettify:

https://packagecontrol.io/packages/HTML-CSS-JS%20Prettify

 

Bracket Highlighter https://packagecontrol.io/packages/BracketHighlighter BracketHighlighter - Packages - Package Control

Jun 01, 2017 12:25

Qubes OS - kort översikt

Posted by admin |

Qubes OS försöker göra din dator säkrare genom att isolera olika aktiviteter i egna virtuella maskiner. Till exempel kan man ha en virtuell maskin för jobb, en annnan för bankärenden och en tredje för slösurfning.

Qubes OS är baserat på Fedora Linux, men man kan köra t ex Debian inuti den. Jag har provat att köra Qubes OS på min laptop, på en USB-sticka. Det funkade bra. Qubes OS består av ett antal virtuella maskiner, och man gör egentligen inget arbete ute i värdsystemet. T o m nätverkskopplingarna ligger i en egen virtuell maskin, som de andra maskinerna kopplar sig genom. Man bör ha en del RAM och man kan installera Qubes OS på en 32GB USB-sticka (Installationen kräver minst 24GB) och testa först.

Så det yttersta systemet i Qubes OS är inte en virtuell maskin, utan värdsystemet, som är en del av Qubes OS. Detta värdsystem är byggt på Fedora.

 

 

May 26, 2017 09:05

News tells us what causes the Venezuela crisis

Posted by admin |

News tells us what causes the Venezuela crisis, well at least some news does. You have to dig a bit.

People are prevented to cooperate and create value, to the point of starvation and under abundant abuse by criminals and people turned criminals.

Many news articles seem to miss that point. Here is a recent BBC article that barely mentions the economic situation as behind the turmoil, truly remarkable: Venezuela crisis: What is behind the turmoil? - BBC News

Let's dig a bit deeper and start with CNN Money:

4 reasons why Venezuela became the world's worst economy - Oct. 25, 2016

Two reasons could be valid as causing the others and the crisis:

  • Government spending
  • Price controls

Time Magazine is starting to give some answers Venezuela Government to Blame as Economic Situation Worsens:

Venezuela depends on oil for about 96% of export earnings and nearly half its federal budget. When prices were high, policymakers could have created a rainy-day fund. Some of that money went toward lifting poor people from poverty, but much was stolen: Venezuela is the most corrupt country in the Americas and the ninth most corrupt in the world, according to Transparency International.

Ok, so they used oil money to run the state and when that got less, there was less money for handouts and subsidies.

The Guardian gives more hints Venezuela's worsening economic crisis – the Guardian briefing:

Chávez build his popularity on oil money and foreign debt, using both to fund consumption, while nationalising more than 1,200 private companies deemed not to be functioning in the public interest.

So 1200 companies were nationalised.

The overall themes seem to be two:

  • Reckless spending that has put people in a position of dependency, and when that spending dries up, people have no means, networks, trust in each other or experience to cooperate around creating value
  • An obsession with control, that puts people in charge who are incompetent and corrupt, and price controls that make it impossible to sell imported stuff at market value

To summarize these two themes, it's about preventing people to cooperate and create value, to the point of starvation and abundant abuse of people by criminals. I talked to some Venezuelans about two years ago here in Sweden and they told me how bad the situation was then for their loved ones. I cannot imagine how bad it is now.

 

May 23, 2017 12:32 | Comments (15)

Memory for different window managers and desktop environments

Posted by admin |

Memory requirements of different window managers and desktop environments on Linux (a bit old)

 

Source cmp-all4.png (PNG Image, 698 × 690 pixels)

May 22, 2017 01:55

Ansible variables that tells you the location in the controller's file system

Posted by admin |

Taken from here, where there is a list of many more variables in Ansible: lorin/ansible-quickref: Quick reference for Ansible variables

  Description
playbook_dir Directory that contains the playbook being executed
inventory_dir Directory that contains the inventory
inventory_file Host file or script path (?)

If you are using included playbooks, playbook_dir get really confused. It will report a path such as:

/home/use/playbook_dir/./sub_playbook_dir

You can truncate the path to before the dot, with a filter, like this:

"{{ playbook_dir | regex_replace('(/\\./.*)', '')  }}
May 08, 2017 10:40