split 'common' Ansible role into bcdb_base & ntp, modified those a bit

This commit is contained in:
troymc 2016-08-23 17:17:26 +02:00
parent 460e1c3fba
commit a5a6e8ad4d
7 changed files with 62 additions and 51 deletions

View File

@ -20,7 +20,7 @@ but replace `192.0.2.128` with the IP address of the host.
## Run the Ansible Playbook
The next step is to run the Ansible playbook `one-m-node.yml`. It installs all the software necessary in a one-machine BigchainDB node, configures it, and starts it. Here's how to run that playbook:
The next step is to run the Ansible playbook `one-m-node.yml`:
```text
# cd to the directory .../bigchaindb/ntools/one-m/ansible
ansible-playbook -i hosts --private-key ~/.ssh/<key-name> one-m-node.yml
@ -28,7 +28,9 @@ ansible-playbook -i hosts --private-key ~/.ssh/<key-name> one-m-node.yml
where `<key-name>` should be replaced by the name of the SSH private key you created earlier (for SSHing to the host machine at your cloud hosting provider).
Note: At the time of writing, the playbook only installs and runs an NTP daemon, but more is coming soon.
What did you just do? Running that playbook ensures all the software necessary for a one-machine BigchainDB node is installed, configured, and running properly. You can run that playbook on a regular schedule to ensure that the system stays properly configured. If something is okay, it does nothing; it only takes action when something is not as-desired.
Note: At the time of writing, the playbook only installs, configures and runs an NTP daemon, but more is coming soon.
## Optional: Create an Ansible Config File

View File

@ -1,9 +1,11 @@
---
# This playbook deploys a BigchainDB node in one machine (one-m).
- name: install + configure + start all software
- name: Ensure a one-machine BigchainDB node is configured properly
hosts: all
remote_user: ubuntu
roles:
- common
- bcdb_base
- ntp
# TODO: upgrade pip and setuptools, see https://github.com/bobbyrenwick/ansible-pip

View File

@ -0,0 +1,25 @@
---
# ansible/roles/bcdb_base/tasks/main.yml
# Note: "become: true" basically means "become root user for this task" i.e. sudo <cmd>
# See https://docs.ansible.com/ansible/become.html
- name: Do the equivalent of "sudo apt-get update"
apt: update_cache=yes
become: true
- name: Configure all unpacked but unconfigured packages
shell: /usr/bin/dpkg --configure -a
become: true
- name: Attempt to correct a system with broken dependencies in place
shell: /usr/bin/apt-get -y -f install
become: true
- name: Ensure the LATEST git g++ python3-dev are installed
apt: name={{item}} state=latest
become: true
with_items:
- git
- g++
- python3-dev

View File

@ -1,9 +0,0 @@
---
# ansible/roles/common/handlers/main.yml
# See http://docs.ansible.com/playbooks_intro.html for more information about handlers.
- name: restart ntp
service: name=ntpd state=restarted
#- name: restart iptables
# service: name=iptables state=restarted

View File

@ -1,38 +0,0 @@
---
# ansible/roles/common/tasks/main.yml
# Note: "become: true" basically means "become root user for this task" i.e. sudo <cmd>
# See https://docs.ansible.com/ansible/become.html
- name: Do the equivalent of "sudo apt-get update"
apt: update_cache=yes
become: true
- name: Uninstall ntpdate (deprecated)
apt: name=ntpdate state=absent
become: true
tags: ntp
- name: Update all installed packages to their latest versions
apt: upgrade=dist
become: true
- name: Install ntp
apt: name=ntp state=latest update_cache=yes
become: true
tags: ntp
#- name: Configure ntp file
# template: src=ntp.conf.j2 dest=/etc/ntp.conf
# tags: ntp
# "restart ntp" is the name of a handler (in common/handlers/main.yml)
# notify: restart ntp
- name: Start the ntp service
service: name=ntp state=started enabled=yes
become: true
tags: ntp
#- name: test to see if selinux is running
# command: getenforce
# register: sestatus
# changed_when: false

View File

@ -0,0 +1,5 @@
---
# ansible/roles/common/handlers/main.yml
- name: restart ntp
service: name=ntpd state=restarted

View File

@ -0,0 +1,24 @@
---
# ansible/roles/ntp/tasks/main.yml
- name: Ensure ntpdate is not installed (and uninstall it if necessary)
apt: name=ntpdate state=absent
become: true
- name: Ensure the LATEST ntp is installed and do "sudo apt-get update"
apt: name=ntp state=latest update_cache=yes
become: true
- name: Retrieve facts about the file /etc/ntp.conf
stat: path=/etc/ntp.conf
register: ntp_conf_file
- name: Fail when /etc/ntp.conf doesn't exist
fail: msg="The NTP config file /etc/ntp.conf doesn't exist'"
when: ntp_conf_file.stat.exists == False
# For now, we assume the default /etc/ntp.conf file is okay
- name: Ensure the ntp service is now started and should start on boot (enabled=yes)
service: name=ntp state=started enabled=yes
become: true