node

2017-02-11

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/ 
        main.yaml
  whanApp.yaml

the whanApp.yaml playbook looks like this

---
- hosts: nodejsHosts
  become: true
  roles:
    - 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
  debug: 
    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 devdocs.io the list of tasks looks like

---
- name: install some prereqs
  apt: name=python-software-properties
- name: make apt see nodesource
  shell: curl -sL https://deb.nodesource.com/setup_7.x | 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