11 February 2017 | 1 min read

ansible executes tasks on hosts, and what tasks are executed on what hosts are plonked into playbooks

if you reuse tasks in different playbooks you put them into roles

  ▸ inventory/
  ▾ roles/
    ▾ nodejs/ 
      ▾ tasks/ 

the whanApp.yaml playbook looks like this

- hosts: nodejsHosts
  become: true
    - nodejs
  • become: true basically means escalate (aka sudo)

in roles/nodejs/tasks/main.yaml are the tasks for the nodejs role

tasks specified in a role are a yaml list that basically follows a convention of name, module, module parameters, task parameters loosely specified like this, debug module example

# one form with the module parameters inline
- name: say hi
  debug: msg="weird way to say hi, from server {{ansible_hostname}}"
# another form with the module parameters as yaml
- name: say hi one more time
    msg: "another weird way to say, hi from server {{ansible_hostname}}"

you can see the "{{variable}}" bit is a template replacement, jinja2 style

Bob's linux flavour of choice is Ubuntu 16.04 and since google knows how to install it - lmgtfy

so translating what google tells us, and referring to the list of tasks looks like

- name: install some prereqs
  apt: name=python-software-properties
- name: make apt see nodesource
  shell: curl -sL | bash -
- name: install nodejs
  apt: name=nodejs
  • basically the module apt takes care of apt-get
  • shell is what you would type on the command line

to run the playbook

ansible-plabook -i inventory/dev/hosts -u ci_user whanApp.yaml