diff --git a/test/integration/targets/delegate_to/aliases b/test/integration/targets/delegate_to/aliases index 1bf9c0dc22..38ad1b8f8c 100644 --- a/test/integration/targets/delegate_to/aliases +++ b/test/integration/targets/delegate_to/aliases @@ -1,2 +1,3 @@ shippable/posix/group3 needs/ssh +needs/root # only on macOS and FreeBSD to configure network interfaces diff --git a/test/integration/targets/delegate_to/runme.sh b/test/integration/targets/delegate_to/runme.sh index a9056eb880..0334ce1dae 100755 --- a/test/integration/targets/delegate_to/runme.sh +++ b/test/integration/targets/delegate_to/runme.sh @@ -2,6 +2,46 @@ set -eux +platform="$(uname)" + +function setup() { + if [[ "${platform}" == "FreeBSD" ]] || [[ "${platform}" == "Darwin" ]]; then + ifconfig lo0 + + existing=$(ifconfig lo0 | grep '^[[:blank:]]inet 127\.0\.0\. ' || true) + + echo "${existing}" + + for i in 3 4 254; do + ip="127.0.0.${i}" + + if [[ "${existing}" != *"${ip}"* ]]; then + ifconfig lo0 alias "${ip}" up + fi + done + + ifconfig lo0 + fi +} + +function teardown() { + if [[ "${platform}" == "FreeBSD" ]] || [[ "${platform}" == "Darwin" ]]; then + for i in 3 4 254; do + ip="127.0.0.${i}" + + if [[ "${existing}" != *"${ip}"* ]]; then + ifconfig lo0 -alias "${ip}" + fi + done + + ifconfig lo0 + fi +} + +setup + +trap teardown EXIT + ANSIBLE_SSH_ARGS='-C -o ControlMaster=auto -o ControlPersist=60s -o UserKnownHostsFile=/dev/null' \ ANSIBLE_HOST_KEY_CHECKING=false ansible-playbook test_delegate_to.yml -i inventory -v "$@" diff --git a/test/runner/setup/remote.sh b/test/runner/setup/remote.sh index 0c8d4632e1..f3d79368ff 100644 --- a/test/runner/setup/remote.sh +++ b/test/runner/setup/remote.sh @@ -75,15 +75,6 @@ fi if [ "${platform}" = "freebsd" ] || [ "${platform}" = "osx" ]; then pip install virtualenv - - # Tests assume loopback addresses other than 127.0.0.1 will work. - # Add aliases for loopback addresses used by tests. - - for i in 3 4 254; do - ifconfig lo0 alias "127.0.0.${i}" up - done - - ifconfig lo0 fi # Since tests run as root, we also need to be able to ssh to localhost as root.