diff --git a/Makefile b/Makefile index 916468c..3655076 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -ANSIBLE_INSTALL_VERSION ?= 2.2.3.0 +ANSIBLE_INSTALL_VERSION ?= 2.7.6 PATH := $(PWD)/.venv_ansible$(ANSIBLE_INSTALL_VERSION)/bin:$(shell printenv PATH) SHELL := env PATH=$(PATH) /bin/bash diff --git a/meta/main.yml b/meta/main.yml index 761c7c6..a8a08a2 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -6,7 +6,7 @@ dependencies: [] galaxy_info: description: Users and Groups Management Made Simple license: MIT - min_ansible_version: 2.2 + min_ansible_version: 2.5 platforms: - name: Ubuntu versions: diff --git a/molecule/default/create.yml b/molecule/default/create.yml deleted file mode 100644 index c52693c..0000000 --- a/molecule/default/create.yml +++ /dev/null @@ -1,60 +0,0 @@ ---- - -- name: Create - hosts: localhost - connection: local - gather_facts: false - no_log: "{{ not lookup('env', 'MOLECULE_DEBUG') | bool }}" - vars: - molecule_file: "{{ lookup('env', 'MOLECULE_FILE') }}" - molecule_ephemeral_directory: "{{ lookup('env', 'MOLECULE_EPHEMERAL_DIRECTORY') }}" - molecule_scenario_directory: "{{ lookup('env', 'MOLECULE_SCENARIO_DIRECTORY') }}" - molecule_yml: "{{ lookup('file', molecule_file) | molecule_from_yaml }}" - tasks: - - name: Create Dockerfiles from image names - template: - src: "{{ molecule_scenario_directory }}/Dockerfile.j2" - dest: "{{ molecule_ephemeral_directory }}/Dockerfile_{{ item.image | regex_replace('[^a-zA-Z0-9_]', '_') }}" - with_items: "{{ molecule_yml.platforms }}" - register: platforms - - - name: Discover local Docker images - docker_image_facts: - name: "molecule_local/{{ item.item.name }}" - with_items: "{{ platforms.results }}" - register: docker_images - - - name: Build an Ansible compatible image - docker_image: - path: "{{ molecule_ephemeral_directory }}" - name: "molecule_local/{{ item.item.image }}" - dockerfile: "{{ item.item.dockerfile | default(item.invocation.module_args.dest) }}" - force: "{{ item.item.force | default(true) }}" - with_items: "{{ platforms.results }}" - when: platforms.changed or docker_images.results | map(attribute='images') | select('equalto', []) | list | count >= 0 - - - name: Create molecule instance(s) - docker_container: - name: "{{ item.name }}" - hostname: "{{ item.name }}" - image: "molecule_local/{{ item.image }}" - state: started - recreate: false - log_driver: "{{ 'none' if ( ansible_version.full | version_compare('2.4', '>=' )) else 'json-file' }}" - command: "{{ item.command | default('bash -c \"while true; do sleep 10000; done\"') }}" - privileged: "{{ item.privileged | default(omit) }}" - volumes: "{{ item.volumes | default(omit) }}" - capabilities: "{{ item.capabilities | default(omit) }}" - ports: "{{ item.exposed_ports | default(omit) }}" - register: server - with_items: "{{ molecule_yml.platforms }}" - async: 7200 - poll: 0 - - - name: Wait for instance(s) creation to complete - async_status: - jid: "{{ item.ansible_job_id }}" - register: docker_jobs - until: docker_jobs.finished - retries: 300 - with_items: "{{ server.results }}" diff --git a/molecule/default/destroy.yml b/molecule/default/destroy.yml deleted file mode 100644 index 68dd4fd..0000000 --- a/molecule/default/destroy.yml +++ /dev/null @@ -1,28 +0,0 @@ ---- - -- name: Destroy - hosts: localhost - connection: local - gather_facts: false - no_log: "{{ not lookup('env', 'MOLECULE_DEBUG') | bool }}" - vars: - molecule_file: "{{ lookup('env', 'MOLECULE_FILE') }}" - molecule_yml: "{{ lookup('file', molecule_file) | molecule_from_yaml }}" - tasks: - - name: Destroy molecule instance(s) - docker_container: - name: "{{ item.name }}" - state: absent - force_kill: "{{ item.force_kill | default(true) }}" - register: server - with_items: "{{ molecule_yml.platforms }}" - async: 7200 - poll: 0 - - - name: Wait for instance(s) deletion to complete - async_status: - jid: "{{ item.ansible_job_id }}" - register: docker_jobs - until: docker_jobs.finished - retries: 300 - with_items: "{{ server.results }}" diff --git a/molecule/default/playbook.yml b/molecule/default/playbook.yml index bb3ffe4..18f730b 100644 --- a/molecule/default/playbook.yml +++ b/molecule/default/playbook.yml @@ -4,6 +4,19 @@ hosts: all roles: + - role: users_and_groups + sansible_users_and_groups_groups: + - name: test_basic + sansible_users_and_groups_users: + - name: test_basic + group: test_basic + ssh_key: test_basic.pub + sansible_users_and_groups_sudoers: + - name: test_basic + user: "%test_basic" + runas: "ALL=(ALL)" + commands: "NOPASSWD: ALL" + - role: users_and_groups sansible_users_and_groups_authorized_keys_dir: /etc/ssh/authorized_keys/ diff --git a/molecule/default/prepare.yml b/molecule/default/prepare.yml index 849cea1..148e74d 100644 --- a/molecule/default/prepare.yml +++ b/molecule/default/prepare.yml @@ -2,5 +2,20 @@ - name: Prepare hosts: all - gather_facts: false - tasks: [] + gather_facts: no + + tasks: + - name: Install Python for Ansible + become: yes + raw: test -e /usr/bin/python || (apt -y update && apt install -y python-minimal python-zipstream) + changed_when: no + + - name: Install apt-transport-https, lsb-release, net-tools + become: yes + apt: + name: "{{ item }}" + update_cache: yes + with_items: + - apt-transport-https + - lsb-release + - net-tools diff --git a/molecule/default/test_basic.pub b/molecule/default/test_basic.pub new file mode 100644 index 0000000..141610a --- /dev/null +++ b/molecule/default/test_basic.pub @@ -0,0 +1 @@ +ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAA/gu0O2EI2lxAItjJzd/mN7sKtRWkpYg2HX/bnlfA01733kvTz1etqR6UqzQnyRK5mMGj5a6XQmezF2kyQztImkaDnnF0r5sz34QBhjIEy2MTw4eARprxLvN2voMQWMr8Rd7AgAkVQkXgAwsIZs0z1QA6dV4p8eDfNFVHYI9zScrCk41ljarLAge0vj9JfgIh0X6bz4hiG2+89QAXgICgpve6kXzA5BUQLyzn4E9H1MNFU/RVib5SgRldZyfCNP7qnRa+XUvNOj9WZslrVkwxViHgXKzz6xLoNGP0OrIA9FiZu5FaewP6xA59SPQyDFg6oCnvOxMgRyuGDH1cXiw7 lorem.ipsum@example.com diff --git a/molecule/default/tests/test_default.py b/molecule/default/tests/test_default.py index 74889a1..2feb2c7 100644 --- a/molecule/default/tests/test_default.py +++ b/molecule/default/tests/test_default.py @@ -7,6 +7,8 @@ def test_groups(host): + assert host.group('test_basic').exists + assert host.group('test_one').exists assert host.group('test_two').exists @@ -17,6 +19,9 @@ def test_groups(host): def test_users(host): + assert host.user('test_basic').exists + assert 'test_basic' in host.user('test_basic').groups + assert host.user('john').exists assert 'test_one' in host.user('john').groups assert 'test_two' in host.user('john').groups @@ -33,6 +38,10 @@ def test_users(host): def test_sudo(host): + with host.sudo('test_basic'): + with host.sudo(): + assert host.check_output('whoami') == 'root' + with host.sudo('john'): with host.sudo(): assert host.check_output('whoami') == 'root' diff --git a/requirements.txt b/requirements.txt index 6de582a..30ff12a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ -docker-py -molecule +docker==3.5.1 +molecule==2.19.0 +pytest==3.9.3 \ No newline at end of file diff --git a/tasks/build.yml b/tasks/build.yml index 12f774d..9851fa7 100644 --- a/tasks/build.yml +++ b/tasks/build.yml @@ -72,7 +72,7 @@ - name: Create .ssh directory in default user home directory become: yes file: - path: "{{ item.home | default('/home/' ~ item.name)/}}/.ssh" + path: "{{ item.home | default('/home/' ~ item.name) }}/.ssh" owner: "{{ item.name }}" group: "{{ item.group | default(omit) }}" mode: 0700