From 468bd332975e089c13140007182e708205095b30 Mon Sep 17 00:00:00 2001
From: Adar Nimrod <nimrod@shore.co.il>
Date: Fri, 23 Dec 2016 00:17:35 +0200
Subject: [PATCH] - Forked from the example role. - Works fine, passes tests in
 Docker. - Need to find working Vagrant boxes (these don't work properly).

---
 .travis.yml           |  1 +
 README.rst            | 17 ++++++++++-------
 defaults/main.yml     |  2 +-
 handlers/main.yml     |  2 +-
 meta/main.yml         | 12 +++++-------
 molecule.yml          | 28 ++++++++++++----------------
 tasks/main.yml        | 20 ++++++++++++++------
 tests/playbook.yml    | 19 ++++++++++---------
 tests/test_example.py |  5 -----
 tests/test_python.py  |  9 +++++++++
 vars/main.yml         |  2 +-
 11 files changed, 64 insertions(+), 53 deletions(-)
 create mode 100644 tests/test_python.py

diff --git a/.travis.yml b/.travis.yml
index abc583a..76f5971 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -14,6 +14,7 @@ install:
   - pip install -r tests/requirements.txt | cat
   - ansible-galaxy install git+file://$(pwd),$(git rev-parse --abbrev-ref HEAD) -p .molecule/roles
   - molecule dependency
+  - for version in 14.07 15.05; do docker pull xdrum/openwrt:$version; done
 
 script:
   - pre-commit run --all-files
diff --git a/README.rst b/README.rst
index edf5c47..e756a5e 100644
--- a/README.rst
+++ b/README.rst
@@ -1,12 +1,10 @@
-Example
-#######
+OpenWRT bootstrap
+#################
 
-.. image:: https://travis-ci.org/adarnimrod/example.svg?branch=master
-    :target: https://travis-ci.org/adarnimrod/example
+.. image:: https://travis-ci.org/adarnimrod/openwrt-bootstrap.svg?branch=master
+    :target: https://travis-ci.org/adarnimrod/openwrt-bootstrap
 
-An (empty) example Ansible role complete with working tests out of the box. For
-more information read the `blog post
-<https://www.shore.co.il/blog/ansible-example-role/>`_.
+Bootstrap an OpenWRT instance (allow Ansible to provision the instance).
 
 Requirements
 ------------
@@ -61,3 +59,8 @@ Nimrod Adar, `contact me <nimrod@shore.co.il>`_ or visit my `website
 <https://www.shore.co.il/>`_. Patches are welcome via `git send-email
 <http://git-scm.com/book/en/v2/Git-Commands-Email>`_. The repository is located
 at: https://www.shore.co.il/git/.
+
+TODO
+----
+
+- Working tests using Vagrant.
diff --git a/defaults/main.yml b/defaults/main.yml
index 0a97962..6c6e19e 100644
--- a/defaults/main.yml
+++ b/defaults/main.yml
@@ -1,2 +1,2 @@
 ---
-# defaults file for example
+# defaults file for openwrt-bootstrap
diff --git a/handlers/main.yml b/handlers/main.yml
index bd0df0d..f83a884 100644
--- a/handlers/main.yml
+++ b/handlers/main.yml
@@ -1,2 +1,2 @@
 ---
-# handlers file for example
+# handlers file for openwrt-bootstrap
diff --git a/meta/main.yml b/meta/main.yml
index 2dea7f4..57ceea2 100644
--- a/meta/main.yml
+++ b/meta/main.yml
@@ -1,15 +1,13 @@
 galaxy_info:
   author: Nimrod Adar
-  description: An example Ansible role
+  description: Bootstrap an OpenWRT instance (allow Ansible to provision the instance)
   company: Shore technologies
   license: MIT
   min_ansible_version: 2.0
   platforms:
-  - name: OpenBSD
+  - name: OpenWRT
     versions:
-    - 6.0
-  - name: Ubuntu
-    versions:
-    - xenial
-  galaxy_tags: [ ansible ]
+    - 14.07
+    - 15.05
+  galaxy_tags: [ ansible, openwrt ]
 dependencies: []
diff --git a/molecule.yml b/molecule.yml
index 792e630..93ae0ba 100644
--- a/molecule.yml
+++ b/molecule.yml
@@ -14,12 +14,12 @@ vagrant:
   - name: virtualbox
     type: virtualbox
   platforms:
-  - name: openbsd
-    box: kaorimatz/openbsd-6.0-amd64
-  - name: xenial
-    box: ubuntu/xenial64
+  - name: '14.07'
+    box: qqshfox/openwrt-barrier_breaker
+  - name: '15.05'
+    box: lifeeth/openwrt-15.05-x86
   instances:
-  - name: example
+  - name: openwrt-bootstrap
     options:
         append_platform_to_hostname: yes
   raw_config_args:
@@ -29,15 +29,11 @@ vagrant:
   - 'landrush_ip.override = false'
 
 docker:
+  build_image: False
   containers:
-  - name: example-xenial
-    image: ubuntu
-    image_version: xenial
-    command: /sbin/init
-    privileged: True
-    volume_mounts:
-      - /sys/fs/cgroup:/sys/fs/cgroup
-      - /var/run/dbus/system_bus_socket:/var/run/dbus/system_bus_socket
-    environment:
-        DEBIAN_FRONTEND: noninteractive
-        container: docker
+  - name: openwrt-bootstrap-15.05
+    image: xdrum/openwrt
+    image_version: 15.05
+  - name: openwrt-bootstrap-14.07
+    image: xdrum/openwrt
+    image_version: 14.07
diff --git a/tasks/main.yml b/tasks/main.yml
index 6784821..373e3dc 100644
--- a/tasks/main.yml
+++ b/tasks/main.yml
@@ -1,8 +1,16 @@
 ---
-# tasks file for example
+# tasks file for openwrt-bootstrap
 
-- name: Assertions
-  assert:
-    that:
-        - ansible_os_family in ['OpenBSD', 'Debian']
-        - ansible_distribution_release in ['6.0', 'xenial']
+- name: Update opkg package lists
+  raw: opkg update
+  changed_when: False
+
+- name: opkg install python
+  raw: opkg install python
+  register: openwrt_bootstrap_install_python
+  changed_when: "'Downloading' in openwrt_bootstrap_install_python.stdout"
+
+- name: opkg install ip
+  opkg:
+      name: ip
+      state: present
diff --git a/tests/playbook.yml b/tests/playbook.yml
index aa08159..dd9d30d 100644
--- a/tests/playbook.yml
+++ b/tests/playbook.yml
@@ -1,13 +1,14 @@
 ---
-- hosts: example-openbsd
-  gather_facts: false
-  roles: [openbsd-bootstrap]
-
-- hosts: example-xenial
-  gather_facts: false
-  roles: [debian-bootstrap]
-
 - hosts: all
+  gather_facts: False
   strategy: free
   roles:
-    - role: example
+    - role: openwrt-bootstrap
+  post_tasks:
+      - name: Test gathering facts
+        setup:
+
+      - name: Assertions
+        assert:
+            that:
+                - ansible_default_ipv4 is defined
diff --git a/tests/test_example.py b/tests/test_example.py
index aaea500..4f4066c 100644
--- a/tests/test_example.py
+++ b/tests/test_example.py
@@ -5,8 +5,3 @@ testinfra_hosts = AnsibleRunner('.molecule/ansible_inventory').get_hosts('all')
 
 def test_example(Command):
     assert Command('uname').rc == 0
-
-
-def test_root(Command, Sudo):
-    with Sudo():
-        assert Command('whoami').stdout.strip() == 'root'
diff --git a/tests/test_python.py b/tests/test_python.py
new file mode 100644
index 0000000..4f70048
--- /dev/null
+++ b/tests/test_python.py
@@ -0,0 +1,9 @@
+from testinfra.utils.ansible_runner import AnsibleRunner
+
+testinfra_hosts = AnsibleRunner('.molecule/ansible_inventory').get_hosts('all')
+
+
+def test_python(Command):
+    python = Command('python --version')
+    assert python.rc == 0
+    assert '2.7' in python.stderr
diff --git a/vars/main.yml b/vars/main.yml
index 7542f3c..ceae34a 100644
--- a/vars/main.yml
+++ b/vars/main.yml
@@ -1,2 +1,2 @@
 ---
-# vars file for example
+# vars file for openwrt-bootstrap
-- 
GitLab