Initial commit

This commit is contained in:
Ansible Core Team 2020-03-09 09:11:07 +00:00
commit aebc1b03fd
4861 changed files with 812621 additions and 0 deletions

View file

@ -0,0 +1,10 @@
disabled
shippable/posix/group2
skip/aix
skip/osx
skip/freebsd
destructive
skip/docker # We need SSH access to the VM and need to be able to let
# docker-machine install docker in the VM. This won't work
# with tests running in docker containers.
needs/root

View file

@ -0,0 +1,20 @@
#!/usr/bin/env bash
# Mock Docker Machine wrapper for testing purposes
[ "$MOCK_ERROR_IN" == "$1" ] && echo >&2 "Mock Docker Machine error" && exit 1
case $1 in
env)
cat <<'EOF'
export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://134.209.204.160:2376"
export DOCKER_CERT_PATH="/root/.docker/machine/machines/routinator"
export DOCKER_MACHINE_NAME="routinator"
# Run this command to configure your shell:
# eval $(docker-machine env --shell=bash routinator)
EOF
;;
*)
/usr/bin/docker-machine $*
;;
esac

View file

@ -0,0 +1 @@
plugin: community.general.docker_machine

View file

@ -0,0 +1,2 @@
plugin: community.general.docker_machine
daemon_env: require

View file

@ -0,0 +1,2 @@
plugin: community.general.docker_machine
daemon_env: optional

View file

@ -0,0 +1,3 @@
---
dependencies:
- setup_docker

View file

@ -0,0 +1,18 @@
---
- hosts: 127.0.0.1
connection: local
tasks:
- name: Setup docker
include_role:
name: setup_docker
# There seems to be no better way to install docker-machine. At least I couldn't find any packages for RHEL7/8.
- name: Download docker-machine binary
vars:
docker_machine_version: "0.16.1"
get_url:
url: "https://github.com/docker/machine/releases/download/v{{ docker_machine_version }}/docker-machine-{{ ansible_system }}-{{ ansible_userspace_architecture }}"
dest: /tmp/docker-machine
- name: Install docker-machine binary
command: install /tmp/docker-machine /usr/bin/docker-machine
become: yes

View file

@ -0,0 +1,11 @@
---
- hosts: 127.0.0.1
connection: local
tasks:
- name: Request Docker Machine to use this machine as a generic VM
command: "docker-machine --debug create \
--driver generic \
--generic-ip-address=localhost \
--generic-ssh-key {{ lookup('env', 'HOME') }}/.ssh/id_rsa \
--generic-ssh-user root \
vm"

View file

@ -0,0 +1,6 @@
---
- hosts: 127.0.0.1
connection: local
tasks:
- name: Request Docker Machine to remove this machine as a generic VM
command: "docker-machine rm vm -f"

View file

@ -0,0 +1,50 @@
- hosts: 127.0.0.1
gather_facts: no
tasks:
- name: sanity check Docker Machine output
vars:
dm_ls_format: !unsafe '{{.Name}} | {{.DriverName}} | {{.State}} | {{.URL}} | {{.Error}}'
success_regex: "^vm | [^|]+ | Running | tcp://.+ |$"
command: docker-machine ls --format '{{ dm_ls_format }}'
register: result
failed_when: result.rc != 0 or result.stdout is not match(success_regex)
- name: verify Docker Machine ip
command: docker-machine ip vm
register: result
failed_when: result.rc != 0 or result.stdout != hostvars['vm'].ansible_host
- name: verify Docker Machine env
command: docker-machine env --shell=sh vm
register: result
- debug: var=result.stdout
- assert:
that:
- "'DOCKER_TLS_VERIFY=\"{{ hostvars['vm'].dm_DOCKER_TLS_VERIFY }}\"' in result.stdout"
- "'DOCKER_HOST=\"{{ hostvars['vm'].dm_DOCKER_HOST }}\"' in result.stdout"
- "'DOCKER_CERT_PATH=\"{{ hostvars['vm'].dm_DOCKER_CERT_PATH }}\"' in result.stdout"
- "'DOCKER_MACHINE_NAME=\"{{ hostvars['vm'].dm_DOCKER_MACHINE_NAME }}\"' in result.stdout"
- hosts: vm
gather_facts: no
tasks:
- name: do something to verify that accept-new ssh setting was applied by the docker-machine inventory plugin
raw: uname -a
register: result
- debug: var=result.stdout
- hosts: 127.0.0.1
gather_facts: no
environment:
DOCKER_CERT_PATH: "{{ hostvars['vm'].dm_DOCKER_CERT_PATH }}"
DOCKER_HOST: "{{ hostvars['vm'].dm_DOCKER_HOST }}"
DOCKER_MACHINE_NAME: "{{ hostvars['vm'].dm_DOCKER_MACHINE_NAME }}"
DOCKER_TLS_VERIFY: "{{ hostvars['vm'].dm_DOCKER_TLS_VERIFY }}"
tasks:
- name: run a Docker container on the target Docker Machine host to verify that Docker daemon connection settings from the docker-machine inventory plugin work as expected
docker_container:
name: test
image: hello-world:latest

View file

@ -0,0 +1,68 @@
#!/usr/bin/env bash
SCRIPT_DIR=$(dirname "$0")
echo "Who am I: $(whoami)"
echo "Home: ${HOME}"
echo "PWD: $(pwd)"
echo "Script dir: ${SCRIPT_DIR}"
# restrict Ansible just to our inventory plugin, to prevent inventory data being matched by the test but being provided
# by some other dynamic inventory provider
export ANSIBLE_INVENTORY_ENABLED=docker_machine
[[ -n "$DEBUG" || -n "$ANSIBLE_DEBUG" ]] && set -x
set -euo pipefail
SAVED_PATH="$PATH"
cleanup() {
PATH="${SAVED_PATH}"
echo "Cleanup"
ansible-playbook -i teardown.docker_machine.yml playbooks/teardown.yml
echo "Done"
}
trap cleanup INT TERM EXIT
echo "Pre-setup (install docker, docker-machine)"
ANSIBLE_ROLES_PATH=.. ansible-playbook playbooks/pre-setup.yml
echo "Print docker-machine version"
docker-machine --version
echo "Check preconditions"
# Host should NOT be known to Ansible before the test starts
ansible-inventory -i inventory_1.docker_machine.yml --host vm >/dev/null && exit 1
echo "Test that the docker_machine inventory plugin is being loaded"
ANSIBLE_DEBUG=yes ansible-inventory -i inventory_1.docker_machine.yml --list | grep -F "Loading InventoryModule 'docker_machine'"
echo "Setup"
ansible-playbook playbooks/setup.yml
echo "Test docker_machine inventory 1"
ansible-playbook -i inventory_1.docker_machine.yml playbooks/test_inventory_1.yml
echo "Activate Docker Machine mock"
PATH=${SCRIPT_DIR}:$PATH
echo "Test docker_machine inventory 2: daemon_env=require daemon env success=yes"
ansible-inventory -i inventory_2.docker_machine.yml --list
echo "Test docker_machine inventory 2: daemon_env=require daemon env success=no"
export MOCK_ERROR_IN=env
ansible-inventory -i inventory_2.docker_machine.yml --list
unset MOCK_ERROR_IN
echo "Test docker_machine inventory 3: daemon_env=optional daemon env success=yes"
ansible-inventory -i inventory_3.docker_machine.yml --list
echo "Test docker_machine inventory 3: daemon_env=optional daemon env success=no"
export MOCK_ERROR_IN=env
ansible-inventory -i inventory_2.docker_machine.yml --list
unset MOCK_ERROR_IN
echo "Deactivate Docker Machine mock"
PATH="${SAVED_PATH}"

View file

@ -0,0 +1,3 @@
plugin: community.general.docker_machine
daemon_env: skip
running_required: false