diff --git a/.travis.yml b/.travis.yml index abc583a44f62a169059b177cabed55bfe3ab9183..76f59715afcaf9cd74d4ab6775daf01fafd31866 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 edf5c4706215f0f88a982206ca521fc462fd3882..e756a5e2cf4fb656f8c7a65be0ff412292f1517e 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 0a97962c3b635cf908e8e45d5171b0aa8b7f3d92..6c6e19e8205f59098243bf8a974b294565a3c671 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 bd0df0d80d6094e097cca7760cd1b12a480df33c..f83a8845e317597cdc2a7adeff1b74b01de65994 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 2dea7f403f2774209b2935d8aecfe4e81d2379a8..57ceea255af376022d7fa0734f43c5c2b7df5d0e 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 792e63098a7ab31421eaf2c9acc299cced8f45fc..93ae0baf40d17a5076912fb9a3be53f359e1fa02 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 6784821deee6cb0db41de18ee53b6e04ce43ea01..373e3dcf514fb4900dec2e2b00e5d471d0b8a089 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 aa08159b36b209253114a1a10d70493d1af78b75..dd9d30d8442fd462840036bcb63054bdfbf5c7d2 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 aaea50030b9784f0528df9b936cf1903d3af5994..4f4066cb7e9d60d2116f7cf9708c336a4145e9b7 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 0000000000000000000000000000000000000000..4f70048912fef0b990e6a95d85fbaad18fa36f93 --- /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 7542f3cf45dd754b408bd13b5c57af85bc3d0fc8..ceae34a6a486f1c6abecda17772994c31ec5d76e 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -1,2 +1,2 @@ --- -# vars file for example +# vars file for openwrt-bootstrap