Compare commits
1 Commits
devel
...
threading_
| Author | SHA1 | Date | |
|---|---|---|---|
| 847327eb9a |
@ -1,245 +0,0 @@
|
||||
trigger:
|
||||
batch: true
|
||||
branches:
|
||||
include:
|
||||
- devel
|
||||
- stable-*
|
||||
|
||||
pr:
|
||||
autoCancel: true
|
||||
branches:
|
||||
include:
|
||||
- devel
|
||||
- stable-*
|
||||
|
||||
schedules:
|
||||
- cron: 0 7 * * *
|
||||
displayName: Nightly
|
||||
always: true
|
||||
branches:
|
||||
include:
|
||||
- devel
|
||||
- stable-*
|
||||
|
||||
variables:
|
||||
- name: checkoutPath
|
||||
value: ansible
|
||||
- name: coverageBranches
|
||||
value: devel
|
||||
- name: entryPoint
|
||||
value: .azure-pipelines/commands/entry-point.sh
|
||||
- name: fetchDepth
|
||||
value: 500
|
||||
- name: defaultContainer
|
||||
value: quay.io/ansible/azure-pipelines-test-container:6.0.0
|
||||
|
||||
pool: Standard
|
||||
|
||||
stages:
|
||||
- stage: Sanity
|
||||
dependsOn: []
|
||||
jobs:
|
||||
- template: templates/matrix.yml
|
||||
parameters:
|
||||
nameFormat: Test {0}
|
||||
testFormat: sanity/{0}
|
||||
targets:
|
||||
- test: 1
|
||||
- test: 2
|
||||
- stage: Units
|
||||
dependsOn: []
|
||||
jobs:
|
||||
- template: templates/matrix.yml
|
||||
parameters:
|
||||
nameFormat: Python {0}
|
||||
testFormat: units/{0}
|
||||
targets:
|
||||
- test: 3.8
|
||||
- test: 3.9
|
||||
- test: '3.10'
|
||||
- test: 3.11
|
||||
- test: 3.12
|
||||
- test: 3.13
|
||||
- stage: Windows
|
||||
dependsOn: []
|
||||
jobs:
|
||||
- template: templates/matrix.yml
|
||||
parameters:
|
||||
nameFormat: Server {0}
|
||||
testFormat: windows/{0}/1
|
||||
targets:
|
||||
- name: 2016 WinRM HTTP
|
||||
test: 2016/winrm/http
|
||||
- name: 2019 WinRM HTTPS
|
||||
test: 2019/winrm/https
|
||||
- name: 2022 WinRM HTTPS
|
||||
test: 2022/winrm/https
|
||||
- name: 2022 PSRP HTTP
|
||||
test: 2022/psrp/http
|
||||
- name: 2022 SSH Key
|
||||
test: 2022/ssh/key
|
||||
- name: 2025 PSRP HTTP
|
||||
test: 2025/psrp/http
|
||||
- name: 2025 SSH Key
|
||||
test: 2025/ssh/key
|
||||
- stage: Remote
|
||||
dependsOn: []
|
||||
jobs:
|
||||
- template: templates/matrix.yml # context/target
|
||||
parameters:
|
||||
targets:
|
||||
- name: macOS 15.3
|
||||
test: macos/15.3
|
||||
- name: RHEL 9.5 py39
|
||||
test: rhel/9.5@3.9
|
||||
- name: RHEL 9.5 py312
|
||||
test: rhel/9.5@3.12
|
||||
- name: RHEL 10.0
|
||||
test: rhel/10.0
|
||||
- name: FreeBSD 13.5
|
||||
test: freebsd/13.5
|
||||
- name: FreeBSD 14.2
|
||||
test: freebsd/14.2
|
||||
groups:
|
||||
- 1
|
||||
- 2
|
||||
- template: templates/matrix.yml # context/controller
|
||||
parameters:
|
||||
targets:
|
||||
- name: macOS 15.3
|
||||
test: macos/15.3
|
||||
- name: RHEL 9.5
|
||||
test: rhel/9.5
|
||||
- name: RHEL 10.0
|
||||
test: rhel/10.0
|
||||
- name: FreeBSD 13.5
|
||||
test: freebsd/13.5
|
||||
- name: FreeBSD 14.2
|
||||
test: freebsd/14.2
|
||||
groups:
|
||||
- 3
|
||||
- 4
|
||||
- 5
|
||||
- template: templates/matrix.yml # context/controller (ansible-test container management)
|
||||
parameters:
|
||||
targets:
|
||||
- name: Alpine 3.21
|
||||
test: alpine/3.21
|
||||
- name: Fedora 41
|
||||
test: fedora/41
|
||||
- name: RHEL 9.5
|
||||
test: rhel/9.5
|
||||
- name: RHEL 10.0
|
||||
test: rhel/10.0
|
||||
- name: Ubuntu 24.04
|
||||
test: ubuntu/24.04
|
||||
groups:
|
||||
- 6
|
||||
- stage: Docker
|
||||
dependsOn: []
|
||||
jobs:
|
||||
- template: templates/matrix.yml # context/target
|
||||
parameters:
|
||||
testFormat: linux/{0}
|
||||
targets:
|
||||
- name: Alpine 3.21
|
||||
test: alpine321
|
||||
- name: Fedora 41
|
||||
test: fedora41
|
||||
- name: Ubuntu 22.04
|
||||
test: ubuntu2204
|
||||
- name: Ubuntu 24.04
|
||||
test: ubuntu2404
|
||||
groups:
|
||||
- 1
|
||||
- 2
|
||||
- template: templates/matrix.yml # context/controller
|
||||
parameters:
|
||||
testFormat: linux/{0}
|
||||
targets:
|
||||
- name: Alpine 3.21
|
||||
test: alpine321
|
||||
- name: Fedora 41
|
||||
test: fedora41
|
||||
- name: Ubuntu 24.04
|
||||
test: ubuntu2404
|
||||
groups:
|
||||
- 3
|
||||
- 4
|
||||
- 5
|
||||
- template: templates/matrix.yml # context/target (dnf-oldest, dnf-latest)
|
||||
parameters:
|
||||
testFormat: linux/{0}
|
||||
targets:
|
||||
- name: Fedora 41
|
||||
test: fedora41
|
||||
groups:
|
||||
- 7
|
||||
- stage: Galaxy
|
||||
dependsOn: []
|
||||
jobs:
|
||||
- template: templates/matrix.yml
|
||||
parameters:
|
||||
nameFormat: Python {0}
|
||||
testFormat: galaxy/{0}/1
|
||||
targets:
|
||||
- test: 3.11
|
||||
- test: 3.12
|
||||
- test: 3.13
|
||||
- stage: Generic
|
||||
dependsOn: []
|
||||
jobs:
|
||||
- template: templates/matrix.yml
|
||||
parameters:
|
||||
nameFormat: Python {0}
|
||||
testFormat: generic/{0}/1
|
||||
targets:
|
||||
- test: 3.11
|
||||
- test: 3.12
|
||||
- test: 3.13
|
||||
- stage: Incidental_Windows
|
||||
displayName: Incidental Windows
|
||||
dependsOn: []
|
||||
jobs:
|
||||
- template: templates/matrix.yml
|
||||
parameters:
|
||||
nameFormat: Server {0}
|
||||
testFormat: i/windows/{0}
|
||||
targets:
|
||||
- name: 2016 WinRM HTTP
|
||||
test: 2016/winrm/http
|
||||
- name: 2019 WinRM HTTPS
|
||||
test: 2019/winrm/https
|
||||
- name: 2022 WinRM HTTPS
|
||||
test: 2022/winrm/https
|
||||
- name: 2022 PSRP HTTP
|
||||
test: 2022/psrp/http
|
||||
- name: 2022 SSH Key
|
||||
test: 2022/ssh/key
|
||||
- name: 2025 PSRP HTTP
|
||||
test: 2025/psrp/http
|
||||
- name: 2025 SSH Key
|
||||
test: 2025/ssh/key
|
||||
- stage: Incidental
|
||||
dependsOn: []
|
||||
jobs:
|
||||
- template: templates/matrix.yml
|
||||
parameters:
|
||||
testFormat: i/{0}/1
|
||||
targets:
|
||||
- name: IOS Python
|
||||
test: ios/csr1000v/
|
||||
- stage: Summary
|
||||
condition: succeededOrFailed()
|
||||
dependsOn:
|
||||
- Sanity
|
||||
- Units
|
||||
- Windows
|
||||
- Remote
|
||||
- Docker
|
||||
- Galaxy
|
||||
- Generic
|
||||
- Incidental_Windows
|
||||
- Incidental
|
||||
jobs:
|
||||
- template: templates/coverage.yml
|
||||
@ -1 +0,0 @@
|
||||
remote.sh
|
||||
@ -1,34 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -o pipefail -eux
|
||||
|
||||
declare -a args
|
||||
IFS='/:' read -ra args <<< "$1"
|
||||
|
||||
cloud="${args[0]}"
|
||||
python="${args[1]}"
|
||||
group="${args[2]}"
|
||||
|
||||
target="shippable/${cloud}/group${group}/"
|
||||
|
||||
stage="${S:-prod}"
|
||||
|
||||
changed_all_target="shippable/${cloud}/smoketest/"
|
||||
|
||||
if ! ansible-test integration "${changed_all_target}" --list-targets > /dev/null 2>&1; then
|
||||
# no smoketest tests are available for this cloud
|
||||
changed_all_target="none"
|
||||
fi
|
||||
|
||||
if [ "${group}" == "1" ]; then
|
||||
# only run smoketest tests for group1
|
||||
changed_all_mode="include"
|
||||
else
|
||||
# smoketest tests already covered by group1
|
||||
changed_all_mode="exclude"
|
||||
fi
|
||||
|
||||
# shellcheck disable=SC2086
|
||||
ansible-test integration --color -v --retry-on-error "${target}" ${COVERAGE:+"$COVERAGE"} ${CHANGED:+"$CHANGED"} ${UNSTABLE:+"$UNSTABLE"} \
|
||||
--remote-terminate always --remote-stage "${stage}" \
|
||||
--docker --python "${python}" --changed-all-target "${changed_all_target}" --changed-all-mode "${changed_all_mode}"
|
||||
@ -1,62 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -o pipefail -eux
|
||||
|
||||
declare -a args
|
||||
IFS='/:' read -ra args <<< "$1"
|
||||
|
||||
script="${args[0]}"
|
||||
|
||||
test="$1"
|
||||
|
||||
docker images
|
||||
docker ps
|
||||
|
||||
for container in $(docker ps --format '{{.Image}} {{.ID}}' | grep -v -e '^quay.io/ansible/azure-pipelines-test-container:' | sed 's/^.* //'); do
|
||||
docker rm -f "${container}" || true # ignore errors
|
||||
done
|
||||
|
||||
docker ps
|
||||
|
||||
export PATH="${PWD}/bin:${PATH}"
|
||||
export PYTHONIOENCODING='utf-8'
|
||||
|
||||
if [ -n "${COVERAGE:-}" ]; then
|
||||
# on-demand coverage reporting triggered by setting the COVERAGE environment variable to a non-empty value
|
||||
export COVERAGE="--coverage"
|
||||
elif [[ "${COMMIT_MESSAGE}" =~ ci_coverage ]]; then
|
||||
# on-demand coverage reporting triggered by having 'ci_coverage' in the latest commit message
|
||||
export COVERAGE="--coverage"
|
||||
else
|
||||
# on-demand coverage reporting disabled (default behavior, always-on coverage reporting remains enabled)
|
||||
export COVERAGE="--coverage-check"
|
||||
fi
|
||||
|
||||
if [ -n "${COMPLETE:-}" ]; then
|
||||
# disable change detection triggered by setting the COMPLETE environment variable to a non-empty value
|
||||
export CHANGED=""
|
||||
elif [[ "${COMMIT_MESSAGE}" =~ ci_complete ]]; then
|
||||
# disable change detection triggered by having 'ci_complete' in the latest commit message
|
||||
export CHANGED=""
|
||||
else
|
||||
# enable change detection (default behavior)
|
||||
export CHANGED="--changed"
|
||||
fi
|
||||
|
||||
if [ "${IS_PULL_REQUEST:-}" == "true" ]; then
|
||||
# run unstable tests which are targeted by focused changes on PRs
|
||||
export UNSTABLE="--allow-unstable-changed"
|
||||
else
|
||||
# do not run unstable tests outside PRs
|
||||
export UNSTABLE=""
|
||||
fi
|
||||
|
||||
if [[ "${COVERAGE:-}" == "--coverage" ]]; then
|
||||
timeout=60
|
||||
else
|
||||
timeout=50
|
||||
fi
|
||||
|
||||
ansible-test env --dump --show --timeout "${timeout}" --color -v
|
||||
|
||||
".azure-pipelines/commands/${script}.sh" "${test}"
|
||||
@ -1 +0,0 @@
|
||||
remote.sh
|
||||
@ -1 +0,0 @@
|
||||
remote.sh
|
||||
@ -1 +0,0 @@
|
||||
cloud.sh
|
||||
@ -1,18 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -o pipefail -eux
|
||||
|
||||
declare -a args
|
||||
IFS='/:' read -ra args <<< "$1"
|
||||
|
||||
python="${args[1]}"
|
||||
|
||||
if [ "${#args[@]}" -gt 2 ]; then
|
||||
target="shippable/generic/group${args[2]}/"
|
||||
else
|
||||
target="shippable/generic/"
|
||||
fi
|
||||
|
||||
# shellcheck disable=SC2086
|
||||
ansible-test integration --color -v --retry-on-error "${target}" ${COVERAGE:+"$COVERAGE"} ${CHANGED:+"$CHANGED"} ${UNSTABLE:+"$UNSTABLE"} \
|
||||
--docker default --python "${python}"
|
||||
@ -1,14 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# Temporary script to support side-by-side testing for incidental code coverage.
|
||||
# Once collection migration has been completed the incidental tests can be combined with the regular tests.
|
||||
|
||||
set -o pipefail -eux
|
||||
|
||||
declare -a args
|
||||
IFS='/:' read -ra args <<< "$1"
|
||||
|
||||
script="${args[1]}"
|
||||
|
||||
IFS='/' test="${args[*]:1}"
|
||||
|
||||
".azure-pipelines/commands/incidental/${script}.sh" "${test}"
|
||||
@ -1 +0,0 @@
|
||||
network.sh
|
||||
@ -1,40 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -o pipefail -eux
|
||||
|
||||
declare -a args
|
||||
IFS='/:' read -ra args <<< "$1"
|
||||
|
||||
platform="${args[0]}"
|
||||
version="${args[1]}"
|
||||
python_version="${args[2]}"
|
||||
|
||||
target="shippable/${platform}/incidental/"
|
||||
|
||||
stage="${S:-prod}"
|
||||
provider="${P:-default}"
|
||||
|
||||
# python versions to test in order
|
||||
# all versions run full tests
|
||||
IFS=' ' read -r -a python_versions <<< \
|
||||
"$(PYTHONPATH="${PWD}/test/lib" python -c 'from ansible_test._internal import constants; print(" ".join(constants.CONTROLLER_PYTHON_VERSIONS))')"
|
||||
|
||||
if [ "${python_version}" ]; then
|
||||
# limit tests to a single python version
|
||||
python_versions=("${python_version}")
|
||||
fi
|
||||
|
||||
for python_version in "${python_versions[@]}"; do
|
||||
# terminate remote instances on the final python version tested
|
||||
if [ "${python_version}" = "${python_versions[-1]}" ]; then
|
||||
terminate="always"
|
||||
else
|
||||
terminate="never"
|
||||
fi
|
||||
|
||||
# shellcheck disable=SC2086
|
||||
ansible-test network-integration --color -v --retry-on-error "${target}" ${COVERAGE:+"$COVERAGE"} ${CHANGED:+"$CHANGED"} ${UNSTABLE:+"$UNSTABLE"} \
|
||||
--platform "${platform}/${version}" \
|
||||
--docker default --python "${python_version}" \
|
||||
--remote-terminate "${terminate}" --remote-stage "${stage}" --remote-provider "${provider}"
|
||||
done
|
||||
@ -1,46 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -o pipefail -eux
|
||||
|
||||
declare -a args
|
||||
IFS='/:' read -ra args <<< "$1"
|
||||
|
||||
version="${args[1]}"
|
||||
connection="${args[2]}"
|
||||
connection_setting="${args[3]}"
|
||||
|
||||
target="shippable/windows/incidental/"
|
||||
|
||||
stage="${S:-prod}"
|
||||
provider="${P:-default}"
|
||||
|
||||
# python version to run full tests on while other versions run minimal tests
|
||||
python_default="$(PYTHONPATH="${PWD}/test/lib" python -c 'from ansible_test._internal import constants; print(constants.CONTROLLER_MIN_PYTHON_VERSION)')"
|
||||
|
||||
# version to test when only testing a single version
|
||||
single_version=2022
|
||||
|
||||
# shellcheck disable=SC2086
|
||||
ansible-test windows-integration --list-targets -v ${CHANGED:+"$CHANGED"} ${UNSTABLE:+"$UNSTABLE"} > /tmp/explain.txt 2>&1 || { cat /tmp/explain.txt && false; }
|
||||
{ grep ' windows-integration: .* (targeted)$' /tmp/explain.txt || true; } > /tmp/windows.txt
|
||||
|
||||
if [ -s /tmp/windows.txt ] || [ "${CHANGED:+$CHANGED}" == "" ]; then
|
||||
echo "Detected changes requiring integration tests specific to Windows:"
|
||||
cat /tmp/windows.txt
|
||||
|
||||
echo "Running Windows integration tests for the version ${version}."
|
||||
else
|
||||
echo "No changes requiring integration tests specific to Windows were detected."
|
||||
echo "Running Windows integration tests for a single version only: ${single_version}"
|
||||
|
||||
if [ "${version}" != "${single_version}" ]; then
|
||||
echo "Skipping this job since it is for: ${version}"
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
|
||||
# shellcheck disable=SC2086
|
||||
ansible-test windows-integration --color -v --retry-on-error "${target}" ${COVERAGE:+"$COVERAGE"} ${CHANGED:+"$CHANGED"} ${UNSTABLE:+"$UNSTABLE"} \
|
||||
--controller "docker:default,python=${python_default}" \
|
||||
--target "remote:windows/${version},connection=${connection}+${connection_setting},provider=${provider}" \
|
||||
--remote-terminate always --remote-stage "${stage}"
|
||||
@ -1,18 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -o pipefail -eux
|
||||
|
||||
declare -a args
|
||||
IFS='/:' read -ra args <<< "$1"
|
||||
|
||||
image="${args[1]}"
|
||||
|
||||
if [ "${#args[@]}" -gt 2 ]; then
|
||||
target="shippable/posix/group${args[2]}/"
|
||||
else
|
||||
target="shippable/posix/"
|
||||
fi
|
||||
|
||||
# shellcheck disable=SC2086
|
||||
ansible-test integration --color -v --retry-on-error "${target}" ${COVERAGE:+"$COVERAGE"} ${CHANGED:+"$CHANGED"} ${UNSTABLE:+"$UNSTABLE"} \
|
||||
--docker "${image}"
|
||||
@ -1 +0,0 @@
|
||||
remote.sh
|
||||
@ -1,32 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -o pipefail -eux
|
||||
|
||||
declare -a args
|
||||
IFS='/:' read -ra args <<< "$1"
|
||||
|
||||
platform="${args[0]}"
|
||||
version="${args[1]}"
|
||||
pyver=default
|
||||
|
||||
# check for explicit python version like 8.3@3.8
|
||||
declare -a splitversion
|
||||
IFS='@' read -ra splitversion <<< "$version"
|
||||
|
||||
if [ "${#splitversion[@]}" -gt 1 ]; then
|
||||
version="${splitversion[0]}"
|
||||
pyver="${splitversion[1]}"
|
||||
fi
|
||||
|
||||
if [ "${#args[@]}" -gt 2 ]; then
|
||||
target="shippable/posix/group${args[2]}/"
|
||||
else
|
||||
target="shippable/posix/"
|
||||
fi
|
||||
|
||||
stage="${S:-prod}"
|
||||
provider="${P:-default}"
|
||||
|
||||
# shellcheck disable=SC2086
|
||||
ansible-test integration --color -v --retry-on-error "${target}" ${COVERAGE:+"$COVERAGE"} ${CHANGED:+"$CHANGED"} ${UNSTABLE:+"$UNSTABLE"} \
|
||||
--python "${pyver}" --remote "${platform}/${version}" --remote-terminate always --remote-stage "${stage}" --remote-provider "${provider}" \
|
||||
@ -1 +0,0 @@
|
||||
remote.sh
|
||||
@ -1,41 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -o pipefail -eux
|
||||
|
||||
declare -a args
|
||||
IFS='/:' read -ra args <<< "$1"
|
||||
|
||||
group="${args[1]}"
|
||||
|
||||
group2_include=(
|
||||
ansible-doc
|
||||
changelog
|
||||
package-data
|
||||
pep8
|
||||
pylint
|
||||
validate-modules
|
||||
)
|
||||
|
||||
group1_exclude=(
|
||||
"${group2_include[@]}"
|
||||
)
|
||||
|
||||
options=()
|
||||
|
||||
case "${group}" in
|
||||
1)
|
||||
for name in "${group1_exclude[@]}"; do
|
||||
options+=(--skip-test "${name}")
|
||||
done
|
||||
;;
|
||||
2)
|
||||
for name in "${group2_include[@]}"; do
|
||||
options+=(--test "${name}")
|
||||
done
|
||||
;;
|
||||
esac
|
||||
|
||||
# shellcheck disable=SC2086
|
||||
ansible-test sanity --color -v --junit ${COVERAGE:+"$COVERAGE"} ${CHANGED:+"$CHANGED"} \
|
||||
--docker \
|
||||
"${options[@]}" --allow-disabled
|
||||
@ -1 +0,0 @@
|
||||
remote.sh
|
||||
@ -1,11 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -o pipefail -eux
|
||||
|
||||
declare -a args
|
||||
IFS='/:' read -ra args <<< "$1"
|
||||
|
||||
version="${args[1]}"
|
||||
|
||||
# shellcheck disable=SC2086
|
||||
ansible-test units --color -v --docker default --python "${version}" ${COVERAGE:+"$COVERAGE"} ${CHANGED:+"$CHANGED"} \
|
||||
@ -1,89 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -o pipefail -eux
|
||||
|
||||
declare -a args
|
||||
IFS='/:' read -ra args <<< "$1"
|
||||
|
||||
version="${args[1]}"
|
||||
connection="${args[2]}"
|
||||
connection_setting="${args[3]}"
|
||||
group="${args[4]}"
|
||||
|
||||
target="shippable/windows/group${group}/"
|
||||
|
||||
stage="${S:-prod}"
|
||||
provider="${P:-default}"
|
||||
|
||||
# python versions to test in order
|
||||
IFS=' ' read -r -a python_versions <<< \
|
||||
"$(PYTHONPATH="${PWD}/test/lib" python -c 'from ansible_test._internal import constants; print(" ".join(constants.CONTROLLER_PYTHON_VERSIONS))')"
|
||||
|
||||
# python version to run full tests on while other versions run minimal tests
|
||||
python_default="$(PYTHONPATH="${PWD}/test/lib" python -c 'from ansible_test._internal import constants; print(constants.CONTROLLER_MIN_PYTHON_VERSION)')"
|
||||
|
||||
# version to test when only testing a single version
|
||||
single_version=2022
|
||||
|
||||
# shellcheck disable=SC2086
|
||||
ansible-test windows-integration --list-targets -v ${CHANGED:+"$CHANGED"} ${UNSTABLE:+"$UNSTABLE"} > /tmp/explain.txt 2>&1 || { cat /tmp/explain.txt && false; }
|
||||
{ grep ' windows-integration: .* (targeted)$' /tmp/explain.txt || true; } > /tmp/windows.txt
|
||||
|
||||
if [ -s /tmp/windows.txt ] || [ "${CHANGED:+$CHANGED}" == "" ]; then
|
||||
echo "Detected changes requiring integration tests specific to Windows:"
|
||||
cat /tmp/windows.txt
|
||||
|
||||
echo "Running Windows integration tests for the version ${version}."
|
||||
else
|
||||
echo "No changes requiring integration tests specific to Windows were detected."
|
||||
echo "Running Windows integration tests for a single version only: ${single_version}"
|
||||
|
||||
if [ "${version}" != "${single_version}" ]; then
|
||||
echo "Skipping this job since it is for: ${version}"
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
|
||||
for py_version in "${python_versions[@]}"; do
|
||||
changed_all_target="all"
|
||||
changed_all_mode="default"
|
||||
|
||||
if [ "${py_version}" == "${python_default}" ]; then
|
||||
# smoketest tests
|
||||
if [ "${CHANGED}" ]; then
|
||||
# with change detection enabled run tests for anything changed
|
||||
# use the smoketest tests for any change that triggers all tests
|
||||
ci="${target}"
|
||||
changed_all_target="shippable/windows/smoketest/"
|
||||
if [ "${target}" == "shippable/windows/group1/" ]; then
|
||||
# only run smoketest tests for group1
|
||||
changed_all_mode="include"
|
||||
else
|
||||
# smoketest tests already covered by group1
|
||||
changed_all_mode="exclude"
|
||||
fi
|
||||
else
|
||||
# without change detection enabled run entire test group
|
||||
ci="${target}"
|
||||
fi
|
||||
else
|
||||
# only run minimal tests for group1
|
||||
if [ "${target}" != "shippable/windows/group1/" ]; then continue; fi
|
||||
# minimal tests for other python versions
|
||||
ci="shippable/windows/minimal/"
|
||||
fi
|
||||
|
||||
# terminate remote instances on the final python version tested
|
||||
if [ "${py_version}" = "${python_versions[-1]}" ]; then
|
||||
terminate="always"
|
||||
else
|
||||
terminate="never"
|
||||
fi
|
||||
|
||||
# shellcheck disable=SC2086
|
||||
ansible-test windows-integration --color -v --retry-on-error "${ci}" ${COVERAGE:+"$COVERAGE"} ${CHANGED:+"$CHANGED"} ${UNSTABLE:+"$UNSTABLE"} \
|
||||
--changed-all-target "${changed_all_target}" --changed-all-mode "${changed_all_mode}" \
|
||||
--controller "docker:default,python=${py_version}" \
|
||||
--target "remote:windows/${version},connection=${connection}+${connection_setting},provider=${provider}" \
|
||||
--remote-terminate "${terminate}" --remote-stage "${stage}"
|
||||
done
|
||||
@ -1,20 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# Aggregate code coverage results for later processing.
|
||||
|
||||
set -o pipefail -eu
|
||||
|
||||
agent_temp_directory="$1"
|
||||
|
||||
PATH="${PWD}/bin:${PATH}"
|
||||
|
||||
mkdir "${agent_temp_directory}/coverage/"
|
||||
|
||||
options=(--venv --color -v)
|
||||
|
||||
ansible-test coverage combine --group-by command --export "${agent_temp_directory}/coverage/" "${options[@]}"
|
||||
|
||||
if ansible-test coverage analyze targets generate --help >/dev/null 2>&1; then
|
||||
# Only analyze coverage if the installed version of ansible-test supports it.
|
||||
# Doing so allows this script to work unmodified for multiple Ansible versions.
|
||||
ansible-test coverage analyze targets generate "${agent_temp_directory}/coverage/coverage-analyze-targets.json" "${options[@]}"
|
||||
fi
|
||||
@ -1,59 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
"""
|
||||
Combine coverage data from multiple jobs, keeping the data only from the most recent attempt from each job.
|
||||
Coverage artifacts must be named using the format: "Coverage $(System.JobAttempt) {StableUniqueNameForEachJob}"
|
||||
The recommended coverage artifact name format is: Coverage $(System.JobAttempt) $(System.StageDisplayName) $(System.JobDisplayName)
|
||||
Keep in mind that Azure Pipelines does not enforce unique job display names (only names).
|
||||
It is up to pipeline authors to avoid name collisions when deviating from the recommended format.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
import sys
|
||||
|
||||
|
||||
def main():
|
||||
"""Main program entry point."""
|
||||
source_directory = sys.argv[1]
|
||||
|
||||
if '/ansible_collections/' in os.getcwd():
|
||||
output_path = "tests/output"
|
||||
else:
|
||||
output_path = "test/results"
|
||||
|
||||
destination_directory = os.path.join(output_path, 'coverage')
|
||||
|
||||
if not os.path.exists(destination_directory):
|
||||
os.makedirs(destination_directory)
|
||||
|
||||
jobs = {}
|
||||
count = 0
|
||||
|
||||
for name in os.listdir(source_directory):
|
||||
match = re.search('^Coverage (?P<attempt>[0-9]+) (?P<label>.+)$', name)
|
||||
label = match.group('label')
|
||||
attempt = int(match.group('attempt'))
|
||||
jobs[label] = max(attempt, jobs.get(label, 0))
|
||||
|
||||
for label, attempt in jobs.items():
|
||||
name = 'Coverage {attempt} {label}'.format(label=label, attempt=attempt)
|
||||
source = os.path.join(source_directory, name)
|
||||
source_files = os.listdir(source)
|
||||
|
||||
for source_file in source_files:
|
||||
source_path = os.path.join(source, source_file)
|
||||
destination_path = os.path.join(destination_directory, source_file + '.' + label)
|
||||
print('"%s" -> "%s"' % (source_path, destination_path))
|
||||
shutil.copyfile(source_path, destination_path)
|
||||
count += 1
|
||||
|
||||
print('Coverage file count: %d' % count)
|
||||
print('##vso[task.setVariable variable=coverageFileCount]%d' % count)
|
||||
print('##vso[task.setVariable variable=outputPath]%s' % output_path)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@ -1,24 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# Check the test results and set variables for use in later steps.
|
||||
|
||||
set -o pipefail -eu
|
||||
|
||||
if [[ "$PWD" =~ /ansible_collections/ ]]; then
|
||||
output_path="tests/output"
|
||||
else
|
||||
output_path="test/results"
|
||||
fi
|
||||
|
||||
echo "##vso[task.setVariable variable=outputPath]${output_path}"
|
||||
|
||||
if compgen -G "${output_path}"'/junit/*.xml' > /dev/null; then
|
||||
echo "##vso[task.setVariable variable=haveTestResults]true"
|
||||
fi
|
||||
|
||||
if compgen -G "${output_path}"'/bot/ansible-test-*' > /dev/null; then
|
||||
echo "##vso[task.setVariable variable=haveBotResults]true"
|
||||
fi
|
||||
|
||||
if compgen -G "${output_path}"'/coverage/*' > /dev/null; then
|
||||
echo "##vso[task.setVariable variable=haveCoverageData]true"
|
||||
fi
|
||||
@ -1,121 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
"""
|
||||
Upload code coverage reports to codecov.io.
|
||||
Multiple coverage files from multiple languages are accepted and aggregated after upload.
|
||||
Python coverage, as well as PowerShell and Python stubs can all be uploaded.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import dataclasses
|
||||
import pathlib
|
||||
import shlex
|
||||
import subprocess
|
||||
import tempfile
|
||||
import typing as t
|
||||
import venv
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
class CoverageFile:
|
||||
name: str
|
||||
path: pathlib.Path
|
||||
flags: t.List[str]
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
class Args:
|
||||
dry_run: bool
|
||||
path: pathlib.Path
|
||||
|
||||
|
||||
def parse_args() -> Args:
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('-n', '--dry-run', action='store_true')
|
||||
parser.add_argument('path', type=pathlib.Path)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
# Store arguments in a typed dataclass
|
||||
fields = dataclasses.fields(Args)
|
||||
kwargs = {field.name: getattr(args, field.name) for field in fields}
|
||||
|
||||
return Args(**kwargs)
|
||||
|
||||
|
||||
def run(*args: str | pathlib.Path) -> None:
|
||||
cmd = [str(arg) for arg in args]
|
||||
print(f'==> {shlex.join(cmd)}', flush=True)
|
||||
subprocess.run(cmd, check=True)
|
||||
|
||||
|
||||
def install_codecov(dest: pathlib.Path) -> pathlib.Path:
|
||||
package = 'codecov-cli'
|
||||
version = '11.0.3'
|
||||
|
||||
venv_dir = dest / 'venv'
|
||||
python_bin = venv_dir / 'bin' / 'python'
|
||||
codecov_bin = venv_dir / 'bin' / 'codecovcli'
|
||||
|
||||
venv.create(venv_dir, with_pip=True)
|
||||
|
||||
run(python_bin, '-m', 'pip', 'install', f'{package}=={version}', '--disable-pip-version-check')
|
||||
|
||||
return codecov_bin
|
||||
|
||||
|
||||
def process_files(directory: pathlib.Path) -> t.Tuple[CoverageFile, ...]:
|
||||
processed = []
|
||||
for file in directory.joinpath('reports').glob('coverage*.xml'):
|
||||
name = file.stem.replace('coverage=', '')
|
||||
|
||||
# Get flags from name
|
||||
flags = name.replace('-powershell', '').split('=') # Drop '-powershell' suffix
|
||||
flags = [flag if not flag.startswith('stub') else flag.split('-')[0] for flag in flags] # Remove "-01" from stub files
|
||||
|
||||
processed.append(CoverageFile(name, file, flags))
|
||||
|
||||
return tuple(processed)
|
||||
|
||||
|
||||
def upload_files(codecov_bin: pathlib.Path, config_file: pathlib.Path, files: t.Tuple[CoverageFile, ...], dry_run: bool = False) -> None:
|
||||
for file in files:
|
||||
cmd = [
|
||||
codecov_bin,
|
||||
'--disable-telem',
|
||||
'--codecov-yml-path',
|
||||
config_file,
|
||||
'upload-process',
|
||||
'--disable-search',
|
||||
'--disable-file-fixes',
|
||||
'--plugin',
|
||||
'noop',
|
||||
'--name',
|
||||
file.name,
|
||||
'--file',
|
||||
file.path,
|
||||
]
|
||||
|
||||
for flag in file.flags:
|
||||
cmd.extend(['--flag', flag])
|
||||
|
||||
if dry_run:
|
||||
cmd.append('--dry-run')
|
||||
|
||||
run(*cmd)
|
||||
|
||||
|
||||
def main() -> None:
|
||||
args = parse_args()
|
||||
|
||||
with tempfile.TemporaryDirectory(prefix='codecov-') as tmpdir:
|
||||
config_file = pathlib.Path(tmpdir) / 'config.yml'
|
||||
config_file.write_text('')
|
||||
|
||||
codecov_bin = install_codecov(pathlib.Path(tmpdir))
|
||||
files = process_files(args.path)
|
||||
upload_files(codecov_bin, config_file, files, args.dry_run)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@ -1,17 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# Generate code coverage reports for uploading to Azure Pipelines and codecov.io.
|
||||
|
||||
set -o pipefail -eu
|
||||
|
||||
PATH="${PWD}/bin:${PATH}"
|
||||
|
||||
if ! ansible-test --help >/dev/null 2>&1; then
|
||||
# Install the devel version of ansible-test for generating code coverage reports.
|
||||
# This is only used by Ansible Collections, which are typically tested against multiple Ansible versions (in separate jobs).
|
||||
# Since a version of ansible-test is required that can work the output from multiple older releases, the devel version is used.
|
||||
pip install https://github.com/ansible/ansible/archive/devel.tar.gz --disable-pip-version-check
|
||||
fi
|
||||
|
||||
# Generate stubs using docker.
|
||||
# The use of docker is mandatory when Powershell code is present.
|
||||
ansible-test coverage xml --group-by command --stub --docker --color -v
|
||||
@ -1,34 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# Configure the test environment and run the tests.
|
||||
|
||||
set -o pipefail -eu
|
||||
|
||||
entry_point="$1"
|
||||
test="$2"
|
||||
read -r -a coverage_branches <<< "$3" # space separated list of branches to run code coverage on for scheduled builds
|
||||
|
||||
export COMMIT_MESSAGE
|
||||
export COMPLETE
|
||||
export COVERAGE
|
||||
export IS_PULL_REQUEST
|
||||
|
||||
if [ "${SYSTEM_PULLREQUEST_TARGETBRANCH:-}" ]; then
|
||||
IS_PULL_REQUEST=true
|
||||
COMMIT_MESSAGE=$(git log --format=%B -n 1 HEAD^2)
|
||||
else
|
||||
IS_PULL_REQUEST=
|
||||
COMMIT_MESSAGE=$(git log --format=%B -n 1 HEAD)
|
||||
fi
|
||||
|
||||
COMPLETE=
|
||||
COVERAGE=
|
||||
|
||||
if [ "${BUILD_REASON}" = "Schedule" ]; then
|
||||
COMPLETE=yes
|
||||
|
||||
if printf '%s\n' "${coverage_branches[@]}" | grep -q "^${BUILD_SOURCEBRANCHNAME}$"; then
|
||||
COVERAGE=yes
|
||||
fi
|
||||
fi
|
||||
|
||||
"${entry_point}" "${test}" 2>&1 | "$(dirname "$0")/time-command.py"
|
||||
@ -1,24 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
"""Prepends a relative timestamp to each input line from stdin and writes it to stdout."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import sys
|
||||
import time
|
||||
|
||||
|
||||
def main():
|
||||
"""Main program entry point."""
|
||||
start = time.time()
|
||||
|
||||
sys.stdin.reconfigure(errors='surrogateescape')
|
||||
sys.stdout.reconfigure(errors='surrogateescape')
|
||||
|
||||
for line in sys.stdin:
|
||||
seconds = time.time() - start
|
||||
sys.stdout.write('%02d:%02d %s' % (seconds // 60, seconds % 60, line))
|
||||
sys.stdout.flush()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@ -1,29 +0,0 @@
|
||||
# This template adds a job for processing code coverage data.
|
||||
# It will upload results to Azure Pipelines and codecov.io.
|
||||
# Use it from a job stage that completes after all other jobs have completed.
|
||||
# This can be done by placing it in a separate summary stage that runs after the test stage(s) have completed.
|
||||
|
||||
jobs:
|
||||
- job: Coverage
|
||||
displayName: Code Coverage
|
||||
container: $[ variables.defaultContainer ]
|
||||
workspace:
|
||||
clean: all
|
||||
steps:
|
||||
- checkout: self
|
||||
fetchDepth: $(fetchDepth)
|
||||
path: $(checkoutPath)
|
||||
- task: DownloadPipelineArtifact@2
|
||||
displayName: Download Coverage Data
|
||||
inputs:
|
||||
path: coverage/
|
||||
patterns: "Coverage */*=coverage.combined"
|
||||
- bash: .azure-pipelines/scripts/combine-coverage.py coverage/
|
||||
displayName: Combine Coverage Data
|
||||
- bash: .azure-pipelines/scripts/report-coverage.sh
|
||||
displayName: Generate Coverage Report
|
||||
condition: gt(variables.coverageFileCount, 0)
|
||||
- bash: .azure-pipelines/scripts/publish-codecov.py "$(outputPath)"
|
||||
displayName: Publish to codecov.io
|
||||
condition: gt(variables.coverageFileCount, 0)
|
||||
continueOnError: true
|
||||
@ -1,55 +0,0 @@
|
||||
# This template uses the provided targets and optional groups to generate a matrix which is then passed to the test template.
|
||||
# If this matrix template does not provide the required functionality, consider using the test template directly instead.
|
||||
|
||||
parameters:
|
||||
# A required list of dictionaries, one per test target.
|
||||
# Each item in the list must contain a "test" or "name" key.
|
||||
# Both may be provided. If one is omitted, the other will be used.
|
||||
- name: targets
|
||||
type: object
|
||||
|
||||
# An optional list of values which will be used to multiply the targets list into a matrix.
|
||||
# Values can be strings or numbers.
|
||||
- name: groups
|
||||
type: object
|
||||
default: []
|
||||
|
||||
# An optional format string used to generate the job name.
|
||||
# - {0} is the name of an item in the targets list.
|
||||
- name: nameFormat
|
||||
type: string
|
||||
default: "{0}"
|
||||
|
||||
# An optional format string used to generate the test name.
|
||||
# - {0} is the name of an item in the targets list.
|
||||
- name: testFormat
|
||||
type: string
|
||||
default: "{0}"
|
||||
|
||||
# An optional format string used to add the group to the job name.
|
||||
# {0} is the formatted name of an item in the targets list.
|
||||
# {{1}} is the group -- be sure to include the double "{{" and "}}".
|
||||
- name: nameGroupFormat
|
||||
type: string
|
||||
default: "{0} - {{1}}"
|
||||
|
||||
# An optional format string used to add the group to the test name.
|
||||
# {0} is the formatted test of an item in the targets list.
|
||||
# {{1}} is the group -- be sure to include the double "{{" and "}}".
|
||||
- name: testGroupFormat
|
||||
type: string
|
||||
default: "{0}/{{1}}"
|
||||
|
||||
jobs:
|
||||
- template: test.yml
|
||||
parameters:
|
||||
jobs:
|
||||
- ${{ if eq(length(parameters.groups), 0) }}:
|
||||
- ${{ each target in parameters.targets }}:
|
||||
- name: ${{ format(parameters.nameFormat, coalesce(target.name, target.test)) }}
|
||||
test: ${{ format(parameters.testFormat, coalesce(target.test, target.name)) }}
|
||||
- ${{ if not(eq(length(parameters.groups), 0)) }}:
|
||||
- ${{ each group in parameters.groups }}:
|
||||
- ${{ each target in parameters.targets }}:
|
||||
- name: ${{ format(format(parameters.nameGroupFormat, parameters.nameFormat), coalesce(target.name, target.test), group) }}
|
||||
test: ${{ format(format(parameters.testGroupFormat, parameters.testFormat), coalesce(target.test, target.name), group) }}
|
||||
@ -1,45 +0,0 @@
|
||||
# This template uses the provided list of jobs to create test one or more test jobs.
|
||||
# It can be used directly if needed, or through the matrix template.
|
||||
|
||||
parameters:
|
||||
# A required list of dictionaries, one per test job.
|
||||
# Each item in the list must contain a "job" and "name" key.
|
||||
- name: jobs
|
||||
type: object
|
||||
|
||||
jobs:
|
||||
- ${{ each job in parameters.jobs }}:
|
||||
- job: test_${{ replace(replace(replace(replace(job.test, '/', '_'), '.', '_'), '-', '_'), '@', '_') }}
|
||||
displayName: ${{ job.name }}
|
||||
container: $[ variables.defaultContainer ]
|
||||
workspace:
|
||||
clean: all
|
||||
steps:
|
||||
- checkout: self
|
||||
fetchDepth: $(fetchDepth)
|
||||
path: $(checkoutPath)
|
||||
- bash: .azure-pipelines/scripts/run-tests.sh "$(entryPoint)" "${{ job.test }}" "$(coverageBranches)"
|
||||
displayName: Run Tests
|
||||
- bash: .azure-pipelines/scripts/process-results.sh
|
||||
condition: succeededOrFailed()
|
||||
displayName: Process Results
|
||||
- bash: .azure-pipelines/scripts/aggregate-coverage.sh "$(Agent.TempDirectory)"
|
||||
condition: eq(variables.haveCoverageData, 'true')
|
||||
displayName: Aggregate Coverage Data
|
||||
- task: PublishTestResults@2
|
||||
condition: eq(variables.haveTestResults, 'true')
|
||||
inputs:
|
||||
testResultsFiles: "$(outputPath)/junit/*.xml"
|
||||
displayName: Publish Test Results
|
||||
- task: PublishPipelineArtifact@1
|
||||
condition: eq(variables.haveBotResults, 'true')
|
||||
displayName: Publish Bot Results
|
||||
inputs:
|
||||
targetPath: "$(outputPath)/bot/"
|
||||
artifactName: "Bot $(System.JobAttempt) $(System.StageDisplayName) $(System.JobDisplayName)"
|
||||
- task: PublishPipelineArtifact@1
|
||||
condition: eq(variables.haveCoverageData, 'true')
|
||||
displayName: Publish Coverage Data
|
||||
inputs:
|
||||
targetPath: "$(Agent.TempDirectory)/coverage/"
|
||||
artifactName: "Coverage $(System.JobAttempt) $(System.StageDisplayName) $(System.JobDisplayName)"
|
||||
@ -1,5 +0,0 @@
|
||||
team = "ansible"
|
||||
repo = "ansible"
|
||||
check_sha = "f31421576b00f0b167cdbe61217c31c21a41ac02" # the very first commit in repo
|
||||
fix_commit_msg = false # Don't replace "#" with "GH-"
|
||||
default_branch = "devel"
|
||||
25
.coveragerc
Normal file
25
.coveragerc
Normal file
@ -0,0 +1,25 @@
|
||||
# This configuration file is used for manual execution of coverage
|
||||
# as well as for tests run through ansible-test.
|
||||
|
||||
[run]
|
||||
branch = True
|
||||
|
||||
# Enable concurrency. This also enables parallel mode, which results in
|
||||
# multiple coverage files being created. Concurrency allows us to collect
|
||||
# results from multiple tests simultaneously, as well as supporting multiple
|
||||
# test runs, such as from integration tests.
|
||||
concurrency = multiprocessing
|
||||
parallel = True
|
||||
|
||||
# When running tests through ansible-test, this option is overridden by
|
||||
# the COVERAGE_FILE environment variable. This option is present for
|
||||
# convenience when running coverage manually from this directory.
|
||||
data_file = test/results/coverage/coverage
|
||||
|
||||
# Don't collect or report code coverage from files matching these patterns.
|
||||
omit =
|
||||
*/python*/dist-packages/*
|
||||
*/python*/site-packages/*
|
||||
*/python*/distutils/*
|
||||
*/pyshared/*
|
||||
*/pytest
|
||||
@ -1,6 +0,0 @@
|
||||
# .git-blame-ignore-revs
|
||||
# Bulk PowerShell sanity fixes
|
||||
6def4a3180fe03981ba64c6d8db28fed3bb39c0c
|
||||
716631189cb5a3f66b3add98f39e64e98bc17bf7
|
||||
# Bulk update of strings from triple single quotes to triple double quotes
|
||||
a0495fc31497798a7a833ba7406a9729e1528dd8
|
||||
3
.gitattributes
vendored
3
.gitattributes
vendored
@ -1 +1,4 @@
|
||||
CHANGELOG.md merge=union
|
||||
.github/ export-ignore
|
||||
hacking/ export-ignore
|
||||
ticket-stubs/ export-ignore
|
||||
|
||||
1117
.github/BOTMETA.yml
vendored
Normal file
1117
.github/BOTMETA.yml
vendored
Normal file
File diff suppressed because it is too large
Load Diff
3
.github/CODE_OF_CONDUCT.md
vendored
3
.github/CODE_OF_CONDUCT.md
vendored
@ -1,3 +0,0 @@
|
||||
# Community Code of Conduct
|
||||
|
||||
Please see the official [Ansible Community Code of Conduct](https://docs.ansible.com/ansible/latest/community/code_of_conduct.html).
|
||||
78
.github/CONTRIBUTING.md
vendored
78
.github/CONTRIBUTING.md
vendored
@ -1,78 +0,0 @@
|
||||
# WELCOME TO ANSIBLE GITHUB
|
||||
|
||||
Hi! Nice to see you here!
|
||||
|
||||
## QUESTIONS ?
|
||||
|
||||
If you have questions about anything related to Ansible, get in touch with us!
|
||||
See [Communicating with the Ansible community](https://docs.ansible.com/ansible/devel/community/communication.html) to find out how.
|
||||
|
||||
The [Community Guide](https://docs.ansible.com/ansible/devel/community/index.html) also explains how to contribute
|
||||
and interact with the project, including how to submit bug reports and code to Ansible.
|
||||
|
||||
Please note that the GitHub issue tracker is not the best place to ask questions for several reasons.
|
||||
You'll get more helpful, and quicker, responses in the forum.
|
||||
|
||||
## CONTRIBUTING ?
|
||||
|
||||
By contributing to this project you agree to the [Developer Certificate of Origin (DCO)](#developer-certificate-of-origin-dco).
|
||||
|
||||
The Ansible project is licensed under the [GPL-3.0](COPYING) or later. Some portions of the code fall under other licenses as noted in individual files.
|
||||
|
||||
The Ansible project accepts contributions through GitHub pull requests.
|
||||
Please review the [Community Guide](https://docs.ansible.com/ansible/devel/community/index.html) for more information on contributing to Ansible.
|
||||
|
||||
## BUG TO REPORT ?
|
||||
|
||||
First and foremost, also check the [Community Guide](https://docs.ansible.com/ansible/devel/community/index.html).
|
||||
|
||||
You can report bugs or make enhancement requests at
|
||||
the [Ansible GitHub issue page](http://github.com/ansible/ansible/issues/new/choose) by filling out the issue template that will be presented.
|
||||
|
||||
Also please make sure you are testing on the latest released version of Ansible or the development branch.
|
||||
See the [Installation Guide](https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html) for details.
|
||||
|
||||
Thanks!
|
||||
|
||||
## DEVELOPER CERTIFICATE OF ORIGIN (DCO)
|
||||
|
||||
This document was created by the Linux Kernel community and is a simple statement that you, as a contributor, have the legal right to make the contribution.
|
||||
|
||||
```text
|
||||
Developer Certificate of Origin
|
||||
Version 1.1
|
||||
|
||||
Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
|
||||
1 Letterman Drive
|
||||
Suite D4700
|
||||
San Francisco, CA, 94129
|
||||
|
||||
Everyone is permitted to copy and distribute verbatim copies of this
|
||||
license document, but changing it is not allowed.
|
||||
|
||||
Developer's Certificate of Origin 1.1
|
||||
|
||||
By making a contribution to this project, I certify that:
|
||||
|
||||
(a) The contribution was created in whole or in part by me and I
|
||||
have the right to submit it under the open source license
|
||||
indicated in the file; or
|
||||
|
||||
(b) The contribution is based upon previous work that, to the best
|
||||
of my knowledge, is covered under an appropriate open source
|
||||
license and I have the right under that license to submit that
|
||||
work with modifications, whether created in whole or in part
|
||||
by me, under the same open source license (unless I am
|
||||
permitted to submit under a different license), as indicated
|
||||
in the file; or
|
||||
|
||||
(c) The contribution was provided directly to me by some other
|
||||
person who certified (a), (b) or (c) and I have not modified
|
||||
it.
|
||||
|
||||
(d) I understand and agree that this project and the contribution
|
||||
are public and that a record of the contribution (including all
|
||||
personal information I submit with it, including my sign-off) is
|
||||
maintained indefinitely and may be redistributed consistent with
|
||||
this project or the open source license(s) involved.
|
||||
```
|
||||
64
.github/ISSUE_TEMPLATE.md
vendored
64
.github/ISSUE_TEMPLATE.md
vendored
@ -1 +1,63 @@
|
||||
Please raise issues via the [new interface](https://github.com/ansible/ansible/issues/new/choose)
|
||||
<!---
|
||||
Verify first that your issue/request is not already reported on GitHub.
|
||||
Also test if the latest release, and master branch are affected too.
|
||||
-->
|
||||
|
||||
##### ISSUE TYPE
|
||||
<!--- Pick one below and delete the rest: -->
|
||||
- Bug Report
|
||||
- Feature Idea
|
||||
- Documentation Report
|
||||
|
||||
##### COMPONENT NAME
|
||||
<!--- Name of the module/plugin/task/feature -->
|
||||
|
||||
##### ANSIBLE VERSION
|
||||
<!--- Paste verbatim output from "ansible --version" between quotes below -->
|
||||
```
|
||||
|
||||
```
|
||||
|
||||
##### CONFIGURATION
|
||||
<!---
|
||||
If using Ansible 2.4 or above, paste the results of "ansible-config dump --only-changed"
|
||||
|
||||
Otherwise, mention any settings you have changed/added/removed in ansible.cfg
|
||||
(or using the ANSIBLE_* environment variables).
|
||||
|
||||
-->
|
||||
|
||||
##### OS / ENVIRONMENT
|
||||
<!---
|
||||
Mention the OS you are running Ansible from, and the OS you are
|
||||
managing, or say "N/A" for anything that is not platform-specific.
|
||||
Also mention the specific version of what you are trying to control,
|
||||
e.g. if this is a network bug the version of firmware on the network device.
|
||||
-->
|
||||
|
||||
##### SUMMARY
|
||||
<!--- Explain the problem briefly -->
|
||||
|
||||
##### STEPS TO REPRODUCE
|
||||
<!---
|
||||
For bugs, show exactly how to reproduce the problem, using a minimal test-case.
|
||||
For new features, show how the feature would be used.
|
||||
-->
|
||||
|
||||
<!--- Paste example playbooks or commands between quotes below -->
|
||||
```yaml
|
||||
|
||||
```
|
||||
|
||||
<!--- You can also paste gist.github.com links for larger files -->
|
||||
|
||||
##### EXPECTED RESULTS
|
||||
<!--- What did you expect to happen when running the steps above? -->
|
||||
|
||||
##### ACTUAL RESULTS
|
||||
<!--- What actually happened? If possible run with extra verbosity (-vvvv) -->
|
||||
|
||||
<!--- Paste verbatim command output between quotes below -->
|
||||
```
|
||||
|
||||
```
|
||||
|
||||
250
.github/ISSUE_TEMPLATE/bug_report.yml
vendored
250
.github/ISSUE_TEMPLATE/bug_report.yml
vendored
@ -1,250 +0,0 @@
|
||||
---
|
||||
name: 🐛 Bug report
|
||||
description: Create a report to help us improve
|
||||
|
||||
body:
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: >
|
||||
**Thank you for wanting to report a bug in ansible-core!**
|
||||
|
||||
|
||||
⚠
|
||||
Verify first that your issue is not [already reported on
|
||||
GitHub][issue search] and keep in mind that we may have to keep
|
||||
the current behavior because [every change breaks someone's
|
||||
workflow][XKCD 1172].
|
||||
We try to be mindful about this.
|
||||
|
||||
Also test if the latest release and devel branch are affected too.
|
||||
|
||||
|
||||
**Tip:** If you are seeking community support, please see
|
||||
[Communicating with the Ansible community][communication] to
|
||||
get in touch and ask questions.
|
||||
|
||||
|
||||
|
||||
[communication]:
|
||||
https://docs.ansible.com/ansible/devel/community/communication.html
|
||||
|
||||
[issue search]: ../search?q=is%3Aissue&type=issues
|
||||
|
||||
[XKCD 1172]: https://xkcd.com/1172/
|
||||
|
||||
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: Summary
|
||||
description: Explain the problem briefly below.
|
||||
placeholder: >-
|
||||
When I try to do X with ansible-core from the devel branch on GitHub, Y
|
||||
breaks in a way Z under the env E. Here are all the details I know
|
||||
about this problem...
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: dropdown
|
||||
attributes:
|
||||
label: Issue Type
|
||||
description: This is a marker for our automatic bot. Do not change it.
|
||||
options:
|
||||
- Bug Report
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: input
|
||||
attributes:
|
||||
label: Component Name
|
||||
description: >
|
||||
Write the short name of the rst file, module, plugin, task or
|
||||
feature below, *use your best guess if unsure*.
|
||||
|
||||
|
||||
**Tip:** Cannot find it in this repository? Please be advised that
|
||||
the source for some parts of the documentation are hosted outside
|
||||
of this repository. If the page you are reporting describes
|
||||
modules/plugins/etc that are not officially supported by the
|
||||
Ansible Core Engineering team, there is a good chance that it is
|
||||
coming from one of the [Ansible Collections maintained by the
|
||||
community][collections org]. If this is the case, please make sure
|
||||
to file an issue under the appropriate project there instead.
|
||||
|
||||
|
||||
[collections org]: /ansible-collections
|
||||
placeholder: dnf, apt, pip, user etc.
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: Ansible Version
|
||||
description: >-
|
||||
Paste verbatim output from `ansible --version` below, under
|
||||
the prompt line. Please don't wrap it with triple backticks — your
|
||||
whole input will be turned into a code snippet automatically.
|
||||
render: console
|
||||
value: |
|
||||
$ ansible --version
|
||||
placeholder: |
|
||||
$ ansible --version
|
||||
ansible [core 2.11.0b4.post0] (detached HEAD ref: refs/) last updated 2021/04/02 00:33:35 (GMT +200)
|
||||
config file = None
|
||||
configured module search path = ['~/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
|
||||
ansible python module location = ~/src/github/ansible/ansible/lib/ansible
|
||||
ansible collection location = ~/.ansible/collections:/usr/share/ansible/collections
|
||||
executable location = bin/ansible
|
||||
python version = 3.9.0 (default, Oct 26 2020, 13:08:59) [GCC 10.2.0]
|
||||
jinja version = 2.11.3
|
||||
libyaml = True
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: Configuration
|
||||
description: >-
|
||||
Paste verbatim output from `ansible-config dump --only-changed -t all` below, under the prompt line.
|
||||
(if using a version older than ansible-core 2.12 you should omit the '-t all')
|
||||
Please don't wrap it with triple backticks — your
|
||||
whole input will be turned into a code snippet automatically.
|
||||
render: console
|
||||
value: |
|
||||
# if using a version older than ansible-core 2.12 you should omit the '-t all'
|
||||
$ ansible-config dump --only-changed -t all
|
||||
placeholder: |
|
||||
# if using a version older than ansible-core 2.12 you should omit the '-t all'
|
||||
$ ansible-config dump --only-changed -t all
|
||||
DEFAULT_GATHERING(~/src/github/ansible/ansible/ansible.cfg) = smart
|
||||
DEFAULT_HOST_LIST(~/src/github/ansible/ansible/ansible.cfg) = ['~/src/github/ansible/ansible/hosts']
|
||||
DEFAULT_VAULT_PASSWORD_FILE(~/src/github/ansible/ansible/ansible.cfg) = ~/src/github/ansible/ansible/vault/print-password.sh
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: OS / Environment
|
||||
description: >-
|
||||
Provide all relevant information below, e.g. target OS versions,
|
||||
network device firmware, etc.
|
||||
placeholder: RHEL 8, CentOS Stream etc.
|
||||
validations:
|
||||
required: true
|
||||
|
||||
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: Steps to Reproduce
|
||||
description: |
|
||||
Describe exactly how to reproduce the problem, using a minimal test-case. It would *really* help us understand your problem if you could also provide any playbooks, configs and commands you used.
|
||||
|
||||
**HINT:** You can paste https://gist.github.com links for larger files.
|
||||
value: |
|
||||
<!--- Paste example playbooks or commands between quotes below -->
|
||||
```yaml (paste below)
|
||||
|
||||
```
|
||||
placeholder: |
|
||||
1. Implement the following playbook:
|
||||
|
||||
```yaml
|
||||
---
|
||||
# ping.yml
|
||||
- hosts: all
|
||||
gather_facts: false
|
||||
tasks:
|
||||
- ping:
|
||||
...
|
||||
```
|
||||
2. Then run `ANSIBLE_DEBUG=1 ansible-playbook ping.yml -vvvvv`
|
||||
3. An error occurs.
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: Expected Results
|
||||
description: >-
|
||||
Describe what you expected to happen when running the steps above.
|
||||
placeholder: >-
|
||||
I expected X to happen because I assumed Y and was shocked
|
||||
that it did not.
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: Actual Results
|
||||
description: |
|
||||
Describe what actually happened. If possible run with extra verbosity (`-vvvv`).
|
||||
|
||||
Paste verbatim command output and don't wrap it with triple backticks — your
|
||||
whole input will be turned into a code snippet automatically.
|
||||
render: console
|
||||
placeholder: >-
|
||||
Certificate did not match expected hostname: files.pythonhosted.org. Certificate: {'notAfter': 'Apr 28 19:20:25 2021 GMT', 'subjectAltName': ((u'DNS', 'r.ssl.fastly.net'), (u'DNS', '*.catchpoint.com'), (u'DNS', '*.cnn.io'), (u'DNS', '*.dollarshaveclub.com'), (u'DNS', '*.eater.com'), (u'DNS', '*.fastly.picmonkey.com'), (u'DNS', '*.files.saymedia-content.com'), (u'DNS', '*.ft.com'), (u'DNS', '*.meetupstatic.com'), (u'DNS', '*.nfl.com'), (u'DNS', '*.pagar.me'), (u'DNS', '*.picmonkey.com'), (u'DNS', '*.realself.com'), (u'DNS', '*.sbnation.com'), (u'DNS', '*.shakr.com'), (u'DNS', '*.streamable.com'), (u'DNS', '*.surfly.com'), (u'DNS', '*.theverge.com'), (u'DNS', '*.thrillist.com'), (u'DNS', '*.vox-cdn.com'), (u'DNS', '*.vox.com'), (u'DNS', '*.voxmedia.com'), (u'DNS', 'eater.com'), (u'DNS', 'ft.com'), (u'DNS', 'i.gse.io'), (u'DNS', 'picmonkey.com'), (u'DNS', 'realself.com'), (u'DNS', 'static.wixstatic.com'), (u'DNS', 'streamable.com'), (u'DNS', 'surfly.com'), (u'DNS', 'theverge.com'), (u'DNS', 'vox-cdn.com'), (u'DNS', 'vox.com'), (u'DNS', 'www.joyent.com')), 'subject': ((('countryName', u'US'),), (('stateOrProvinceName', u'California'),), (('localityName', u'San Francisco'),), (('organizationName', u'Fastly, Inc'),), (('commonName', u'r.ssl.fastly.net'),))}
|
||||
Exception:
|
||||
Traceback (most recent call last):
|
||||
File "/usr/local/lib/python2.6/dist-packages/pip/basecommand.py", line 215, in main
|
||||
status = self.run(options, args)
|
||||
File "/usr/local/lib/python2.6/dist-packages/pip/commands/install.py", line 335, in run
|
||||
wb.build(autobuilding=True)
|
||||
File "/usr/local/lib/python2.6/dist-packages/pip/wheel.py", line 749, in build
|
||||
self.requirement_set.prepare_files(self.finder)
|
||||
File "/usr/local/lib/python2.6/dist-packages/pip/req/req_set.py", line 380, in prepare_files
|
||||
ignore_dependencies=self.ignore_dependencies))
|
||||
File "/usr/local/lib/python2.6/dist-packages/pip/req/req_set.py", line 620, in _prepare_file
|
||||
session=self.session, hashes=hashes)
|
||||
File "/usr/local/lib/python2.6/dist-packages/pip/download.py", line 821, in unpack_url
|
||||
hashes=hashes
|
||||
File "/usr/local/lib/python2.6/dist-packages/pip/download.py", line 659, in unpack_http_url
|
||||
hashes)
|
||||
File "/usr/local/lib/python2.6/dist-packages/pip/download.py", line 853, in _download_http_url
|
||||
stream=True,
|
||||
File "/usr/local/lib/python2.6/dist-packages/pip/_vendor/requests/sessions.py", line 521, in get
|
||||
return self.request('GET', url, **kwargs)
|
||||
File "/usr/local/lib/python2.6/dist-packages/pip/download.py", line 386, in request
|
||||
return super(PipSession, self).request(method, url, *args, **kwargs)
|
||||
File "/usr/local/lib/python2.6/dist-packages/pip/_vendor/requests/sessions.py", line 508, in request
|
||||
resp = self.send(prep, **send_kwargs)
|
||||
File "/usr/local/lib/python2.6/dist-packages/pip/_vendor/requests/sessions.py", line 618, in send
|
||||
r = adapter.send(request, **kwargs)
|
||||
File "/usr/local/lib/python2.6/dist-packages/pip/_vendor/cachecontrol/adapter.py", line 47, in send
|
||||
resp = super(CacheControlAdapter, self).send(request, **kw)
|
||||
File "/usr/local/lib/python2.6/dist-packages/pip/_vendor/requests/adapters.py", line 506, in send
|
||||
raise SSLError(e, request=request)
|
||||
SSLError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Max retries exceeded with url: /packages/ef/ab/aa12712415809bf698e719b307419f953e25344e8f42d557533d7a02b276/netapp_lib-2020.7.16-py2-none-any.whl (Caused by SSLError(CertificateError("hostname 'files.pythonhosted.org' doesn't match either of 'r.ssl.fastly.net', '*.catchpoint.com', '*.cnn.io', '*.dollarshaveclub.com', '*.eater.com', '*.fastly.picmonkey.com', '*.files.saymedia-content.com', '*.ft.com', '*.meetupstatic.com', '*.nfl.com', '*.pagar.me', '*.picmonkey.com', '*.realself.com', '*.sbnation.com', '*.shakr.com', '*.streamable.com', '*.surfly.com', '*.theverge.com', '*.thrillist.com', '*.vox-cdn.com', '*.vox.com', '*.voxmedia.com', 'eater.com', 'ft.com', 'i.gse.io', 'picmonkey.com', 'realself.com', 'static.wixstatic.com', 'streamable.com', 'surfly.com', 'theverge.com', 'vox-cdn.com', 'vox.com', 'www.joyent.com'",),))
|
||||
ERROR: Command "/usr/bin/python2.6 /root/ansible/test/lib/ansible_test/_data/quiet_pip.py install --disable-pip-version-check -r /root/ansible/test/lib/ansible_test/_data/requirements/units.txt -r tests/unit/requirements.txt -c /root/ansible/test/lib/ansible_test/_data/requirements/constraints.txt" returned exit status 2.
|
||||
ERROR: Command "docker exec d47eb360db4ce779c1f690db964655b76e68895c4360ff252c46fe7fe6f5c75a /usr/bin/env ANSIBLE_TEST_CONTENT_ROOT=/root/ansible_collections/netapp/ontap LC_ALL=en_US.UTF-8 /usr/bin/python3.6 /root/ansible/bin/ansible-test units --metadata tests/output/.tmp/metadata-9i2qfrcl.json --truncate 200 --redact --color yes --requirements --python default --requirements-mode only" returned exit status 1.
|
||||
validations:
|
||||
required: true
|
||||
|
||||
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: >
|
||||
*One last thing...*
|
||||
|
||||
|
||||
*Please, complete **all** sections as described, this form
|
||||
is [processed automatically by a robot][ansibot help].*
|
||||
|
||||
|
||||
Thank you for your collaboration!
|
||||
|
||||
|
||||
[ansibot help]:
|
||||
/ansible/ansibotmini#ansibotmini
|
||||
|
||||
|
||||
- type: checkboxes
|
||||
attributes:
|
||||
label: Code of Conduct
|
||||
description: |
|
||||
Read the [Ansible Code of Conduct][CoC] first.
|
||||
|
||||
[CoC]: https://docs.ansible.com/ansible/devel/community/code_of_conduct.html?utm_medium=github&utm_source=issue_form--bug_report.yml
|
||||
options:
|
||||
- label: I agree to follow the Ansible Code of Conduct
|
||||
required: true
|
||||
...
|
||||
26
.github/ISSUE_TEMPLATE/config.yml
vendored
26
.github/ISSUE_TEMPLATE/config.yml
vendored
@ -1,26 +0,0 @@
|
||||
# Ref: https://help.github.com/en/github/building-a-strong-community/configuring-issue-templates-for-your-repository#configuring-the-template-chooser
|
||||
blank_issues_enabled: false # default: true
|
||||
contact_links:
|
||||
- name: 🔐 Security bug report 🔥
|
||||
url: https://docs.ansible.com/ansible/devel/community/reporting_bugs_and_features.html?utm_medium=github&utm_source=issue_template_chooser
|
||||
about: |
|
||||
Please learn how to report security vulnerabilities here.
|
||||
|
||||
For all security related bugs, email security@ansible.com
|
||||
instead of using this issue tracker and you will receive
|
||||
a prompt response.
|
||||
|
||||
For more information, see
|
||||
https://docs.ansible.com/ansible/devel/community/reporting_bugs_and_features.html
|
||||
- name: 📝 Ansible Code of Conduct
|
||||
url: https://docs.ansible.com/ansible/devel/community/code_of_conduct.html?utm_medium=github&utm_source=issue_template_chooser
|
||||
about: ❤ Be nice to other members of the community. ☮ Behave.
|
||||
- name: 💬 Talk to the community
|
||||
url: https://docs.ansible.com/ansible/devel/community/communication.html?utm_medium=github&utm_source=issue_template_chooser#forum
|
||||
about: Please ask and answer usage questions here
|
||||
- name: ⚡ Working groups
|
||||
url: https://forum.ansible.com/g?utm_medium=github&utm_source=issue_template_chooser
|
||||
about: Interested in improving a specific area? Become a part of a working group!
|
||||
- name: 💼 For Enterprise
|
||||
url: https://www.ansible.com/products/engine?utm_medium=github&utm_source=issue_template_chooser
|
||||
about: Red Hat offers support for the Ansible Automation Platform
|
||||
201
.github/ISSUE_TEMPLATE/documentation_report.yml
vendored
201
.github/ISSUE_TEMPLATE/documentation_report.yml
vendored
@ -1,201 +0,0 @@
|
||||
---
|
||||
name: 📝 Documentation Report
|
||||
description: Ask us about docs
|
||||
|
||||
body:
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: >
|
||||
**Thank you for wanting to report a problem with ansible-core
|
||||
documentation!**
|
||||
|
||||
|
||||
Please fill out your suggestions below. If the problem seems
|
||||
straightforward, feel free to go ahead and
|
||||
[submit a pull request] instead!
|
||||
|
||||
|
||||
⚠
|
||||
Verify first that your issue is not [already reported on
|
||||
GitHub][issue search].
|
||||
|
||||
Also test if the latest release and devel branch are affected too.
|
||||
|
||||
|
||||
**Tip:** If you are seeking community support, please see
|
||||
[Communicating with the Ansible community][communication] to
|
||||
get in touch and ask questions.
|
||||
|
||||
|
||||
|
||||
[communication]:
|
||||
https://docs.ansible.com/ansible/devel/community/communication.html
|
||||
|
||||
[issue search]: ../search?q=is%3Aissue&type=issues
|
||||
|
||||
[submit a pull request]:
|
||||
https://docs.ansible.com/ansible-core/devel/community/documentation_contributions.html
|
||||
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: >
|
||||
**Check the repository for your issue.**
|
||||
|
||||
Source files for Ansible community documentation are
|
||||
hosted in different repositories. Please make sure to file an
|
||||
issue in the correct project.
|
||||
|
||||
Documentation for modules/plugins/etc that are officially
|
||||
supported by the Ansible Core Engineering team is available
|
||||
in this (`ansible/ansible`) repository.
|
||||
|
||||
The Installation Guide, Playbook Guide, Developer Guide,
|
||||
and other documentation is available in the
|
||||
[ansible/ansible-documentation] repository.
|
||||
Documentation for other modules/plugins/etc is likely to be
|
||||
available in one of the [Ansible Collections][collections index].
|
||||
If available in the collection documentation, select the
|
||||
**Issue Tracker** button to go directly to the GitHub issues.
|
||||
|
||||
|
||||
[ansible/ansible-documentation]: /ansible/ansible-documentation
|
||||
|
||||
[collections index]:
|
||||
https://docs.ansible.com/ansible/latest/collections/index.html
|
||||
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: Summary
|
||||
description: >
|
||||
Explain the problem briefly below, add suggestions to wording
|
||||
or structure.
|
||||
|
||||
|
||||
**HINT:** Did you know the documentation has a `View on GitHub`
|
||||
link on some pages? Feel free to use it to start a pull request
|
||||
right from the GitHub UI!
|
||||
placeholder: >-
|
||||
I was reading the ansible-core documentation of version X and I'm having
|
||||
problems understanding Y. It would be very helpful if that got
|
||||
rephrased as Z.
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: dropdown
|
||||
attributes:
|
||||
label: Issue Type
|
||||
description: This is a marker for our automatic bot. Do not change it.
|
||||
options:
|
||||
- Documentation Report
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: input
|
||||
attributes:
|
||||
label: Component Name
|
||||
description: >
|
||||
Write the short name of the rst file, module, plugin, task or
|
||||
feature below, *use your best guess if unsure*.
|
||||
|
||||
placeholder: lib/ansible/modules/copy.py
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: Ansible Version
|
||||
description: >-
|
||||
Paste verbatim output from `ansible --version` below, under
|
||||
the prompt line. Please don't wrap it with triple backticks — your
|
||||
whole input will be turned into a code snippet automatically.
|
||||
render: console
|
||||
value: |
|
||||
$ ansible --version
|
||||
placeholder: |
|
||||
$ ansible --version
|
||||
ansible [core 2.11.0b4.post0] (detached HEAD ref: refs/) last updated 2021/04/02 00:33:35 (GMT +200)
|
||||
config file = None
|
||||
configured module search path = ['~/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
|
||||
ansible python module location = ~/src/github/ansible/ansible/lib/ansible
|
||||
ansible collection location = ~/.ansible/collections:/usr/share/ansible/collections
|
||||
executable location = bin/ansible
|
||||
python version = 3.9.0 (default, Oct 26 2020, 13:08:59) [GCC 10.2.0]
|
||||
jinja version = 2.11.3
|
||||
libyaml = True
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: Configuration
|
||||
description: >-
|
||||
Paste verbatim output from `ansible-config dump --only-changed -t all` below, under the prompt line.
|
||||
(if using a version older than ansible-core 2.12 you should omit the '-t all')
|
||||
Please don't wrap it with triple backticks — your
|
||||
whole input will be turned into a code snippet automatically.
|
||||
render: console
|
||||
value: |
|
||||
# if using a version older than ansible-core 2.12 you should omit the '-t all'
|
||||
$ ansible-config dump --only-changed -t all
|
||||
placeholder: |
|
||||
# if using a version older than ansible-core 2.12 you should omit the '-t all'
|
||||
$ ansible-config dump --only-changed -t all
|
||||
DEFAULT_GATHERING(~/src/github/ansible/ansible/ansible.cfg) = smart
|
||||
DEFAULT_HOST_LIST(~/src/github/ansible/ansible/ansible.cfg) = ['~/src/github/ansible/ansible/hosts']
|
||||
DEFAULT_VAULT_PASSWORD_FILE(~/src/github/ansible/ansible/ansible.cfg) = ~/src/github/ansible/ansible/vault/print-password.sh
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: OS / Environment
|
||||
description: >-
|
||||
Provide all relevant information below, e.g. OS version,
|
||||
browser, etc.
|
||||
placeholder: Fedora 33, Firefox etc.
|
||||
validations:
|
||||
required: true
|
||||
|
||||
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: Additional Information
|
||||
description: |
|
||||
Describe how this improves the documentation, e.g. before/after situation or screenshots.
|
||||
|
||||
**HINT:** You can paste https://gist.github.com links for larger files.
|
||||
placeholder: >-
|
||||
When the improvement is applied, it makes it more straightforward
|
||||
to understand X.
|
||||
validations:
|
||||
required: true
|
||||
|
||||
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: >
|
||||
*One last thing...*
|
||||
|
||||
|
||||
*Please, complete **all** sections as described, this form
|
||||
is [processed automatically by a robot][ansibot help].*
|
||||
|
||||
|
||||
Thank you for your collaboration!
|
||||
|
||||
|
||||
[ansibot help]:
|
||||
/ansible/ansibotmini#ansibotmini
|
||||
|
||||
|
||||
- type: checkboxes
|
||||
attributes:
|
||||
label: Code of Conduct
|
||||
description: |
|
||||
Read the [Ansible Code of Conduct][CoC] first.
|
||||
|
||||
[CoC]: https://docs.ansible.com/ansible/devel/community/code_of_conduct.html?utm_medium=github&utm_source=issue_form--documentation_report.yml
|
||||
options:
|
||||
- label: I agree to follow the Ansible Code of Conduct
|
||||
required: true
|
||||
...
|
||||
176
.github/ISSUE_TEMPLATE/feature_request.yml
vendored
176
.github/ISSUE_TEMPLATE/feature_request.yml
vendored
@ -1,176 +0,0 @@
|
||||
---
|
||||
name: ✨ Feature request
|
||||
description: Suggest an idea for this project
|
||||
|
||||
body:
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: >
|
||||
**Thank you for wanting to suggest a feature for ansible-core!**
|
||||
|
||||
|
||||
|
||||
💡
|
||||
Before you go ahead with your request, please first consider if it
|
||||
would be useful for majority of the ansible-core users. As a
|
||||
general rule of thumb, any feature that is only of interest to a
|
||||
small sub group should be [implemented in a third-party Ansible
|
||||
Collection][contribute to collections] or maybe even just your
|
||||
project alone. Be mindful of the fact that the essential
|
||||
ansible-core features have a broad impact.
|
||||
|
||||
If unsure, consider filing a [new proposal] instead outlining your
|
||||
use-cases, the research and implementation considerations. Then,
|
||||
start a discussion in the [Ansible forum][forum].
|
||||
|
||||
|
||||
<details>
|
||||
<summary>
|
||||
❗ Every change breaks someone's workflow.
|
||||
</summary>
|
||||
|
||||
|
||||
[
|
||||
](https://xkcd.com/1172/)
|
||||
</details>
|
||||
|
||||
|
||||
⚠
|
||||
Verify first that your idea is not [already requested on
|
||||
GitHub][issue search].
|
||||
|
||||
Also test if the devel branch does not already implement this.
|
||||
|
||||
|
||||
**Tip:** If you are seeking community support, please see
|
||||
[Communicating with the Ansible community][communication] to
|
||||
get in touch and ask questions.
|
||||
|
||||
|
||||
|
||||
[contribute to collections]:
|
||||
https://docs.ansible.com/ansible-core/devel/community/contributing_maintained_collections.html?utm_medium=github&utm_source=issue_form--feature_request.yml
|
||||
|
||||
[communication]:
|
||||
https://docs.ansible.com/ansible/devel/community/communication.html
|
||||
|
||||
[issue search]: ../search?q=is%3Aissue&type=issues
|
||||
|
||||
[forum help]:
|
||||
https://forum.ansible.com/c/help/6
|
||||
|
||||
[new proposal]: ../../proposals/issues/new
|
||||
|
||||
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: Summary
|
||||
description: >
|
||||
Describe the new feature/improvement you would like briefly below.
|
||||
|
||||
|
||||
What's the problem this feature will solve?
|
||||
|
||||
What are you trying to do, that you are unable to achieve
|
||||
with ansible-core as it currently stands?
|
||||
|
||||
|
||||
* Provide examples of real-world use cases that this would enable
|
||||
and how it solves the problem you described.
|
||||
|
||||
* How do you solve this now?
|
||||
|
||||
* Have you tried to work around the problem using other tools?
|
||||
|
||||
* Could there be a different approach to solving this issue?
|
||||
|
||||
|
||||
*Know **exactly** what you want?* Consider filing a [new proposal]
|
||||
instead outlining your research and implementation considerations.
|
||||
|
||||
|
||||
[new proposal]: ../../proposals/issues/new
|
||||
placeholder: >-
|
||||
I am trying to do X with ansible-core from the devel branch on GitHub and
|
||||
I think that implementing a feature Y would be very helpful for me and
|
||||
every other user of ansible-core because of Z.
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: dropdown
|
||||
attributes:
|
||||
label: Issue Type
|
||||
description: This is a marker for our automatic bot. Do not change it.
|
||||
options:
|
||||
- Feature Idea
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: input
|
||||
attributes:
|
||||
label: Component Name
|
||||
description: >
|
||||
Write the short name of the module, plugin, task or feature below,
|
||||
*use your best guess if unsure*.
|
||||
|
||||
|
||||
Be aware that a lot of content that used to reside in this repository
|
||||
previously, is now hosted under [individual collection
|
||||
projects][collections org].
|
||||
If this is the case, please make sure to file an issue under the
|
||||
appropriate project there instead.
|
||||
|
||||
|
||||
[collections org]: /ansible-collections
|
||||
placeholder: dnf, apt, pip, user etc.
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: Additional Information
|
||||
description: |
|
||||
Describe how the feature would be used, why it is needed and what it would solve.
|
||||
|
||||
**HINT:** You can paste https://gist.github.com links for larger files.
|
||||
value: |
|
||||
<!--- Paste example playbooks or commands between quotes below -->
|
||||
```yaml (paste below)
|
||||
|
||||
```
|
||||
placeholder: >-
|
||||
I asked on https://stackoverflow.com/.... and the community
|
||||
advised me to do X, Y and Z.
|
||||
validations:
|
||||
required: true
|
||||
|
||||
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: >
|
||||
*One last thing...*
|
||||
|
||||
|
||||
*Please, complete **all** sections as described, this form
|
||||
is [processed automatically by a robot][ansibot help].*
|
||||
|
||||
|
||||
Thank you for your collaboration!
|
||||
|
||||
|
||||
[ansibot help]:
|
||||
/ansible/ansibotmini#ansibotmini
|
||||
|
||||
|
||||
- type: checkboxes
|
||||
attributes:
|
||||
label: Code of Conduct
|
||||
description: |
|
||||
Read the [Ansible Code of Conduct][CoC] first.
|
||||
|
||||
[CoC]: https://docs.ansible.com/ansible/devel/community/code_of_conduct.html?utm_medium=github&utm_source=issue_form--feature_request.yml
|
||||
options:
|
||||
- label: I agree to follow the Ansible Code of Conduct
|
||||
required: true
|
||||
...
|
||||
10
.github/ISSUE_TEMPLATE/internal_issue.md
vendored
10
.github/ISSUE_TEMPLATE/internal_issue.md
vendored
@ -1,10 +0,0 @@
|
||||
---
|
||||
name: Internal Issue
|
||||
about: Free-form issue creation for core maintainer use only.
|
||||
title: ''
|
||||
labels: [core-internal]
|
||||
assignees: ''
|
||||
---
|
||||
|
||||
|
||||
@ansibot bot_skip
|
||||
42
.github/ISSUE_TEMPLATE/pre_release.yml
vendored
42
.github/ISSUE_TEMPLATE/pre_release.yml
vendored
@ -1,42 +0,0 @@
|
||||
name: Pre-Release Bug Report
|
||||
description: File a bug report against a pre-release version
|
||||
labels:
|
||||
- bug
|
||||
- pre_release
|
||||
assignees:
|
||||
- nitzmahone
|
||||
- mattclay
|
||||
body:
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||
## Bug Report
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: Ansible Version
|
||||
description: Paste the full output from `ansible --version` below.
|
||||
render: console
|
||||
placeholder: $ ansible --version
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: Summary
|
||||
description: Describe the issue with any relevant steps to reproduce.
|
||||
validations:
|
||||
required: true
|
||||
- type: dropdown
|
||||
attributes:
|
||||
label: <!-- Bot instructions (ignore this) -->
|
||||
options:
|
||||
- |
|
||||
<!--
|
||||
### Component Name
|
||||
bin/ansible
|
||||
### Issue Type
|
||||
Bug Report
|
||||
### Configuration
|
||||
### OS / Environment
|
||||
-->
|
||||
validations:
|
||||
required: true
|
||||
1
.github/PULL_REQUEST_TEMPLATE.md
vendored
1
.github/PULL_REQUEST_TEMPLATE.md
vendored
@ -1 +0,0 @@
|
||||
PULL_REQUEST_TEMPLATE/Unclear purpose or motivation.md
|
||||
37
.github/PULL_REQUEST_TEMPLATE.md
vendored
Normal file
37
.github/PULL_REQUEST_TEMPLATE.md
vendored
Normal file
@ -0,0 +1,37 @@
|
||||
##### SUMMARY
|
||||
<!--- Describe the change, including rationale and design decisions -->
|
||||
|
||||
<!---
|
||||
If you are fixing an existing issue, please include "Fixes #nnn" in your
|
||||
commit message and your description; but you should still explain what
|
||||
the change does.
|
||||
-->
|
||||
|
||||
##### ISSUE TYPE
|
||||
<!--- Pick one below and delete the rest: -->
|
||||
- Feature Pull Request
|
||||
- New Module Pull Request
|
||||
- Bugfix Pull Request
|
||||
- Docs Pull Request
|
||||
|
||||
##### COMPONENT NAME
|
||||
<!--- Name of the module/plugin/module/task -->
|
||||
|
||||
##### ANSIBLE VERSION
|
||||
<!--- Paste verbatim output from "ansible --version" between quotes below -->
|
||||
```
|
||||
|
||||
```
|
||||
|
||||
|
||||
##### ADDITIONAL INFORMATION
|
||||
<!---
|
||||
Include additional information to help people understand the change here.
|
||||
For bugs that don't have a linked bug report, a step-by-step reproduction
|
||||
of the problem is helpful.
|
||||
-->
|
||||
|
||||
<!--- Paste verbatim command output below, e.g. before and after your change -->
|
||||
```
|
||||
|
||||
```
|
||||
9
.github/PULL_REQUEST_TEMPLATE/Bug fix.md
vendored
9
.github/PULL_REQUEST_TEMPLATE/Bug fix.md
vendored
@ -1,9 +0,0 @@
|
||||
##### SUMMARY
|
||||
|
||||
<!--- Describe the change below, including rationale and design decisions -->
|
||||
|
||||
<!--- Add "Fixes #1234" or steps to reproduce the problem if there is no corresponding issue -->
|
||||
|
||||
##### ISSUE TYPE
|
||||
|
||||
- Bugfix Pull Request
|
||||
@ -1,9 +0,0 @@
|
||||
##### SUMMARY
|
||||
|
||||
<!--- Describe the change below, including rationale -->
|
||||
|
||||
<!--- Add "Fixes #1234" if there is a corresponding issue -->
|
||||
|
||||
##### ISSUE TYPE
|
||||
|
||||
- Docs Pull Request
|
||||
9
.github/PULL_REQUEST_TEMPLATE/New feature.md
vendored
9
.github/PULL_REQUEST_TEMPLATE/New feature.md
vendored
@ -1,9 +0,0 @@
|
||||
##### SUMMARY
|
||||
|
||||
<!--- Describe the change below, including rationale and design decisions -->
|
||||
|
||||
<!--- Add "Fixes #1234" if there is a corresponding issue -->
|
||||
|
||||
##### ISSUE TYPE
|
||||
|
||||
- Feature Pull Request
|
||||
@ -1 +0,0 @@
|
||||
Unclear purpose or motivation.md
|
||||
9
.github/PULL_REQUEST_TEMPLATE/Tests.md
vendored
9
.github/PULL_REQUEST_TEMPLATE/Tests.md
vendored
@ -1,9 +0,0 @@
|
||||
##### SUMMARY
|
||||
|
||||
<!--- Describe the change below, including rationale and design decisions -->
|
||||
|
||||
<!--- Add "Fixes #1234" if there is a corresponding issue -->
|
||||
|
||||
##### ISSUE TYPE
|
||||
|
||||
- Test Pull Request
|
||||
@ -1,14 +0,0 @@
|
||||
##### SUMMARY
|
||||
|
||||
<!--- Describe the change below, including rationale and design decisions -->
|
||||
|
||||
<!--- Add "Fixes #1234" or steps to reproduce the problem if there is no corresponding issue -->
|
||||
|
||||
##### ISSUE TYPE
|
||||
|
||||
<!--- Pick one below and delete the rest -->
|
||||
|
||||
- Bugfix Pull Request
|
||||
- Docs Pull Request
|
||||
- Feature Pull Request
|
||||
- Test Pull Request
|
||||
21
.github/RELEASE_NAMES.txt
vendored
21
.github/RELEASE_NAMES.txt
vendored
@ -1,21 +0,0 @@
|
||||
2.20.0 TBD
|
||||
2.19.0 What Is and What Should Never Be
|
||||
2.18.0 Fool in the Rain
|
||||
2.17.0 Gallows Pole
|
||||
2.16.0 All My Love
|
||||
2.15.0 Ten Years Gone
|
||||
2.14.0 C'mon Everybody
|
||||
2.13.0 Nobody's Fault but Mine
|
||||
2.12.0 Dazed and Confused
|
||||
2.11.0 Hey Hey, What Can I Do
|
||||
2.10.0 When the Levee Breaks
|
||||
2.9.0 Immigrant Song
|
||||
2.8.0 How Many More Times
|
||||
2.7.0 In the Light
|
||||
2.6.0 Heartbreaker
|
||||
2.5.0 Kashmir
|
||||
2.4.0 Dancing Days
|
||||
2.3.0 Ramble On
|
||||
2.2.0 The Battle of Evermore
|
||||
2.1.0 The Song Remains the Same
|
||||
2.0.0 Over the Hills and Far Away
|
||||
15
.github/SECURITY.md
vendored
15
.github/SECURITY.md
vendored
@ -1,15 +0,0 @@
|
||||
# Security Policy
|
||||
|
||||
## Supported Versions
|
||||
|
||||
Ansible applies security fixes according to the 3-versions-back support
|
||||
policy. Please find more information in [our docs](
|
||||
https://docs.ansible.com/ansible/devel/reference_appendices/release_and_maintenance.html#release-status
|
||||
).
|
||||
|
||||
## Reporting a Vulnerability
|
||||
|
||||
We encourage responsible disclosure practices for security
|
||||
vulnerabilities. Please read our [policies for reporting bugs](
|
||||
https://docs.ansible.com/ansible/devel/community/reporting_bugs_and_features.html#reporting-a-bug
|
||||
) if you want to report a security issue that might affect Ansible.
|
||||
93
.gitignore
vendored
93
.gitignore
vendored
@ -17,8 +17,6 @@ rpm-build
|
||||
.idea
|
||||
#IntelliJ IDEA stuff..
|
||||
*.iml
|
||||
#VSCode stuff..
|
||||
.vscode/
|
||||
# Mac OS X stuff...
|
||||
.DS_Store
|
||||
# manpage build stuff...
|
||||
@ -29,90 +27,70 @@ docs/man/man3/*
|
||||
*.sublime-project
|
||||
*.sublime-workspace
|
||||
# docsite stuff...
|
||||
docs/docsite/_build
|
||||
docs/api/_build/
|
||||
docs/api/rst/
|
||||
docs/docsite/*.html
|
||||
docs/docsite/htmlout
|
||||
docs/docsite/rst/conf.py
|
||||
docs/docsite/rst/index.rst
|
||||
docs/docsite/rst/cli/ansible-*.rst
|
||||
docs/docsite/rst/cli/ansible.rst
|
||||
docs/docsite/rst/dev_guide/collections_galaxy_meta.rst
|
||||
docs/docsite/rst/dev_guide/testing/sanity/index.rst.new
|
||||
docs/docsite/rst/dev_guide/index.rst
|
||||
docs/docsite/rst/modules/*.rst
|
||||
docs/docsite/rst/collections/*.rst
|
||||
!docs/docsite/rst/collections/all_plugins.rst
|
||||
docs/docsite/rst/collections/*/*.rst
|
||||
docs/docsite/rst/playbooks_directives.rst
|
||||
docs/docsite/rst/plugins_by_category.rst
|
||||
docs/docsite/rst/plugins/*/*.rst
|
||||
docs/docsite/rst/reference_appendices/config.rst
|
||||
docs/docsite/rst/reference_appendices/playbooks_keywords.rst
|
||||
docs/docsite/rst_warnings
|
||||
docs/docsite/searchindex.js
|
||||
docs/docsite/_build
|
||||
docs/docsite/_static/*.gif
|
||||
docs/docsite/_static/*.png
|
||||
docs/docsite/_static/websupport.js
|
||||
docs/docsite/htmlout
|
||||
docs/docsite/searchindex.js
|
||||
docs/docsite/rst_warnings
|
||||
docs/docsite/rst/*_module.rst
|
||||
docs/docsite/rst/ansible.rst
|
||||
docs/docsite/rst/ansible-*.rst
|
||||
docs/docsite/rst/community_maintained.rst
|
||||
docs/docsite/rst/config.rst
|
||||
docs/docsite/rst/core_maintained.rst
|
||||
docs/docsite/rst/list_of_*.rst
|
||||
docs/docsite/rst/modules_by_category.rst
|
||||
docs/docsite/rst/network_maintained.rst
|
||||
docs/docsite/rst/plugins_by_category.rst
|
||||
docs/docsite/rst/partner_maintained.rst
|
||||
docs/docsite/rst/playbook_keywords.rst
|
||||
docs/docsite/rst/playbooks_directives.rst
|
||||
docs/docsite/rst/plugins/*/*.rst
|
||||
# deb building stuff...
|
||||
/debian/
|
||||
deb-build
|
||||
# Vim swap files
|
||||
*.swp
|
||||
*.swo
|
||||
[._]*.un~
|
||||
credentials.yml
|
||||
# test output
|
||||
*.retry
|
||||
*.out
|
||||
.pytest_cache/
|
||||
.tox
|
||||
.cache
|
||||
.pytest_cache
|
||||
results.xml
|
||||
coverage.xml
|
||||
/test/units/cover-html
|
||||
/test/integration/inventory
|
||||
/test/integration/targets/*/backup/
|
||||
/test/cache/*
|
||||
# Development
|
||||
/test/develop
|
||||
# Environments
|
||||
.env
|
||||
.venv
|
||||
env/
|
||||
venv/
|
||||
ENV/
|
||||
env.bak/
|
||||
venv.bak/
|
||||
venv
|
||||
env
|
||||
Vagrantfile
|
||||
.vagrant
|
||||
# Backwards compatibility with `stable-2.9` and earlier branches.
|
||||
# Also used in the `devel` branch during early Ansible 2.10 development.
|
||||
/lib/ansible.egg-info/
|
||||
# First used in the `devel` branch during Ansible 2.10 development.
|
||||
/lib/ansible_base.egg-info/
|
||||
# First used in the `devel` branch during Ansible 2.11 development.
|
||||
/lib/ansible_core.egg-info/
|
||||
# First used in the `devel` branch during Ansible 2.18 development.
|
||||
/ansible_core.egg-info/
|
||||
# vendored lib dir
|
||||
lib/ansible/_vendor/*
|
||||
!lib/ansible/_vendor/__init__.py
|
||||
# PowerShell signed hashlist
|
||||
lib/ansible/config/powershell_signatures.psd1
|
||||
*.authenticode
|
||||
# test stuff
|
||||
ansible.egg-info/
|
||||
/shippable/
|
||||
/test/integration/cloud-config-*.*
|
||||
!/test/integration/cloud-config-*.*.template
|
||||
.python-version
|
||||
# Release directory
|
||||
packaging/release/ansible_release
|
||||
/.cache/
|
||||
/test/results/
|
||||
/test/integration/cloud-config-aws.yml
|
||||
/test/results/coverage/*=coverage.*
|
||||
/test/results/coverage/coverage*
|
||||
/test/results/reports/coverage*.xml
|
||||
/test/results/reports/coverage*/
|
||||
/test/results/bot/*.json
|
||||
/test/results/junit/*.xml
|
||||
/test/results/logs/*.log
|
||||
/test/results/data/*.json
|
||||
/test/integration/inventory.remote
|
||||
/test/integration/inventory.networking
|
||||
/test/integration/inventory.winrm
|
||||
/test/integration/cloud-config-aws.yml
|
||||
/test/integration/cloud-config-cs.ini
|
||||
# python 'rope' stuff
|
||||
.ropeproject
|
||||
# local 'ack' config files
|
||||
@ -124,6 +102,3 @@ htmlcov/
|
||||
# ansible-test coverage results
|
||||
test/units/.coverage.*
|
||||
/test/integration/cloud-config-azure.yml
|
||||
/SYMLINK_CACHE.json
|
||||
changelogs/.plugin-cache.yaml
|
||||
.ansible-test-timeout.json
|
||||
|
||||
2
.mailmap
2
.mailmap
@ -1,5 +1,5 @@
|
||||
Michael DeHaan <michael.dehaan@gmail.com> <michael@ansibleworks.com>
|
||||
Michael DeHaan <michael.dehaan@gmail.com> Michael DeHaan <michael@ansibleworks.com>
|
||||
Michael DeHaan <michael.dehaan@gmail.com> Michael DeHaan <Michael DeHaan michael@ansibleworks.com>
|
||||
Michael DeHaan <michael.dehaan@gmail.com> <michael@ansible.com>
|
||||
<bcoca@ansible.com> <brian.coca+git@gmail.com>
|
||||
<bcoca@ansible.com> <briancoca+ansible@gmail.com>
|
||||
|
||||
3935
CHANGELOG.md
Normal file
3935
CHANGELOG.md
Normal file
File diff suppressed because it is too large
Load Diff
316
CODING_GUIDELINES.md
Normal file
316
CODING_GUIDELINES.md
Normal file
@ -0,0 +1,316 @@
|
||||
Coding Guidelines
|
||||
=================
|
||||
|
||||
Hi! Thanks for interest in contributing to Ansible.
|
||||
|
||||
Here are some guidelines for contributing code. The purpose of this document are to establish what we're looking for in code contributions, and to make sure
|
||||
new contributions know some of the conventions that we've been using.
|
||||
|
||||
We don't think much of this should be too strange to readers familiar with contributing to Python projects, though it helps if we all get on the same page.
|
||||
|
||||
Language
|
||||
========
|
||||
|
||||
* While not all components of Ansible must be in Python, core contributions to the Ansible repo must be written in Python. This is to maximize the ability of everyone to contribute.
|
||||
* If you want to write non-Python ansible modules or inventory scripts, that's fine, but they are not going to get merged in most likely. Sorry!!
|
||||
|
||||
PEP 8 and basic style checks
|
||||
===========================
|
||||
|
||||
* [PEP 8](https://www.python.org/dev/peps/pep-0008/) is a great Python style guide, which you should read.
|
||||
* PEP 8 must not be strictly followed in all aspects, but most of it is good advice
|
||||
* In particular, we don't really care about line lengths. Buy a bigger monitor!
|
||||
* To run checks for things we care about, use [ansible-test](http://docs.ansible.com/ansible/dev_guide/testing_pep8.html#running-locally).
|
||||
* Similarly, additional checks can be made with "make pyflakes"
|
||||
* There is no need to submit code changes for PEP 8 and pyflakes fixes, as these break attribution history. Project leadership will make these periodically.
|
||||
* Do not submit pull requests that simply adjust whitespace in the code
|
||||
|
||||
Testing
|
||||
=======
|
||||
|
||||
* Much of ansible's testing needs are in integration, not unit tests. Add module tests there.
|
||||
* That being said, there are unit tests too!
|
||||
* Code written must absolutely pass tests (i.e. "make tests")
|
||||
* You should anticipate any error paths in your code and test down those error paths.
|
||||
* Additions to tests for core code is welcome, but not always possible. Be sure things are at least well tested manually in that case.
|
||||
|
||||
Whitespace
|
||||
==========
|
||||
|
||||
* Four space indent is strictly required
|
||||
* Include meaningful whitespace between lines of code
|
||||
|
||||
Shebang Lines
|
||||
=============
|
||||
|
||||
* /usr/bin/scripts should start with '/usr/bin/env python'
|
||||
* module code should still use '/usr/bin/python' as this is replaced automatically by 'ansible_python_interpreter', see the FAQ in the docs for more info.
|
||||
|
||||
Comments
|
||||
========
|
||||
|
||||
* Readability is one of the most important goals for this project
|
||||
* Comment any non-trivial code where someone might not know why you are doing something in a particular way
|
||||
* Though if something should be commented, that's often a sign someone should write a function
|
||||
* All new functions must have a basic docstring comment
|
||||
* Commenting above a line is preferable to commenting at the end of a line
|
||||
|
||||
Classes
|
||||
=======
|
||||
|
||||
* With the exception of module code (where inline is better), it is desirable to see classes in their own files.
|
||||
* Classes should generally not cause side effects as soon as they are instantiated, move meaningful behavior to methods rather than constructors.
|
||||
|
||||
Functions and Methods
|
||||
=====================
|
||||
|
||||
* In general, functions should not be 'too long' and should describe a meaningful amount of work
|
||||
* When code gets too nested, that's usually the sign the loop body could benefit from being a function
|
||||
* Parts of our existing code are not the best examples of this at times.
|
||||
* Functions should have names that describe what they do, along with docstrings
|
||||
* Functions should be named with_underscores
|
||||
* "Don't repeat yourself" is generally a good philosophy
|
||||
|
||||
Variables
|
||||
=========
|
||||
|
||||
* Use descriptive variable names instead of variables like 'x', unless x is a obvious loop index
|
||||
* Ansible python code uses identifiers like 'ClassesLikeThis and variables_like_this
|
||||
* Module parameters should also use_underscores and not runtogether
|
||||
|
||||
Module Security
|
||||
===============
|
||||
|
||||
* Modules must take steps to avoid passing user input from the shell and always check return codes
|
||||
* always use module.run_command instead of subprocess or Popen or os.system -- this is mandatory
|
||||
* if you use need the shell you must pass use_unsafe_shell=True to module.run_command
|
||||
* if you do not need the shell, avoid using the shell
|
||||
* any variables that can come from the user input with use_unsafe_shell=True must be wrapped by pipes.quote(x)
|
||||
* downloads of https:// resource urls must import module_utils.urls and use the fetch_url method
|
||||
|
||||
Misc Preferences
|
||||
================
|
||||
|
||||
Use the dict constructor where possible when allocating dictionaries:
|
||||
|
||||
# not this:
|
||||
foo = {
|
||||
'a' : 12,
|
||||
'b' : 34
|
||||
}
|
||||
|
||||
# this:
|
||||
foo = dict(
|
||||
a=12,
|
||||
b=34,
|
||||
)
|
||||
|
||||
Do not line up variables
|
||||
|
||||
# not this
|
||||
a = 12
|
||||
foosball = 34
|
||||
xyz = 'dog'
|
||||
|
||||
# this
|
||||
a = 12
|
||||
foosball = 34
|
||||
xyz = 'dog'
|
||||
|
||||
Don't use line continuations:
|
||||
|
||||
# no
|
||||
if (this_is_a_very_long_line and foo and \
|
||||
i_am_going_to_continue_it):
|
||||
bar()
|
||||
|
||||
# better:
|
||||
if (this_is_a_very_long_line and foo and i_am_going_to_continue_it):
|
||||
bar()
|
||||
|
||||
Spacing:
|
||||
|
||||
# no
|
||||
x = [1,2,3]
|
||||
|
||||
# no
|
||||
x = [ 1, 2, 3 ]
|
||||
|
||||
# yes
|
||||
x = [1, 2, 3]
|
||||
|
||||
Spacing continued:
|
||||
|
||||
# no
|
||||
x=foo(12)
|
||||
|
||||
# no
|
||||
x = foo( 12 )
|
||||
|
||||
# yes
|
||||
x = foo(12)
|
||||
|
||||
Licenses
|
||||
========
|
||||
|
||||
Every file should have a license header, including the copyright of the original author. Major additions to the module are allowed
|
||||
to add an additional copyright line, and this is especially true of rewrites, but original authorship copyright messages should be preserved.
|
||||
|
||||
All contributions to the core repo should preserve original licenses and new contributions must include the GPLv3 header.
|
||||
|
||||
Module Documentation
|
||||
====================
|
||||
|
||||
All module pull requests must include a DOCUMENTATION docstring (YAML format,
|
||||
see other modules for examples) as well as an EXAMPLES docstring, which is free form.
|
||||
|
||||
When adding new modules, any new parameter must have a "version_added" attribute.
|
||||
When submitting a new module, the module should have a "version_added" attribute in the
|
||||
pull request as well, set to the current development version.
|
||||
|
||||
Be sure to check grammar and spelling.
|
||||
|
||||
It's frequently the case that modules get submitted with YAML that isn't valid,
|
||||
so you can run "make webdocs" from the checkout to preview your module's documentation.
|
||||
If it fails to build, take a look at your DOCUMENTATION string
|
||||
or you might have a Python syntax error in there too.
|
||||
|
||||
Python Imports
|
||||
==============
|
||||
|
||||
To make it clear what a module is importing, imports should not be sprinkled throughout the code.
|
||||
|
||||
Python Imports should happen at the top of the file, exempting code from module_utils.
|
||||
|
||||
When a conditional runtime import is required, do so something like this instead:
|
||||
|
||||
HAS_FOO = False
|
||||
try:
|
||||
import foo
|
||||
HAS_FOO = True
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
...
|
||||
|
||||
if not HAS_FOO:
|
||||
raise Exception("the foo library is required")
|
||||
|
||||
This makes it clear what optional dependencies are but allows this to be deferred until runtime. In the case of module code, the raising of the Exception will be replaced
|
||||
with a "module.exit_json" call.
|
||||
|
||||
Exceptions
|
||||
==========
|
||||
|
||||
In the main body of the code, use typed exceptions where possible:
|
||||
|
||||
# not this
|
||||
raise Exception("panic!")
|
||||
|
||||
# this
|
||||
from ansible import errors
|
||||
...
|
||||
raise errors.AnsibleError("panic!")
|
||||
|
||||
Similarly, exception checking should be fine grained:
|
||||
|
||||
# not this
|
||||
try:
|
||||
foo()
|
||||
except:
|
||||
bar()
|
||||
|
||||
# but this
|
||||
try:
|
||||
foo()
|
||||
except SomeTypedException:
|
||||
bar()
|
||||
|
||||
List Comprehensions
|
||||
===================
|
||||
|
||||
In general list comprehensions are always preferred to map() and filter() calls.
|
||||
|
||||
However, they can be abused. Optimize for readability, and avoid nesting them too deeply.
|
||||
|
||||
Regexes
|
||||
=======
|
||||
|
||||
There is a time and place for them, but here's an illustrative joke.
|
||||
|
||||
"A developer had a problem, and used a regular expression to solve it. Now the developer had two problems".
|
||||
|
||||
Often regexes are difficult to maintain, and a trusty call to other string operations can be a great solution, faster,
|
||||
and more readable.
|
||||
|
||||
File Conventions
|
||||
================
|
||||
|
||||
If a piece of code looks for a named YAML file in a directory, it should assume it can take no extension, or an extension of '.yml' or '.yaml'.
|
||||
This should be true against all code that loads files.
|
||||
|
||||
Any code that uses directories should consider the possibility that the directory may be symlink.
|
||||
|
||||
New Ansible language parameters
|
||||
===============================
|
||||
|
||||
If adding a new parameter, like 'can_fizzbuzz: True/False' be sure the value of the parameter is templated somewhere in the Runner code, as if anything can be parameterized in Ansible,
|
||||
there is a user that will try to parameterize it.
|
||||
|
||||
String Find
|
||||
===========
|
||||
|
||||
Use 'in':
|
||||
|
||||
# not this:
|
||||
if x.find('foo') != -1:
|
||||
|
||||
# this:
|
||||
if 'foo' in x:
|
||||
|
||||
String checks
|
||||
=============
|
||||
|
||||
To test if something is a string, consider that it may be unicode.
|
||||
|
||||
# no
|
||||
if type(x) == str:
|
||||
|
||||
# yes
|
||||
from ansible.module_utils.six import string_types
|
||||
if isinstance(x, string_types):
|
||||
|
||||
Cleverness
|
||||
==========
|
||||
|
||||
Ansible's code is intended to be read by as many people as possible, so we don't particularly encourage clever or heavily idiomatic code.
|
||||
|
||||
In particular, metaclasses are probably not appropriate, however entertaining they may be to add.
|
||||
|
||||
Git Practices
|
||||
=============
|
||||
|
||||
Pull requests cannot be accepted that contain merge commits.
|
||||
|
||||
Always do "git pull --rebase" and "git rebase" vs "git pull" or "git merge".
|
||||
|
||||
Always create a new branch for each pull request to avoid intertwingling different features or fixes on the same branch.
|
||||
|
||||
|
||||
Python Version Compliance
|
||||
=========================
|
||||
|
||||
All code in Ansible core must support a minimum version of Python 2.6.
|
||||
|
||||
Module code must support a minimum of Python 2.4, with occasional exception for modules that require code that themselves require 2.6 and later.
|
||||
|
||||
A quick reminder is that list comprehensions in Python 2.4 are not as fully fleshed out, there are no 'dict' comprehensions, and there is no 'with' statement.
|
||||
But otherwise it's pretty much all the same.
|
||||
|
||||
The End
|
||||
=======
|
||||
|
||||
This was not meant to be a scary document, so we hope it wasn't, but we also hope this helps you write code that is easier to maintain by others in the future.
|
||||
If you have questions about this document, please ask on the ansible-devel mailing list.
|
||||
|
||||
Thank you!
|
||||
29
CONTRIBUTING.md
Normal file
29
CONTRIBUTING.md
Normal file
@ -0,0 +1,29 @@
|
||||
# WELCOME TO ANSIBLE GITHUB
|
||||
|
||||
Hi! Nice to see you here!
|
||||
|
||||
|
||||
## QUESTIONS ?
|
||||
|
||||
Please see the [community page](http://docs.ansible.com/community.html) for information on how to ask questions on the [mailing lists](http://docs.ansible.com/community.html#mailing-list-information) and IRC.
|
||||
|
||||
The GitHub issue tracker is not the best place for questions for various reasons, but both IRC and the mailing list are very helpful places for those things, as the community page explains best.
|
||||
|
||||
|
||||
## CONTRIBUTING ?
|
||||
|
||||
Please see the [community page](http://docs.ansible.com/community.html) for information regarding the contribution process. Important license agreement information is also included on that page.
|
||||
|
||||
|
||||
## BUG TO REPORT ?
|
||||
|
||||
First and foremost, also check the [community page](http://docs.ansible.com/community.html).
|
||||
|
||||
You can report bugs or make enhancement requests at the [Ansible GitHub issue page](http://github.com/ansible/ansible/issues/new) by filling out the issue template that will be presented.
|
||||
|
||||
Also please make sure you are testing on the latest released version of Ansible or the development branch. You can find the latest releases and development branch at:
|
||||
|
||||
- https://github.com/ansible/ansible/releases
|
||||
- https://github.com/ansible/ansible/archive/devel.tar.gz
|
||||
|
||||
Thanks!
|
||||
9
COPYING
9
COPYING
@ -1,7 +1,7 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
@ -645,7 +645,7 @@ the "copyright" line and a pointer to where the full notice is found.
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
@ -664,11 +664,12 @@ might be different; for a GUI interface, you would use an "about box".
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<https://www.gnu.org/licenses/>.
|
||||
<http://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
||||
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
|
||||
|
||||
|
||||
29
MANIFEST.in
29
MANIFEST.in
@ -1,10 +1,21 @@
|
||||
include COPYING
|
||||
include changelogs/CHANGELOG*.rst
|
||||
include changelogs/changelog.yaml
|
||||
include licenses/*.txt
|
||||
prune ticket_stubs
|
||||
prune hacking
|
||||
include README.md COPYING
|
||||
include SYMLINK_CACHE.json
|
||||
include requirements.txt
|
||||
recursive-include packaging *.py *.j2
|
||||
recursive-include test/integration *
|
||||
recursive-include test/sanity *.in *.json *.py *.txt *.ini
|
||||
recursive-include test/support *.py *.ps1 *.psm1 *.cs *.md
|
||||
recursive-include test/units *
|
||||
include .coveragerc
|
||||
include .yamllint
|
||||
include examples/hosts
|
||||
include examples/ansible.cfg
|
||||
recursive-include lib/ansible/module_utils/powershell *
|
||||
recursive-include lib/ansible/modules *
|
||||
recursive-include lib/ansible/galaxy/data *
|
||||
recursive-include docs *
|
||||
recursive-include packaging *
|
||||
recursive-include test *
|
||||
include Makefile
|
||||
include VERSION
|
||||
include MANIFEST.in
|
||||
include CHANGELOG.md
|
||||
include contrib/README.md
|
||||
recursive-include contrib/inventory *
|
||||
|
||||
70
MODULE_GUIDELINES.md
Normal file
70
MODULE_GUIDELINES.md
Normal file
@ -0,0 +1,70 @@
|
||||
# Module Maintainer Guidelines
|
||||
|
||||
Thank you for being a maintainer of one Ansible's community modules! This guide provides module maintainers an overview of their responsibilities, resources for additional information, and links to helpful tools.
|
||||
|
||||
In addition to the information below, module maintainers should be familiar with:
|
||||
* General Ansible community development practices (http://docs.ansible.com/ansible/community.html)
|
||||
* Documentation on module development (http://docs.ansible.com/ansible/developing_modules.html)
|
||||
* Any namespace-specific module guidelines (identified as GUIDELINES.md in the appropriate file tree).
|
||||
|
||||
***
|
||||
|
||||
# Maintainer Responsibilities
|
||||
|
||||
When you contribute a new module to the [ansible/ansible](https://github.com/ansible/ansible) repository, you become the maintainer for that module once it has been merged. Maintainership empowers you with the authority to accept, reject, or request revisions to pull requests on your module -- but as they say, "with great power comes great responsibility."
|
||||
|
||||
Maintainers of Ansible modules are expected to provide feedback, responses, or actions on pull requests or issues to the module(s) they maintain in a reasonably timely manner.
|
||||
|
||||
It is also recommended that you occasionally revisit the [contribution guidelines](https://github.com/ansible/ansible/blob/devel/CONTRIBUTING.md), as they are continually refined. Occasionally, you may be requested to update your module to move it closer to the general accepted standard requirements. We hope for this to be infrequent, and will always be a request with a fair amount of lead time (ie: not by tomorrow!).
|
||||
|
||||
Finally, following the [ansible-devel](https://groups.google.com/forum/#!forum/ansible-devel) mailing list can be a great way to participate in the broader Ansible community, and a place where you can influence the overall direction, quality, and goals of Ansible and its modules. If you're not on this relatively low-volume list, please join us here: https://groups.google.com/forum/#!forum/ansible-devel
|
||||
|
||||
The Ansible community hopes that you will find that maintaining your module is as rewarding for you as having the module is for the wider community.
|
||||
|
||||
***
|
||||
|
||||
# Pull Requests, Issues, and Workflow
|
||||
|
||||
## Pull Requests
|
||||
|
||||
Module pull requests are located in the [main Ansible repository](https://github.com/ansible/ansible/pulls).
|
||||
|
||||
Because of the high volume of pull requests, notification of PRs to specific modules are routed by an automated bot to the appropriate maintainer for handling. It is recommended that you set an appropriate notification process to receive notifications which mention your GitHub ID.
|
||||
|
||||
## Issues
|
||||
|
||||
Issues for modules, including bug reports, documentation bug reports, and feature requests, are tracked in the [ansible repository](https://github.com/ansible/ansible/issues).
|
||||
|
||||
Issues for modules are routed to their maintainers via an automated process. This process is still being refined, and currently depends upon the issue creator to provide adequate details (specifically, providing the proper module name) in order to route it correctly. If you are a maintainer of a specific module, it is recommended that you periodically search module issues for issues which mention your module's name (or some variation on that name), as well as setting an appropriate notification process for receiving notification of mentions of your GitHub ID.
|
||||
|
||||
## PR Workflow
|
||||
|
||||
Automated routing of pull requests is handled by a tool called [Ansibullbot](https://github.com/ansible/ansibullbot). (You could say that he moooo-ves things around.)
|
||||
|
||||
Being moderately familiar with how the workflow behind the bot operates can be helpful to you, and -- should things go awry -- your feedback can be helpful to the folks that continually help Ansibullbot to evolve.
|
||||
|
||||
A detailed explanation of the PR workflow can be seen here: https://github.com/ansible/community/blob/master/PR-FLOW.md
|
||||
|
||||
***
|
||||
|
||||
# Maintainers list
|
||||
|
||||
The full list of maintainers for modules is located here: https://github.com/ansible/ansible/blob/devel/.github/BOTMETA.yml
|
||||
|
||||
## Changing Maintainership
|
||||
|
||||
Communities change over time, and no one maintains a module forever. If you'd like to propose an additional maintainer for your module, please submit a PR to the maintainers file with the Github username of the new maintainer.
|
||||
|
||||
If you'd like to step down as a maintainer, please submit a PR to the maintainers file removing your Github ID from the module in question. If that would leave the module with no maintainers, put "ansible" as the maintainer. This will indicate that the module is temporarily without a maintainer, and the Ansible community team will search for a new maintainer.
|
||||
|
||||
***
|
||||
|
||||
# Tools and other Resources
|
||||
|
||||
## Useful tools
|
||||
* https://ansible.sivel.net/pr/byfile.html -- a full list of all open Pull Requests, organized by file.
|
||||
|
||||
## Other Resources
|
||||
|
||||
* Ansibullbot: https://github.com/ansible/ansibullbot
|
||||
* Triage / pull request workflow and information, including definitions for Labels in GitHub: https://github.com/ansible/community/blob/master/PR-FLOW.md
|
||||
359
Makefile
Normal file
359
Makefile
Normal file
@ -0,0 +1,359 @@
|
||||
# WARN: gmake syntax
|
||||
########################################################
|
||||
# Makefile for Ansible
|
||||
#
|
||||
# useful targets:
|
||||
# make sdist ---------------- produce a tarball
|
||||
# make srpm ----------------- produce a SRPM
|
||||
# make rpm ----------------- produce RPMs
|
||||
# make deb-src -------------- produce a DEB source
|
||||
# make deb ------------------ produce a DEB
|
||||
# make docs ----------------- rebuild the manpages (results are checked in)
|
||||
# make tests ---------------- run the tests (see https://docs.ansible.com/ansible/dev_guide/testing_units.html for requirements)
|
||||
# make pyflakes, make pep8 -- source code checks
|
||||
|
||||
########################################################
|
||||
# variable section
|
||||
|
||||
NAME = ansible
|
||||
OS = $(shell uname -s)
|
||||
|
||||
# Manpages are currently built with asciidoc -- would like to move to markdown
|
||||
# This doesn't evaluate until it's called. The -D argument is the
|
||||
# directory of the target file ($@), kinda like `dirname`.
|
||||
|
||||
MANPAGES ?= $(patsubst %.asciidoc.in,%,$(wildcard ./docs/man/man1/ansible*.1.asciidoc.in))
|
||||
ifneq ($(shell which a2x 2>/dev/null),)
|
||||
ASCII2MAN = a2x -L -D $(dir $@) -d manpage -f manpage $<
|
||||
ASCII2HTMLMAN = a2x -L -D docs/html/man/ -d manpage -f xhtml
|
||||
else
|
||||
ASCII2MAN = @echo "ERROR: AsciiDoc 'a2x' command is not installed but is required to build $(MANPAGES)" && exit 1
|
||||
endif
|
||||
GENERATE_CLI = docs/bin/generate_man.py
|
||||
|
||||
PYTHON=python
|
||||
SITELIB = $(shell $(PYTHON) -c "from distutils.sysconfig import get_python_lib; print get_python_lib()")
|
||||
|
||||
# VERSION file provides one place to update the software version
|
||||
VERSION := $(shell cat VERSION | cut -f1 -d' ')
|
||||
RELEASE := $(shell cat VERSION | cut -f2 -d' ')
|
||||
|
||||
# Get the branch information from git
|
||||
ifneq ($(shell which git),)
|
||||
GIT_DATE := $(shell git log -n 1 --format="%ai")
|
||||
GIT_HASH := $(shell git log -n 1 --format="%h")
|
||||
GIT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD | sed 's/[-_.\/]//g')
|
||||
GITINFO = .$(GIT_HASH).$(GIT_BRANCH)
|
||||
else
|
||||
GITINFO = ""
|
||||
endif
|
||||
|
||||
ifeq ($(shell echo $(OS) | egrep -c 'Darwin|FreeBSD|OpenBSD|DragonFly'),1)
|
||||
DATE := $(shell date -j -r $(shell git log -n 1 --format="%at") +%Y%m%d%H%M)
|
||||
CPUS ?= $(shell sysctl hw.ncpu|awk '{print $$2}')
|
||||
else
|
||||
DATE := $(shell date --utc --date="$(GIT_DATE)" +%Y%m%d%H%M)
|
||||
CPUS ?= $(shell nproc)
|
||||
endif
|
||||
|
||||
# DEB build parameters
|
||||
DEBUILD_BIN ?= debuild
|
||||
DEBUILD_OPTS = --source-option="-I"
|
||||
DPUT_BIN ?= dput
|
||||
DPUT_OPTS ?=
|
||||
DEB_DATE := $(shell LC_TIME=C date +"%a, %d %b %Y %T %z")
|
||||
ifeq ($(OFFICIAL),yes)
|
||||
DEB_RELEASE = $(RELEASE)ppa
|
||||
# Sign OFFICIAL builds using 'DEBSIGN_KEYID'
|
||||
# DEBSIGN_KEYID is required when signing
|
||||
ifneq ($(DEBSIGN_KEYID),)
|
||||
DEBUILD_OPTS += -k$(DEBSIGN_KEYID)
|
||||
endif
|
||||
else
|
||||
DEB_RELEASE = 100.git$(DATE)$(GITINFO)
|
||||
# Do not sign unofficial builds
|
||||
DEBUILD_OPTS += -uc -us
|
||||
DPUT_OPTS += -u
|
||||
endif
|
||||
DEBUILD = $(DEBUILD_BIN) $(DEBUILD_OPTS)
|
||||
DEB_PPA ?= ppa
|
||||
# Choose the desired Ubuntu release: lucid precise saucy trusty
|
||||
DEB_DIST ?= unstable
|
||||
|
||||
# pbuilder parameters
|
||||
PBUILDER_ARCH ?= amd64
|
||||
PBUILDER_CACHE_DIR = /var/cache/pbuilder
|
||||
PBUILDER_BIN ?= pbuilder
|
||||
PBUILDER_OPTS ?= --debootstrapopts --variant=buildd --architecture $(PBUILDER_ARCH) --debbuildopts -b
|
||||
|
||||
# RPM build parameters
|
||||
RPMSPECDIR= packaging/rpm
|
||||
RPMSPEC = $(RPMSPECDIR)/ansible.spec
|
||||
RPMDIST = $(shell rpm --eval '%{?dist}')
|
||||
RPMRELEASE = $(RELEASE)
|
||||
ifneq ($(OFFICIAL),yes)
|
||||
RPMRELEASE = 100.git$(DATE)$(GITINFO)
|
||||
endif
|
||||
ifeq ($(PUBLISH),nightly)
|
||||
# https://fedoraproject.org/wiki/Packaging:Versioning#Snapshots
|
||||
RPMRELEASE = $(RELEASE).$(DATE)git.$(GIT_HASH)
|
||||
endif
|
||||
RPMNVR = "$(NAME)-$(VERSION)-$(RPMRELEASE)$(RPMDIST)"
|
||||
|
||||
# MOCK build parameters
|
||||
MOCK_BIN ?= mock
|
||||
MOCK_CFG ?=
|
||||
|
||||
# ansible-test parameters
|
||||
ANSIBLE_TEST ?= test/runner/ansible-test
|
||||
TEST_FLAGS ?=
|
||||
|
||||
# ansible-test units parameters (make test / make test-py3)
|
||||
PYTHON_VERSION ?= $(shell python2 -c 'import sys; print("%s.%s" % sys.version_info[:2])')
|
||||
PYTHON3_VERSION ?= $(shell python3 -c 'import sys; print("%s.%s" % sys.version_info[:2])')
|
||||
|
||||
# ansible-test integration parameters (make integration)
|
||||
IMAGE ?= centos7
|
||||
TARGET ?=
|
||||
|
||||
########################################################
|
||||
|
||||
.PHONY: all
|
||||
all: clean python
|
||||
|
||||
.PHONY: tests
|
||||
tests:
|
||||
$(ANSIBLE_TEST) units -v --python $(PYTHON_VERSION) $(TEST_FLAGS)
|
||||
|
||||
.PHONY: tests-py3
|
||||
tests-py3:
|
||||
$(ANSIBLE_TEST) units -v --python $(PYTHON3_VERSION) $(TEST_FLAGS)
|
||||
|
||||
.PHONY: tests-nonet
|
||||
tests-nonet:
|
||||
$(ANSIBLE_TEST) units -v --python $(PYTHON_VERSION) $(TEST_FLAGS) --exclude test/units/modules/network/
|
||||
|
||||
.PHONY: integration
|
||||
integration:
|
||||
$(ANSIBLE_TEST) integration -v --docker $(IMAGE) $(TARGET) $(TEST_FLAGS)
|
||||
|
||||
.PHONY: authors
|
||||
authors:
|
||||
sh hacking/authors.sh
|
||||
|
||||
# Regenerate %.1.asciidoc if %.1.asciidoc.in has been modified more
|
||||
# recently than %.1.asciidoc.
|
||||
%.1.asciidoc: %.1.asciidoc.in
|
||||
sed "s/%VERSION%/$(VERSION)/" $< > $@
|
||||
|
||||
# Regenerate %.1 if %.1.asciidoc or VERSION has been modified more
|
||||
# recently than %.1. (Implicitly runs the %.1.asciidoc recipe)
|
||||
%.1: %.1.asciidoc VERSION
|
||||
$(ASCII2MAN)
|
||||
|
||||
.PHONY: loc
|
||||
loc:
|
||||
sloccount lib library bin
|
||||
|
||||
.PHONY: pep8
|
||||
pep8:
|
||||
$(ANSIBLE_TEST) sanity --test pep8 --python $(PYTHON_VERSION) $(TEST_FLAGS)
|
||||
|
||||
.PHONY: pyflakes
|
||||
pyflakes:
|
||||
pyflakes lib/ansible/*.py lib/ansible/*/*.py bin/*
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
@echo "Cleaning up distutils stuff"
|
||||
rm -rf build
|
||||
rm -rf dist
|
||||
rm -rf lib/ansible.egg-info/
|
||||
@echo "Cleaning up byte compiled python stuff"
|
||||
find . -type f -regex ".*\.py[co]$$" -delete
|
||||
find . -type d -name "__pycache__" -delete
|
||||
@echo "Cleaning up editor backup files"
|
||||
find . -type f -not -path ./test/units/inventory_test_data/group_vars/noparse/all.yml~ \( -name "*~" -or -name "#*" \) -delete
|
||||
find . -type f \( -name "*.swp" \) -delete
|
||||
@echo "Cleaning up manpage stuff"
|
||||
find ./docs/man -type f -name "*.xml" -delete
|
||||
find ./docs/man -type f -name "*.asciidoc" -delete
|
||||
find ./docs/man/man3 -type f -name "*.3" -delete
|
||||
rm -f ./docs/man/man1/*
|
||||
@echo "Cleaning up output from test runs"
|
||||
rm -rf test/test_data
|
||||
rm -rf shippable/
|
||||
rm -rf logs/
|
||||
rm -rf .cache/
|
||||
rm -f test/units/.coverage*
|
||||
rm -rf test/results/*/*
|
||||
find test/ -type f -name '*.retry' -delete
|
||||
@echo "Cleaning up RPM building stuff"
|
||||
rm -rf MANIFEST rpm-build
|
||||
@echo "Cleaning up Debian building stuff"
|
||||
rm -rf debian
|
||||
rm -rf deb-build
|
||||
rm -rf docs/json
|
||||
rm -rf docs/js
|
||||
@echo "Cleaning up authors file"
|
||||
rm -f AUTHORS.TXT
|
||||
@echo "Cleaning up docsite"
|
||||
$(MAKE) -C docs/docsite clean
|
||||
$(MAKE) -C docs/api clean
|
||||
|
||||
.PHONY: python
|
||||
python:
|
||||
$(PYTHON) setup.py build
|
||||
|
||||
.PHONY: install
|
||||
install:
|
||||
$(PYTHON) setup.py install
|
||||
|
||||
.PHONY: sdist
|
||||
sdist: clean docs
|
||||
$(PYTHON) setup.py sdist
|
||||
|
||||
.PHONY: sdist_upload
|
||||
sdist_upload: clean docs
|
||||
$(PYTHON) setup.py sdist upload 2>&1 |tee upload.log
|
||||
|
||||
.PHONY: rpmcommon
|
||||
rpmcommon: sdist
|
||||
@mkdir -p rpm-build
|
||||
@cp dist/*.gz rpm-build/
|
||||
@sed -e 's#^Version:.*#Version: $(VERSION)#' -e 's#^Release:.*#Release: $(RPMRELEASE)%{?dist}$(REPOTAG)#' $(RPMSPEC) >rpm-build/$(NAME).spec
|
||||
|
||||
.PHONY: mock-srpm
|
||||
mock-srpm: /etc/mock/$(MOCK_CFG).cfg rpmcommon
|
||||
$(MOCK_BIN) -r $(MOCK_CFG) $(MOCK_ARGS) --resultdir rpm-build/ --buildsrpm --spec rpm-build/$(NAME).spec --sources rpm-build/
|
||||
@echo "#############################################"
|
||||
@echo "Ansible SRPM is built:"
|
||||
@echo rpm-build/*.src.rpm
|
||||
@echo "#############################################"
|
||||
|
||||
.PHONY: mock-rpm
|
||||
mock-rpm: /etc/mock/$(MOCK_CFG).cfg mock-srpm
|
||||
$(MOCK_BIN) -r $(MOCK_CFG) $(MOCK_ARGS) --resultdir rpm-build/ --rebuild rpm-build/$(NAME)-*.src.rpm
|
||||
@echo "#############################################"
|
||||
@echo "Ansible RPM is built:"
|
||||
@echo rpm-build/*.noarch.rpm
|
||||
@echo "#############################################"
|
||||
|
||||
.PHONY: srpm
|
||||
srpm: rpmcommon
|
||||
@rpmbuild --define "_topdir %(pwd)/rpm-build" \
|
||||
--define "_builddir %{_topdir}" \
|
||||
--define "_rpmdir %{_topdir}" \
|
||||
--define "_srcrpmdir %{_topdir}" \
|
||||
--define "_specdir $(RPMSPECDIR)" \
|
||||
--define "_sourcedir %{_topdir}" \
|
||||
-bs rpm-build/$(NAME).spec
|
||||
@rm -f rpm-build/$(NAME).spec
|
||||
@echo "#############################################"
|
||||
@echo "Ansible SRPM is built:"
|
||||
@echo " rpm-build/$(RPMNVR).src.rpm"
|
||||
@echo "#############################################"
|
||||
|
||||
.PHONY: rpm
|
||||
rpm: rpmcommon
|
||||
@rpmbuild --define "_topdir %(pwd)/rpm-build" \
|
||||
--define "_builddir %{_topdir}" \
|
||||
--define "_rpmdir %{_topdir}" \
|
||||
--define "_srcrpmdir %{_topdir}" \
|
||||
--define "_specdir $(RPMSPECDIR)" \
|
||||
--define "_sourcedir %{_topdir}" \
|
||||
--define "_rpmfilename %%{NAME}-%%{VERSION}-%%{RELEASE}.%%{ARCH}.rpm" \
|
||||
--define "__python `which $(PYTHON)`" \
|
||||
-ba rpm-build/$(NAME).spec
|
||||
@rm -f rpm-build/$(NAME).spec
|
||||
@echo "#############################################"
|
||||
@echo "Ansible RPM is built:"
|
||||
@echo " rpm-build/$(RPMNVR).noarch.rpm"
|
||||
@echo "#############################################"
|
||||
|
||||
.PHONY: debian
|
||||
debian: sdist
|
||||
@for DIST in $(DEB_DIST) ; do \
|
||||
mkdir -p deb-build/$${DIST} ; \
|
||||
tar -C deb-build/$${DIST} -xvf dist/$(NAME)-$(VERSION).tar.gz ; \
|
||||
cp -a packaging/debian deb-build/$${DIST}/$(NAME)-$(VERSION)/ ; \
|
||||
sed -ie "s|%VERSION%|$(VERSION)|g;s|%RELEASE%|$(DEB_RELEASE)|;s|%DIST%|$${DIST}|g;s|%DATE%|$(DEB_DATE)|g" deb-build/$${DIST}/$(NAME)-$(VERSION)/debian/changelog ; \
|
||||
done
|
||||
|
||||
.PHONY: deb
|
||||
deb: deb-src
|
||||
@for DIST in $(DEB_DIST) ; do \
|
||||
PBUILDER_OPTS="$(PBUILDER_OPTS) --distribution $${DIST} --basetgz $(PBUILDER_CACHE_DIR)/$${DIST}-$(PBUILDER_ARCH)-base.tgz --buildresult $(CURDIR)/deb-build/$${DIST}" ; \
|
||||
$(PBUILDER_BIN) create $${PBUILDER_OPTS} --othermirror "deb http://archive.ubuntu.com/ubuntu $${DIST} universe" ; \
|
||||
$(PBUILDER_BIN) update $${PBUILDER_OPTS} ; \
|
||||
$(PBUILDER_BIN) build $${PBUILDER_OPTS} deb-build/$${DIST}/$(NAME)_$(VERSION)-$(DEB_RELEASE)~$${DIST}.dsc ; \
|
||||
done
|
||||
@echo "#############################################"
|
||||
@echo "Ansible DEB artifacts:"
|
||||
@for DIST in $(DEB_DIST) ; do \
|
||||
echo deb-build/$${DIST}/$(NAME)_$(VERSION)-$(DEB_RELEASE)~$${DIST}_amd64.changes ; \
|
||||
done
|
||||
@echo "#############################################"
|
||||
|
||||
# Build package outside of pbuilder, with locally installed dependencies.
|
||||
# Install BuildRequires as noted in packaging/debian/control.
|
||||
.PHONY: local_deb
|
||||
local_deb: debian
|
||||
@for DIST in $(DEB_DIST) ; do \
|
||||
(cd deb-build/$${DIST}/$(NAME)-$(VERSION)/ && $(DEBUILD) -b) ; \
|
||||
done
|
||||
@echo "#############################################"
|
||||
@echo "Ansible DEB artifacts:"
|
||||
@for DIST in $(DEB_DIST) ; do \
|
||||
echo deb-build/$${DIST}/$(NAME)_$(VERSION)-$(DEB_RELEASE)~$${DIST}_amd64.changes ; \
|
||||
done
|
||||
@echo "#############################################"
|
||||
|
||||
.PHONY: deb-src
|
||||
deb-src: debian
|
||||
@for DIST in $(DEB_DIST) ; do \
|
||||
(cd deb-build/$${DIST}/$(NAME)-$(VERSION)/ && $(DEBUILD) -S) ; \
|
||||
done
|
||||
@echo "#############################################"
|
||||
@echo "Ansible DEB artifacts:"
|
||||
@for DIST in $(DEB_DIST) ; do \
|
||||
echo deb-build/$${DIST}/$(NAME)_$(VERSION)-$(DEB_RELEASE)~$${DIST}_source.changes ; \
|
||||
done
|
||||
@echo "#############################################"
|
||||
|
||||
.PHONY: deb-upload
|
||||
deb-upload: deb
|
||||
@for DIST in $(DEB_DIST) ; do \
|
||||
$(DPUT_BIN) $(DPUT_OPTS) $(DEB_PPA) deb-build/$${DIST}/$(NAME)_$(VERSION)-$(DEB_RELEASE)~$${DIST}_amd64.changes ; \
|
||||
done
|
||||
|
||||
.PHONY: deb-src-upload
|
||||
deb-src-upload: deb-src
|
||||
@for DIST in $(DEB_DIST) ; do \
|
||||
$(DPUT_BIN) $(DPUT_OPTS) $(DEB_PPA) deb-build/$${DIST}/$(NAME)_$(VERSION)-$(DEB_RELEASE)~$${DIST}_source.changes ; \
|
||||
done
|
||||
|
||||
.PHONY: epub
|
||||
epub:
|
||||
(cd docs/docsite/; CPUS=$(CPUS) make epub)
|
||||
|
||||
# for arch or gentoo, read instructions in the appropriate 'packaging' subdirectory directory
|
||||
.PHONY: webdocs
|
||||
webdocs:
|
||||
(cd docs/docsite/; CPUS=$(CPUS) make docs)
|
||||
|
||||
.PHONY: generate_asciidoc
|
||||
generate_asciidoc: lib/ansible/cli/*.py
|
||||
mkdir -p ./docs/man/man1/ ; \
|
||||
PYTHONPATH=./lib $(GENERATE_CLI) --template-file=docs/templates/man.j2 --output-dir=docs/man/man1/ --output-format man lib/ansible/cli/*.py
|
||||
|
||||
|
||||
docs: generate_asciidoc
|
||||
make $(MANPAGES)
|
||||
|
||||
.PHONY: alldocs
|
||||
alldocs: docs webdocs
|
||||
|
||||
version:
|
||||
@echo $(VERSION)
|
||||
|
||||
123
README.md
123
README.md
@ -1,101 +1,56 @@
|
||||
[](https://pypi.org/project/ansible-core)
|
||||
[](https://docs.ansible.com/ansible/latest/)
|
||||
[](https://docs.ansible.com/ansible/devel/community/communication.html)
|
||||
[](https://dev.azure.com/ansible/ansible/_build/latest?definitionId=20&branchName=devel)
|
||||
[](https://docs.ansible.com/ansible/devel/community/code_of_conduct.html)
|
||||
[](https://docs.ansible.com/ansible/devel/community/communication.html#mailing-list-information)
|
||||
[](COPYING)
|
||||
[](https://bestpractices.coreinfrastructure.org/projects/2372)
|
||||
[](https://pypi.python.org/pypi/ansible)
|
||||
[](https://app.shippable.com/projects/573f79d02a8192902e20e34b)
|
||||
|
||||
# Ansible
|
||||
|
||||
Ansible is a radically simple IT automation system. It handles
|
||||
configuration management, application deployment, cloud provisioning,
|
||||
ad-hoc task execution, network automation, and multi-node orchestration. Ansible makes complex
|
||||
changes like zero-downtime rolling updates with load balancers easy. More information on the Ansible [website](https://ansible.com/).
|
||||
Ansible
|
||||
=======
|
||||
|
||||
## Design Principles
|
||||
Ansible is a radically simple IT automation system. It handles configuration-management, application deployment, cloud provisioning, ad-hoc task-execution, and multinode orchestration - including trivializing things like zero downtime rolling updates with load balancers.
|
||||
|
||||
* Have an extremely simple setup process with a minimal learning curve.
|
||||
* Manage machines quickly and in parallel.
|
||||
* Avoid custom-agents and additional open ports, be agentless by
|
||||
leveraging the existing SSH daemon.
|
||||
* Describe infrastructure in a language that is both machine and human
|
||||
friendly.
|
||||
* Focus on security and easy auditability/review/rewriting of content.
|
||||
* Manage new remote machines instantly, without bootstrapping any
|
||||
software.
|
||||
* Allow module development in any dynamic language, not just Python.
|
||||
* Be usable as non-root.
|
||||
* Be the easiest IT automation system to use, ever.
|
||||
Read the documentation and more at https://ansible.com/
|
||||
|
||||
## Use Ansible
|
||||
You can find installation instructions [here](https://docs.ansible.com/ansible/intro_installation.html) for a variety of platforms. Most users should probably install a released version of Ansible from `pip`, a package manager or our [release repository](https://releases.ansible.com/ansible/). [Officially supported](https://www.ansible.com/ansible-engine) builds of Ansible are also available. Some power users run directly from the development branch - while significant efforts are made to ensure that `devel` is reasonably stable, you're more likely to encounter breaking changes when running Ansible this way.
|
||||
|
||||
You can install a released version of Ansible with `pip` or a package manager. See our
|
||||
[installation guide](https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html) for details on installing Ansible
|
||||
on a variety of platforms.
|
||||
Design Principles
|
||||
=================
|
||||
|
||||
Power users and developers can run the `devel` branch, which has the latest
|
||||
features and fixes, directly. Although it is reasonably stable, you are more likely to encounter
|
||||
breaking changes when running the `devel` branch. We recommend getting involved
|
||||
in the Ansible community if you want to run the `devel` branch.
|
||||
* Have a dead simple setup process and a minimal learning curve
|
||||
* Manage machines very quickly and in parallel
|
||||
* Avoid custom-agents and additional open ports, be agentless by leveraging the existing SSH daemon
|
||||
* Describe infrastructure in a language that is both machine and human friendly
|
||||
* Focus on security and easy auditability/review/rewriting of content
|
||||
* Manage new remote machines instantly, without bootstrapping any software
|
||||
* Allow module development in any dynamic language, not just Python
|
||||
* Be usable as non-root
|
||||
* Be the easiest IT automation system to use, ever.
|
||||
|
||||
## Communication
|
||||
Get Involved
|
||||
============
|
||||
|
||||
Join the Ansible forum to ask questions, get help, and interact with the
|
||||
community.
|
||||
* Read [Community Information](https://docs.ansible.com/community.html) for all kinds of ways to contribute to and interact with the project, including mailing list information and how to submit bug reports and code to Ansible.
|
||||
* All code submissions are done through pull requests. Take care to make sure no merge commits are in the submission, and use `git rebase` vs `git merge` for this reason. If submitting a large code change (other than modules), it's probably a good idea to join ansible-devel and talk about what you would like to do or add first and to avoid duplicate efforts. This not only helps everyone know what's going on, it also helps save time and effort if we decide some changes are needed.
|
||||
* Users list: [ansible-project](https://groups.google.com/group/ansible-project)
|
||||
* Development list: [ansible-devel](https://groups.google.com/group/ansible-devel)
|
||||
* Announcement list: [ansible-announce](https://groups.google.com/group/ansible-announce) - read only
|
||||
* irc.freenode.net: #ansible
|
||||
|
||||
* [Get Help](https://forum.ansible.com/c/help/6): Find help or share your Ansible knowledge to help others.
|
||||
Use tags to filter and subscribe to posts, such as the following:
|
||||
* Posts tagged with [ansible](https://forum.ansible.com/tag/ansible)
|
||||
* Posts tagged with [ansible-core](https://forum.ansible.com/tag/ansible-core)
|
||||
* Posts tagged with [playbook](https://forum.ansible.com/tag/playbook)
|
||||
* [Social Spaces](https://forum.ansible.com/c/chat/4): Meet and interact with fellow enthusiasts.
|
||||
* [News & Announcements](https://forum.ansible.com/c/news/5): Track project-wide announcements including social events.
|
||||
* [Bullhorn newsletter](https://docs.ansible.com/ansible/devel/community/communication.html#the-bullhorn): Get release announcements and important changes.
|
||||
Branch Info
|
||||
===========
|
||||
|
||||
For more ways to get in touch, see [Communicating with the Ansible community](https://docs.ansible.com/ansible/devel/community/communication.html).
|
||||
* Releases are named after Led Zeppelin songs. (Releases prior to 2.0 were named after Van Halen songs.)
|
||||
* The devel branch corresponds to the release actively under development.
|
||||
* Various release-X.Y branches exist for previous releases.
|
||||
* We'd love to have your contributions, read [Community Information](https://docs.ansible.com/community.html) for notes on how to get started.
|
||||
|
||||
## Contribute to Ansible
|
||||
Authors
|
||||
=======
|
||||
|
||||
* Check out the [Contributor's Guide](./.github/CONTRIBUTING.md).
|
||||
* Read [Community Information](https://docs.ansible.com/ansible/devel/community) for all
|
||||
kinds of ways to contribute to and interact with the project,
|
||||
including how to submit bug reports and code to Ansible.
|
||||
* Submit a proposed code update through a pull request to the `devel` branch.
|
||||
* Talk to us before making larger changes
|
||||
to avoid duplicate efforts. This not only helps everyone
|
||||
know what is going on, but it also helps save time and effort if we decide
|
||||
some changes are needed.
|
||||
Ansible was created by [Michael DeHaan](https://github.com/mpdehaan) (michael.dehaan/gmail/com) and has contributions from over 1000 users (and growing). Thanks everyone!
|
||||
|
||||
## Coding Guidelines
|
||||
Ansible is sponsored by [Ansible, Inc](https://ansible.com)
|
||||
|
||||
We document our Coding Guidelines in the [Developer Guide](https://docs.ansible.com/ansible/devel/dev_guide/). We particularly suggest you review:
|
||||
|
||||
* [Contributing your module to Ansible](https://docs.ansible.com/ansible/devel/dev_guide/developing_modules_checklist.html)
|
||||
* [Conventions, tips, and pitfalls](https://docs.ansible.com/ansible/devel/dev_guide/developing_modules_best_practices.html)
|
||||
|
||||
## Branch Info
|
||||
|
||||
* The `devel` branch corresponds to the release actively under development.
|
||||
* The `stable-2.X` branches correspond to stable releases.
|
||||
* Create a branch based on `devel` and set up a [dev environment](https://docs.ansible.com/ansible/devel/dev_guide/developing_modules_general.html#common-environment-setup) if you want to open a PR.
|
||||
* See the [Ansible release and maintenance](https://docs.ansible.com/ansible/devel/reference_appendices/release_and_maintenance.html) page for information about active branches.
|
||||
|
||||
## Roadmap
|
||||
|
||||
Based on team and community feedback, an initial roadmap will be published for a major or minor version (ex: 2.7, 2.8).
|
||||
The [Ansible Roadmap page](https://docs.ansible.com/ansible/devel/roadmap/) details what is planned and how to influence the roadmap.
|
||||
|
||||
## Authors
|
||||
|
||||
Ansible was created by [Michael DeHaan](https://github.com/mpdehaan)
|
||||
and has contributions from over 5000 users (and growing). Thanks everyone!
|
||||
|
||||
[Ansible](https://www.ansible.com) is sponsored by [Red Hat, Inc.](https://www.redhat.com)
|
||||
|
||||
## License
|
||||
|
||||
GNU General Public License v3.0 or later
|
||||
License
|
||||
=======
|
||||
GNU General Public License v3.0
|
||||
|
||||
See [COPYING](COPYING) to see the full text.
|
||||
|
||||
84
RELEASES.txt
Normal file
84
RELEASES.txt
Normal file
@ -0,0 +1,84 @@
|
||||
Ansible Releases at a Glance
|
||||
============================
|
||||
|
||||
VERSION RELEASE CODE NAME
|
||||
++++++++++++++++++++++++++++++
|
||||
|
||||
2.4.0 TBD "Dancing Days"
|
||||
2.3.2 2017-08-04 "Ramble On"
|
||||
2.3.1 2017-06-01 "Ramble On"
|
||||
2.3.0 2017-04-12 "Ramble On"
|
||||
2.2.3 2017-05-09 "The Battle of Evermore"
|
||||
2.2.2 2017-03-27 "The Battle of Evermore"
|
||||
2.2.1 2017-01-16 "The Battle of Evermore"
|
||||
2.2.0 2016-11-01 "The Battle of Evermore"
|
||||
2.1.6 2017-06-01 "The Song Remains the Same"
|
||||
2.1.5 2017-03-27 "The Song Remains the Same"
|
||||
2.1.4 2017-01-16 "The Song Remains the Same"
|
||||
2.1.3 2016-11-04 "The Song Remains the Same"
|
||||
2.1.2 2016-09-29 "The Song Remains the Same"
|
||||
2.1.1 2016-07-28 "The Song Remains the Same"
|
||||
2.1.0 2016-05-25 "The Song Remains the Same"
|
||||
2.0.2 2016-04-19 "Over the Hills and Far Away"
|
||||
2.0.1 2016-02-24 "Over the Hills and Far Away"
|
||||
2.0.0 2016-01-12 "Over the Hills and Far Away"
|
||||
1.9.6 2016-04-15 "Dancing In the Streets"
|
||||
1.9.5 2016-03-21 "Dancing In the Streets"
|
||||
1.9.4 2015-10-09 "Dancing In the Streets"
|
||||
1.9.3 2015-09-03 "Dancing In the Streets"
|
||||
1.9.2 2015-06-24 "Dancing In the Streets"
|
||||
1.9.1 2015-04-27 "Dancing In the Streets"
|
||||
1.9.0 2015-03-25 "Dancing In the Streets"
|
||||
1.8.4 2015-02-19 "You Really Got Me"
|
||||
1.8.3 2015-02-17 "You Really Got Me"
|
||||
1.8.2 2014-12-04 "You Really Got Me"
|
||||
1.8.1 2014-11-26 "You Really Got Me"
|
||||
1.8.0 2014-11-25 "You Really Got Me"
|
||||
1.7.2 2014-09-24 "Summer Nights"
|
||||
1.7.1 2014-08-14 "Summer Nights"
|
||||
1.7.0 2014-08-06 "Summer Nights"
|
||||
1.6.10 2014-07-25 "The Cradle Will Rock"
|
||||
1.6.9 2014-07-24 "The Cradle Will Rock"
|
||||
1.6.8 2014-07-22 "The Cradle Will Rock"
|
||||
1.6.7 2014-07-21 "The Cradle Will Rock"
|
||||
1.6.6 2014-07-01 "The Cradle Will Rock"
|
||||
1.6.5 2014-06-25 "The Cradle Will Rock"
|
||||
1.6.4 2014-06-25 "The Cradle Will Rock"
|
||||
1.6.3 2014-06-09 "The Cradle Will Rock"
|
||||
1.6.2 2014-05-23 "The Cradle Will Rock"
|
||||
1.6.1 2014-05-07 "The Cradle Will Rock"
|
||||
1.6.0 2014-05-05 "The Cradle Will Rock"
|
||||
1.5.5 2014-04-18 "Love Walks In"
|
||||
1.5.4 2014-04-01 "Love Walks In"
|
||||
1.5.3 2014-03-13 "Love Walks In"
|
||||
1.5.2 2014-03-11 "Love Walks In"
|
||||
1.5.1 2014-03-10 "Love Walks In"
|
||||
1.5.0 2014-02-28 "Love Walks In"
|
||||
1.4.5 2014-02-12 "Could This Be Magic?"
|
||||
1.4.4 2014-01-06 "Could This Be Magic?"
|
||||
1.4.3 2013-12-20 "Could This Be Magic?"
|
||||
1.4.2 2013-12-18 "Could This Be Magic?"
|
||||
1.4.1 2013-11-27 "Could This Be Magic?"
|
||||
1.4.0 2013-11-21 "Could This Be Magic?"
|
||||
1.3.4 2013-10-29 "Top of the World"
|
||||
1.3.3 2013-10-09 "Top of the World"
|
||||
1.3.2 2013-09-19 "Top of the World"
|
||||
1.3.1 2013-09-16 "Top of the World"
|
||||
1.3.0 2013-09-13 "Top of the World"
|
||||
1.2.3 2013-08-21 "Right Now"
|
||||
1.2.2 2013-07-05 "Right Now"
|
||||
1.2.1 2013-07-04 "Right Now"
|
||||
1.2.0 2013-06-10 "Right Now"
|
||||
1.1.0 2013-04-02 "Mean Street"
|
||||
1.0.0 2013-02-01 "Eruption"
|
||||
0.9.0 2012-11-30 "Dreams"
|
||||
0.8.0 2012-10-19 "Cathedral"
|
||||
0.7.0 2012-09-06 "Panama"
|
||||
0.6.0 2012-08-06 "Cabo"
|
||||
0.5.0 2012-07-04 "Amsterdam"
|
||||
0.4.0 2012-05-23 "Unchained"
|
||||
0.3.0 2012-04-23 "Baluchitherium"
|
||||
0.2.0 ? "Untitled"
|
||||
0.1.0 ? "Untitled"
|
||||
0.0.2 ? "Untitled"
|
||||
0.0.1 ? "Untitled"
|
||||
28
ROADMAP.rst
Normal file
28
ROADMAP.rst
Normal file
@ -0,0 +1,28 @@
|
||||
*******************************
|
||||
Roadmap For Ansible by Red Hat
|
||||
*******************************
|
||||
This document is now the location for published Ansible Core roadmaps.
|
||||
|
||||
The roadmap will be updated by version. Based on team and community feedback, an initial roadmap will be published for a major or minor version (2.0, 2.1). Subminor versions will generally not have roadmaps published.
|
||||
|
||||
2.1 was the first time Ansible has published this and asked for feedback in this manner. So feedback on the roadmap and the new process is quite welcome. The team is aiming for further transparency and better inclusion of both community desires and submissions.
|
||||
|
||||
These roadmaps are the team's *best guess* roadmaps based on the Ansible team's experience and are also based on requests and feedback from the community. There are things that may not make it on due to time constraints, lack of community maintainers, etc. And there may be things that got missed, so each roadmap is published both as an idea of what is upcoming in Ansible, and as a medium for seeking further feedback from the community. Here are the good places for you to submit feedback:
|
||||
|
||||
- Add to the agenda of a `Core IRC Meetings <https://github.com/ansible/community/blob/master/meetings/README.md>`_ (preferred)
|
||||
- Ansible's google-group: ansible-devel
|
||||
- AnsibleFest conferences.
|
||||
- IRC freenode channel: #ansible-devel (this one may have things lost in lots of conversation, so a caution).
|
||||
|
||||
=======================================
|
||||
Current 2.4 Roadmap is open for comment
|
||||
=======================================
|
||||
We are starting to build the 2.4 Roadmap. We are seeking community feedback! That document is here:
|
||||
- `2.4 Roadmap Document <docs/docsite/rst/roadmap/ROADMAP_2_4.rst>`_
|
||||
|
||||
|
||||
|
||||
**Old Roadmaps are found here:**
|
||||
- `2.3 Roadmap Document <docs/docsite/rst/roadmap/ROADMAP_2_3.rst>`_
|
||||
- `2.2 Roadmap Document <docs/docsite/rst/roadmap/ROADMAP_2_2.rst>`_
|
||||
- `2.1 Roadmap Document <docs/docsite/rst/roadmap/ROADMAP_2_1.rst>`_
|
||||
2716
ansible-core-sitemap.xml
Normal file
2716
ansible-core-sitemap.xml
Normal file
File diff suppressed because it is too large
Load Diff
@ -1 +0,0 @@
|
||||
../lib/ansible/cli/adhoc.py
|
||||
145
bin/ansible
Executable file
145
bin/ansible
Executable file
@ -0,0 +1,145 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# (c) 2012, Michael DeHaan <michael.dehaan@gmail.com>
|
||||
#
|
||||
# This file is part of Ansible
|
||||
#
|
||||
# Ansible is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Ansible is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
########################################################
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
__requires__ = ['ansible']
|
||||
try:
|
||||
import pkg_resources
|
||||
except Exception:
|
||||
# Use pkg_resources to find the correct versions of libraries and set
|
||||
# sys.path appropriately when there are multiversion installs. But we
|
||||
# have code that better expresses the errors in the places where the code
|
||||
# is actually used (the deps are optional for many code paths) so we don't
|
||||
# want to fail here.
|
||||
pass
|
||||
|
||||
import os
|
||||
import shutil
|
||||
import sys
|
||||
import traceback
|
||||
|
||||
from ansible.errors import AnsibleError, AnsibleOptionsError, AnsibleParserError
|
||||
from ansible.module_utils._text import to_text
|
||||
|
||||
|
||||
class LastResort(object):
|
||||
# OUTPUT OF LAST RESORT
|
||||
def display(self, msg, log_only=None):
|
||||
print(msg, file=sys.stderr)
|
||||
|
||||
def error(self, msg, wrap_text=None):
|
||||
print(msg, file=sys.stderr)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
display = LastResort()
|
||||
|
||||
try: # bad ANSIBLE_CONFIG or config options can force ugly stacktrace
|
||||
import ansible.constants as C
|
||||
from ansible.utils.display import Display
|
||||
except AnsibleOptionsError as e:
|
||||
display.error(to_text(e), wrap_text=False)
|
||||
sys.exit(5)
|
||||
|
||||
cli = None
|
||||
me = os.path.basename(sys.argv[0])
|
||||
|
||||
try:
|
||||
display = Display()
|
||||
display.debug("starting run")
|
||||
|
||||
sub = None
|
||||
target = me.split('-')
|
||||
if target[-1][0].isdigit():
|
||||
# Remove any version or python version info as downstreams
|
||||
# sometimes add that
|
||||
target = target[:-1]
|
||||
|
||||
if len(target) > 1:
|
||||
sub = target[1]
|
||||
myclass = "%sCLI" % sub.capitalize()
|
||||
elif target[0] == 'ansible':
|
||||
sub = 'adhoc'
|
||||
myclass = 'AdHocCLI'
|
||||
else:
|
||||
raise AnsibleError("Unknown Ansible alias: %s" % me)
|
||||
|
||||
try:
|
||||
mycli = getattr(__import__("ansible.cli.%s" % sub, fromlist=[myclass]), myclass)
|
||||
except ImportError as e:
|
||||
# ImportError members have changed in py3
|
||||
if 'msg' in dir(e):
|
||||
msg = e.msg
|
||||
else:
|
||||
msg = e.message
|
||||
if msg.endswith(' %s' % sub):
|
||||
raise AnsibleError("Ansible sub-program not implemented: %s" % me)
|
||||
else:
|
||||
raise
|
||||
|
||||
try:
|
||||
args = [to_text(a, errors='surrogate_or_strict') for a in sys.argv]
|
||||
except UnicodeError:
|
||||
display.error('Command line args are not in utf-8, unable to continue. Ansible currently only understands utf-8')
|
||||
display.display(u"The full traceback was:\n\n%s" % to_text(traceback.format_exc()))
|
||||
exit_code = 6
|
||||
else:
|
||||
cli = mycli(args)
|
||||
cli.parse()
|
||||
exit_code = cli.run()
|
||||
|
||||
except AnsibleOptionsError as e:
|
||||
cli.parser.print_help()
|
||||
display.error(to_text(e), wrap_text=False)
|
||||
exit_code = 5
|
||||
except AnsibleParserError as e:
|
||||
display.error(to_text(e), wrap_text=False)
|
||||
exit_code = 4
|
||||
# TQM takes care of these, but leaving comment to reserve the exit codes
|
||||
# except AnsibleHostUnreachable as e:
|
||||
# display.error(str(e))
|
||||
# exit_code = 3
|
||||
# except AnsibleHostFailed as e:
|
||||
# display.error(str(e))
|
||||
# exit_code = 2
|
||||
except AnsibleError as e:
|
||||
display.error(to_text(e), wrap_text=False)
|
||||
exit_code = 1
|
||||
except KeyboardInterrupt:
|
||||
display.error("User interrupted execution")
|
||||
exit_code = 99
|
||||
except Exception as e:
|
||||
have_cli_options = cli is not None and cli.options is not None
|
||||
display.error("Unexpected Exception, this is probably a bug: %s" % to_text(e), wrap_text=False)
|
||||
if not have_cli_options or have_cli_options and cli.options.verbosity > 2:
|
||||
log_only = False
|
||||
else:
|
||||
display.display("to see the full traceback, use -vvv")
|
||||
log_only = True
|
||||
display.display(u"the full traceback was:\n\n%s" % to_text(traceback.format_exc()), log_only=log_only)
|
||||
exit_code = 250
|
||||
finally:
|
||||
# Remove ansible tempdir
|
||||
shutil.rmtree(C.DEFAULT_LOCAL_TMP, True)
|
||||
|
||||
sys.exit(exit_code)
|
||||
@ -1 +1 @@
|
||||
../lib/ansible/cli/config.py
|
||||
ansible
|
||||
389
bin/ansible-connection
Executable file
389
bin/ansible-connection
Executable file
@ -0,0 +1,389 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# (c) 2017, Ansible, Inc. <support@ansible.com>
|
||||
#
|
||||
# This file is part of Ansible
|
||||
#
|
||||
# Ansible is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Ansible is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
########################################################
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
|
||||
__metaclass__ = type
|
||||
__requires__ = ['ansible']
|
||||
|
||||
try:
|
||||
import pkg_resources
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
import fcntl
|
||||
import os
|
||||
import shlex
|
||||
import signal
|
||||
import socket
|
||||
import sys
|
||||
import time
|
||||
import traceback
|
||||
import datetime
|
||||
import errno
|
||||
|
||||
from ansible import constants as C
|
||||
from ansible.module_utils._text import to_bytes, to_native, to_text
|
||||
from ansible.module_utils.six import PY3
|
||||
from ansible.module_utils.six.moves import cPickle
|
||||
from ansible.module_utils.connection import send_data, recv_data
|
||||
from ansible.playbook.play_context import PlayContext
|
||||
from ansible.plugins.loader import connection_loader
|
||||
from ansible.utils.path import unfrackpath, makedirs_safe
|
||||
from ansible.errors import AnsibleConnectionFailure
|
||||
from ansible.utils.display import Display
|
||||
|
||||
|
||||
def do_fork():
|
||||
'''
|
||||
Does the required double fork for a daemon process. Based on
|
||||
http://code.activestate.com/recipes/66012-fork-a-daemon-process-on-unix/
|
||||
'''
|
||||
try:
|
||||
pid = os.fork()
|
||||
if pid > 0:
|
||||
return pid
|
||||
# This is done as a 'good practice' for daemons, but we need to keep the cwd
|
||||
# leaving it here as a note that we KNOW its good practice but are not doing it on purpose.
|
||||
# os.chdir("/")
|
||||
os.setsid()
|
||||
os.umask(0)
|
||||
|
||||
try:
|
||||
pid = os.fork()
|
||||
if pid > 0:
|
||||
sys.exit(0)
|
||||
|
||||
if C.DEFAULT_LOG_PATH != '':
|
||||
out_file = open(C.DEFAULT_LOG_PATH, 'ab+')
|
||||
err_file = open(C.DEFAULT_LOG_PATH, 'ab+', 0)
|
||||
else:
|
||||
out_file = open('/dev/null', 'ab+')
|
||||
err_file = open('/dev/null', 'ab+', 0)
|
||||
|
||||
os.dup2(out_file.fileno(), sys.stdout.fileno())
|
||||
os.dup2(err_file.fileno(), sys.stderr.fileno())
|
||||
os.close(sys.stdin.fileno())
|
||||
|
||||
return pid
|
||||
except OSError as e:
|
||||
sys.exit(1)
|
||||
except OSError as e:
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
class Server():
|
||||
|
||||
def __init__(self, socket_path, play_context):
|
||||
self.socket_path = socket_path
|
||||
self.play_context = play_context
|
||||
|
||||
display.display(
|
||||
'creating new control socket for host %s:%s as user %s' %
|
||||
(play_context.remote_addr, play_context.port, play_context.remote_user),
|
||||
log_only=True
|
||||
)
|
||||
|
||||
display.display('control socket path is %s' % socket_path, log_only=True)
|
||||
display.display('current working directory is %s' % os.getcwd(), log_only=True)
|
||||
|
||||
self._start_time = datetime.datetime.now()
|
||||
|
||||
display.display("using connection plugin %s" % self.play_context.connection, log_only=True)
|
||||
|
||||
self.connection = connection_loader.get(play_context.connection, play_context, sys.stdin)
|
||||
self.connection._connect()
|
||||
|
||||
if not self.connection.connected:
|
||||
raise AnsibleConnectionFailure('unable to connect to remote host %s' % self._play_context.remote_addr)
|
||||
|
||||
connection_time = datetime.datetime.now() - self._start_time
|
||||
display.display('connection established to %s in %s' % (play_context.remote_addr, connection_time), log_only=True)
|
||||
|
||||
self.socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
||||
self.socket.bind(self.socket_path)
|
||||
self.socket.listen(1)
|
||||
display.display('local socket is set to listening', log_only=True)
|
||||
|
||||
def run(self):
|
||||
try:
|
||||
while True:
|
||||
signal.signal(signal.SIGALRM, self.connect_timeout)
|
||||
signal.signal(signal.SIGTERM, self.handler)
|
||||
signal.alarm(C.PERSISTENT_CONNECT_TIMEOUT)
|
||||
|
||||
(s, addr) = self.socket.accept()
|
||||
display.display('incoming request accepted on persistent socket', log_only=True)
|
||||
signal.alarm(0)
|
||||
|
||||
while True:
|
||||
data = recv_data(s)
|
||||
if not data:
|
||||
break
|
||||
|
||||
signal.signal(signal.SIGALRM, self.command_timeout)
|
||||
signal.alarm(self.play_context.timeout)
|
||||
|
||||
op = to_text(data.split(b':')[0])
|
||||
display.display('socket operation is %s' % op, log_only=True)
|
||||
|
||||
method = getattr(self, 'do_%s' % op, None)
|
||||
|
||||
rc = 255
|
||||
stdout = stderr = ''
|
||||
|
||||
if not method:
|
||||
stderr = 'Invalid action specified'
|
||||
else:
|
||||
rc, stdout, stderr = method(data)
|
||||
|
||||
signal.alarm(0)
|
||||
|
||||
display.display('socket operation completed with rc %s' % rc, log_only=True)
|
||||
|
||||
send_data(s, to_bytes(rc))
|
||||
send_data(s, to_bytes(stdout))
|
||||
send_data(s, to_bytes(stderr))
|
||||
|
||||
s.close()
|
||||
|
||||
except Exception as e:
|
||||
# socket.accept() will raise EINTR if the socket.close() is called
|
||||
if e.errno != errno.EINTR:
|
||||
display.display(traceback.format_exc(), log_only=True)
|
||||
|
||||
finally:
|
||||
# when done, close the connection properly and cleanup
|
||||
# the socket file so it can be recreated
|
||||
self.shutdown()
|
||||
end_time = datetime.datetime.now()
|
||||
delta = end_time - self._start_time
|
||||
display.display('shutdown local socket, connection was active for %s secs' % delta, log_only=True)
|
||||
|
||||
def connect_timeout(self, signum, frame):
|
||||
display.display('persistent connection idle timeout triggered, timeout value is %s secs' % C.PERSISTENT_CONNECT_TIMEOUT, log_only=True)
|
||||
self.shutdown()
|
||||
|
||||
def command_timeout(self, signum, frame):
|
||||
display.display('command timeout triggered, timeout value is %s secs' % self.play_context.timeout, log_only=True)
|
||||
self.shutdown()
|
||||
|
||||
def handler(self, signum, frame):
|
||||
display.display('signal handler called with signal %s' % signum, log_only=True)
|
||||
self.shutdown()
|
||||
|
||||
def shutdown(self):
|
||||
display.display('shutdown persistent connection requested', log_only=True)
|
||||
|
||||
if not os.path.exists(self.socket_path):
|
||||
display.display('persistent connection is not active', log_only=True)
|
||||
return
|
||||
|
||||
try:
|
||||
if self.socket:
|
||||
display.display('closing local listener', log_only=True)
|
||||
self.socket.close()
|
||||
if self.connection:
|
||||
display.display('closing the connection', log_only=True)
|
||||
self.connection.close()
|
||||
except:
|
||||
pass
|
||||
finally:
|
||||
if os.path.exists(self.socket_path):
|
||||
display.display('removing the local control socket', log_only=True)
|
||||
os.remove(self.socket_path)
|
||||
|
||||
display.display('shutdown complete', log_only=True)
|
||||
|
||||
def do_EXEC(self, data):
|
||||
cmd = data.split(b'EXEC: ')[1]
|
||||
display.display('Command executed: %s' % cmd, log_only=True)
|
||||
return self.connection.exec_command(cmd)
|
||||
|
||||
def do_PUT(self, data):
|
||||
(op, src, dst) = shlex.split(to_native(data))
|
||||
return self.connection.fetch_file(src, dst)
|
||||
|
||||
def do_FETCH(self, data):
|
||||
(op, src, dst) = shlex.split(to_native(data))
|
||||
return self.connection.put_file(src, dst)
|
||||
|
||||
def do_CONTEXT(self, data):
|
||||
pc_data = data.split(b'CONTEXT: ', 1)[1]
|
||||
|
||||
if PY3:
|
||||
pc_data = cPickle.loads(pc_data, encoding='bytes')
|
||||
else:
|
||||
pc_data = cPickle.loads(pc_data)
|
||||
|
||||
pc = PlayContext()
|
||||
pc.deserialize(pc_data)
|
||||
|
||||
try:
|
||||
self.connection.update_play_context(pc)
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
return (0, 'ok', '')
|
||||
|
||||
def do_RUN(self, data):
|
||||
timeout = self.play_context.timeout
|
||||
while bool(timeout):
|
||||
if os.path.exists(self.socket_path):
|
||||
break
|
||||
time.sleep(1)
|
||||
timeout -= 1
|
||||
socket_bytes = to_bytes(self.socket_path, errors='surrogate_or_strict')
|
||||
return 0, b'\n#SOCKET_PATH#: %s\n' % socket_bytes, ''
|
||||
|
||||
|
||||
def communicate(sock, data):
|
||||
send_data(sock, data)
|
||||
rc = int(recv_data(sock), 10)
|
||||
stdout = recv_data(sock)
|
||||
stderr = recv_data(sock)
|
||||
return (rc, stdout, stderr)
|
||||
|
||||
|
||||
def main():
|
||||
# Need stdin as a byte stream
|
||||
if PY3:
|
||||
stdin = sys.stdin.buffer
|
||||
else:
|
||||
stdin = sys.stdin
|
||||
|
||||
try:
|
||||
# read the play context data via stdin, which means depickling it
|
||||
# FIXME: as noted above, we will probably need to deserialize the
|
||||
# connection loader here as well at some point, otherwise this
|
||||
# won't find role- or playbook-based connection plugins
|
||||
cur_line = stdin.readline()
|
||||
init_data = b''
|
||||
while cur_line.strip() != b'#END_INIT#':
|
||||
if cur_line == b'':
|
||||
raise Exception("EOF found before init data was complete")
|
||||
init_data += cur_line
|
||||
cur_line = stdin.readline()
|
||||
if PY3:
|
||||
pc_data = cPickle.loads(init_data, encoding='bytes')
|
||||
else:
|
||||
pc_data = cPickle.loads(init_data)
|
||||
|
||||
pc = PlayContext()
|
||||
pc.deserialize(pc_data)
|
||||
|
||||
except Exception as e:
|
||||
# FIXME: better error message/handling/logging
|
||||
sys.stderr.write(traceback.format_exc())
|
||||
sys.exit("FAIL: %s" % e)
|
||||
|
||||
ssh = connection_loader.get('ssh', class_only=True)
|
||||
cp = ssh._create_control_path(pc.remote_addr, pc.port, pc.remote_user, pc.connection)
|
||||
|
||||
# create the persistent connection dir if need be and create the paths
|
||||
# which we will be using later
|
||||
tmp_path = unfrackpath(C.PERSISTENT_CONTROL_PATH_DIR)
|
||||
makedirs_safe(tmp_path)
|
||||
lock_path = unfrackpath("%s/.ansible_pc_lock" % tmp_path)
|
||||
socket_path = unfrackpath(cp % dict(directory=tmp_path))
|
||||
|
||||
# if the socket file doesn't exist, spin up the daemon process
|
||||
lock_fd = os.open(lock_path, os.O_RDWR | os.O_CREAT, 0o600)
|
||||
fcntl.lockf(lock_fd, fcntl.LOCK_EX)
|
||||
|
||||
if not os.path.exists(socket_path):
|
||||
pid = do_fork()
|
||||
if pid == 0:
|
||||
rc = 0
|
||||
try:
|
||||
server = Server(socket_path, pc)
|
||||
except AnsibleConnectionFailure as exc:
|
||||
display.display('connecting to host %s returned an error' % pc.remote_addr, log_only=True)
|
||||
display.display(str(exc), log_only=True)
|
||||
rc = 1
|
||||
except Exception as exc:
|
||||
display.display('failed to create control socket for host %s' % pc.remote_addr, log_only=True)
|
||||
display.display(traceback.format_exc(), log_only=True)
|
||||
rc = 1
|
||||
fcntl.lockf(lock_fd, fcntl.LOCK_UN)
|
||||
os.close(lock_fd)
|
||||
if rc == 0:
|
||||
server.run()
|
||||
sys.exit(rc)
|
||||
else:
|
||||
display.display('re-using existing socket for %s@%s:%s' % (pc.remote_user, pc.remote_addr, pc.port), log_only=True)
|
||||
|
||||
fcntl.lockf(lock_fd, fcntl.LOCK_UN)
|
||||
os.close(lock_fd)
|
||||
|
||||
timeout = pc.timeout
|
||||
while bool(timeout):
|
||||
if os.path.exists(socket_path):
|
||||
display.vvvv('connected to local socket in %s' % (pc.timeout - timeout), pc.remote_addr)
|
||||
break
|
||||
time.sleep(1)
|
||||
timeout -= 1
|
||||
else:
|
||||
raise AnsibleConnectionFailure('timeout waiting for local socket', pc.remote_addr)
|
||||
|
||||
# now connect to the daemon process
|
||||
# FIXME: if the socket file existed but the daemonized process was killed,
|
||||
# the connection will timeout here. Need to make this more resilient.
|
||||
while True:
|
||||
data = stdin.readline()
|
||||
if data == b'':
|
||||
break
|
||||
if data.strip() == b'':
|
||||
continue
|
||||
|
||||
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
||||
|
||||
connect_retry_timeout = C.PERSISTENT_CONNECT_RETRY_TIMEOUT
|
||||
while bool(connect_retry_timeout):
|
||||
try:
|
||||
sock.connect(socket_path)
|
||||
break
|
||||
except socket.error:
|
||||
time.sleep(1)
|
||||
connect_retry_timeout -= 1
|
||||
else:
|
||||
display.display('connect retry timeout expired, unable to connect to control socket', pc.remote_addr, pc.remote_user, log_only=True)
|
||||
display.display('persistent_connect_retry_timeout is %s secs' % (C.PERSISTENT_CONNECT_RETRY_TIMEOUT), pc.remote_addr, pc.remote_user, log_only=True)
|
||||
sys.stderr.write('failed to connect to control socket')
|
||||
sys.exit(255)
|
||||
|
||||
# send the play_context back into the connection so the connection
|
||||
# can handle any privilege escalation activities
|
||||
pc_data = b'CONTEXT: %s' % init_data
|
||||
communicate(sock, pc_data)
|
||||
|
||||
rc, stdout, stderr = communicate(sock, data.strip())
|
||||
|
||||
sys.stdout.write(to_native(stdout))
|
||||
sys.stderr.write(to_native(stderr))
|
||||
|
||||
sock.close()
|
||||
break
|
||||
|
||||
sys.exit(rc)
|
||||
|
||||
if __name__ == '__main__':
|
||||
display = Display()
|
||||
main()
|
||||
@ -1 +1 @@
|
||||
../lib/ansible/cli/console.py
|
||||
ansible
|
||||
@ -1 +1 @@
|
||||
../lib/ansible/cli/doc.py
|
||||
ansible
|
||||
@ -1 +1 @@
|
||||
../lib/ansible/cli/galaxy.py
|
||||
ansible
|
||||
@ -1 +1 @@
|
||||
../lib/ansible/cli/inventory.py
|
||||
ansible
|
||||
@ -1 +1 @@
|
||||
../lib/ansible/cli/playbook.py
|
||||
ansible
|
||||
@ -1 +1 @@
|
||||
../lib/ansible/cli/pull.py
|
||||
ansible
|
||||
@ -1 +0,0 @@
|
||||
../test/lib/ansible_test/_util/target/cli/ansible_test_cli_stub.py
|
||||
@ -1 +1 @@
|
||||
../lib/ansible/cli/vault.py
|
||||
ansible
|
||||
@ -1,8 +0,0 @@
|
||||
Changelogs
|
||||
==========
|
||||
|
||||
As part of the release process a version-specific `CHANGELOG-vX.Y.rst` will be generated from fragments in
|
||||
the `fragments` directory.
|
||||
|
||||
On release branches once a release has been created, consult the branch's version-specific file for changes that have
|
||||
occurred in that branch. The `devel` branch does not have a generated changelog, only changelog fragments.
|
||||
@ -1,2 +0,0 @@
|
||||
ancestor: 2.18.0
|
||||
releases: {}
|
||||
@ -1,22 +0,0 @@
|
||||
---
|
||||
title: ansible-core
|
||||
release_tag_re: '(v(?:[\d.ab\-]|rc)+)'
|
||||
pre_release_tag_re: '(?P<pre_release>(?:[ab]|rc)+\d*)$'
|
||||
changes_file: changelog.yaml
|
||||
changes_format: combined
|
||||
keep_fragments: true
|
||||
always_refresh: true
|
||||
ignore_other_fragment_extensions: true
|
||||
mention_ancestor: false
|
||||
notesdir: fragments
|
||||
prelude_section_name: release_summary
|
||||
new_plugins_after_name: removed_features
|
||||
sections:
|
||||
- ['major_changes', 'Major Changes']
|
||||
- ['minor_changes', 'Minor Changes']
|
||||
- ['breaking_changes', 'Breaking Changes / Porting Guide']
|
||||
- ['deprecated_features', 'Deprecated Features']
|
||||
- ['removed_features', 'Removed Features (previously deprecated)']
|
||||
- ['security_fixes', 'Security Fixes']
|
||||
- ['bugfixes', 'Bugfixes']
|
||||
- ['known_issues', 'Known Issues']
|
||||
@ -1,2 +0,0 @@
|
||||
minor_changes:
|
||||
- ansible-test - Upgrade to ``coverage`` version 7.9.1 for Python 3.9 and later.
|
||||
@ -1,2 +0,0 @@
|
||||
removed_features:
|
||||
- paramiko - Removed the ``PARAMIKO_HOST_KEY_AUTO_ADD`` and ``PARAMIKO_LOOK_FOR_KEYS`` configuration keys, which were previously deprecated.
|
||||
26
contrib/README.md
Normal file
26
contrib/README.md
Normal file
@ -0,0 +1,26 @@
|
||||
contrib
|
||||
-------
|
||||
Files here provide an extension mechanism for Ansible similar to plugins. They are not maintained by the Ansible core team or installed with Ansible.
|
||||
|
||||
|
||||
inventory
|
||||
=========
|
||||
|
||||
Before 2.4 introduced inventory plugins, inventory scripts were the only way to provide sources that were not built into Ansible. Inventory scripts allow you to store your hosts, groups, and variables in any way you like.
|
||||
|
||||
Starting with Ansible version 2.4, they are enabled via the 'script' inventory plugin.
|
||||
Examples of use include discovering inventory from EC2 or pulling it from Cobbler. These could also be used to interface with LDAP or the database.
|
||||
|
||||
`chmod +x` an inventory plugin and either name it `/etc/ansible/hosts` or use `ansible -i /path/to/inventory/script`. You might also need to copy a configuration file with the same name and/or set environment variables. The scripts or configuration files can provide more details.
|
||||
|
||||
vault
|
||||
=====
|
||||
|
||||
If the file passed to `--vault-password-file` has the executable bit set, Ansible will execute it and use the stdout of that execution as 'the secret'.
|
||||
Vault scripts provided here use this facility to retrieve the vault secret from a number of sources.
|
||||
|
||||
contributions welcome
|
||||
=====================
|
||||
|
||||
Send in pull requests to add scripts of your own. The sky is the limit!
|
||||
|
||||
48
contrib/inventory/abiquo.ini
Normal file
48
contrib/inventory/abiquo.ini
Normal file
@ -0,0 +1,48 @@
|
||||
# Ansible external inventory script settings for Abiquo
|
||||
#
|
||||
|
||||
# Define an Abiquo user with access to Abiquo API which will be used to
|
||||
# perform required queries to obtain information to generate the Ansible
|
||||
# inventory output.
|
||||
#
|
||||
[auth]
|
||||
apiuser = admin
|
||||
apipass = xabiquo
|
||||
|
||||
|
||||
# Specify Abiquo API version in major.minor format and the access URI to
|
||||
# API endpoint. Tested versions are: 2.6 , 3.0 and 3.1
|
||||
# To confirm that your box haves access to Abiquo API you can perform a
|
||||
# curl command, replacing with suitable values, similar to this:
|
||||
# curl -X GET https://192.168.2.100/api/login -u admin:xabiquo
|
||||
#
|
||||
[api]
|
||||
version = 3.0
|
||||
uri = https://192.168.2.100/api
|
||||
# You probably won't need to modify login preferences, but just in case
|
||||
login_path = /login
|
||||
login_type = application/vnd.abiquo.user+json
|
||||
|
||||
|
||||
# To avoid performing excessive calls to Abiquo API you can define a
|
||||
# cache for the plugin output. Within the time defined in seconds, latest
|
||||
# output will be reused. After that time, the cache will be refreshed.
|
||||
#
|
||||
[cache]
|
||||
cache_max_age = 30
|
||||
cache_dir = /tmp
|
||||
|
||||
|
||||
[defaults]
|
||||
# Depending in your Abiquo environment, you may want to use only public IP
|
||||
# addresses (if using public cloud providers) or also private IP addresses.
|
||||
# You can set this with public_ip_only configuration.
|
||||
public_ip_only = false
|
||||
# default_net_interface only is used if public_ip_only = false
|
||||
# If public_ip_only is set to false, you can choose default nic to obtain
|
||||
# IP address to define the host.
|
||||
default_net_interface = nic0
|
||||
# Only deployed VM are displayed in the plugin output.
|
||||
deployed_only = true
|
||||
# Define if VM metadata is obtained from Abiquo API.
|
||||
get_metadata = false
|
||||
235
contrib/inventory/abiquo.py
Executable file
235
contrib/inventory/abiquo.py
Executable file
@ -0,0 +1,235 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
'''
|
||||
External inventory script for Abiquo
|
||||
====================================
|
||||
|
||||
Shamelessly copied from an existing inventory script.
|
||||
|
||||
This script generates an inventory that Ansible can understand by making API requests to Abiquo API
|
||||
Requires some python libraries, ensure to have them installed when using this script.
|
||||
|
||||
This script has been tested in Abiquo 3.0 but it may work also for Abiquo 2.6.
|
||||
|
||||
Before using this script you may want to modify abiquo.ini config file.
|
||||
|
||||
This script generates an Ansible hosts file with these host groups:
|
||||
|
||||
ABQ_xxx: Defines a hosts itself by Abiquo VM name label
|
||||
all: Contains all hosts defined in Abiquo user's enterprise
|
||||
virtualdatecenter: Creates a host group for each virtualdatacenter containing all hosts defined on it
|
||||
virtualappliance: Creates a host group for each virtualappliance containing all hosts defined on it
|
||||
imagetemplate: Creates a host group for each image template containing all hosts using it
|
||||
|
||||
'''
|
||||
|
||||
# (c) 2014, Daniel Beneyto <daniel.beneyto@abiquo.com>
|
||||
#
|
||||
# This file is part of Ansible,
|
||||
#
|
||||
# Ansible is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Ansible is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
import ConfigParser
|
||||
|
||||
try:
|
||||
import json
|
||||
except ImportError:
|
||||
import simplejson as json
|
||||
|
||||
from ansible.module_utils.urls import open_url
|
||||
|
||||
|
||||
def api_get(link, config):
|
||||
try:
|
||||
if link is None:
|
||||
url = config.get('api', 'uri') + config.get('api', 'login_path')
|
||||
headers = {"Accept": config.get('api', 'login_type')}
|
||||
else:
|
||||
url = link['href'] + '?limit=0'
|
||||
headers = {"Accept": link['type']}
|
||||
result = open_url(url, headers=headers, url_username=config.get('auth', 'apiuser').replace('\n', ''),
|
||||
url_password=config.get('auth', 'apipass').replace('\n', ''))
|
||||
return json.loads(result.read())
|
||||
except:
|
||||
return None
|
||||
|
||||
|
||||
def save_cache(data, config):
|
||||
''' saves item to cache '''
|
||||
dpath = config.get('cache', 'cache_dir')
|
||||
try:
|
||||
cache = open('/'.join([dpath, 'inventory']), 'w')
|
||||
cache.write(json.dumps(data))
|
||||
cache.close()
|
||||
except IOError as e:
|
||||
pass # not really sure what to do here
|
||||
|
||||
|
||||
def get_cache(cache_item, config):
|
||||
''' returns cached item '''
|
||||
dpath = config.get('cache', 'cache_dir')
|
||||
inv = {}
|
||||
try:
|
||||
cache = open('/'.join([dpath, 'inventory']), 'r')
|
||||
inv = cache.read()
|
||||
cache.close()
|
||||
except IOError as e:
|
||||
pass # not really sure what to do here
|
||||
|
||||
return inv
|
||||
|
||||
|
||||
def cache_available(config):
|
||||
''' checks if we have a 'fresh' cache available for item requested '''
|
||||
|
||||
if config.has_option('cache', 'cache_dir'):
|
||||
dpath = config.get('cache', 'cache_dir')
|
||||
|
||||
try:
|
||||
existing = os.stat('/'.join([dpath, 'inventory']))
|
||||
except:
|
||||
# cache doesn't exist or isn't accessible
|
||||
return False
|
||||
|
||||
if config.has_option('cache', 'cache_max_age'):
|
||||
maxage = config.get('cache', 'cache_max_age')
|
||||
if (int(time.time()) - int(existing.st_mtime)) <= int(maxage):
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
|
||||
def generate_inv_from_api(enterprise_entity, config):
|
||||
try:
|
||||
inventory['all'] = {}
|
||||
inventory['all']['children'] = []
|
||||
inventory['all']['hosts'] = []
|
||||
inventory['_meta'] = {}
|
||||
inventory['_meta']['hostvars'] = {}
|
||||
|
||||
enterprise = api_get(enterprise_entity, config)
|
||||
vms_entity = next(link for link in enterprise['links'] if link['rel'] == 'virtualmachines')
|
||||
vms = api_get(vms_entity, config)
|
||||
for vmcollection in vms['collection']:
|
||||
for link in vmcollection['links']:
|
||||
if link['rel'] == 'virtualappliance':
|
||||
vm_vapp = link['title'].replace('[', '').replace(']', '').replace(' ', '_')
|
||||
elif link['rel'] == 'virtualdatacenter':
|
||||
vm_vdc = link['title'].replace('[', '').replace(']', '').replace(' ', '_')
|
||||
elif link['rel'] == 'virtualmachinetemplate':
|
||||
vm_template = link['title'].replace('[', '').replace(']', '').replace(' ', '_')
|
||||
|
||||
# From abiquo.ini: Only adding to inventory VMs with public IP
|
||||
if config.getboolean('defaults', 'public_ip_only') is True:
|
||||
for link in vmcollection['links']:
|
||||
if link['type'] == 'application/vnd.abiquo.publicip+json' and link['rel'] == 'ip':
|
||||
vm_nic = link['title']
|
||||
break
|
||||
else:
|
||||
vm_nic = None
|
||||
# Otherwise, assigning defined network interface IP address
|
||||
else:
|
||||
for link in vmcollection['links']:
|
||||
if link['rel'] == config.get('defaults', 'default_net_interface'):
|
||||
vm_nic = link['title']
|
||||
break
|
||||
else:
|
||||
vm_nic = None
|
||||
|
||||
vm_state = True
|
||||
# From abiquo.ini: Only adding to inventory VMs deployed
|
||||
if config.getboolean('defaults', 'deployed_only') is True and vmcollection['state'] == 'NOT_ALLOCATED':
|
||||
vm_state = False
|
||||
|
||||
if vm_nic is not None and vm_state:
|
||||
if vm_vapp not in inventory:
|
||||
inventory[vm_vapp] = {}
|
||||
inventory[vm_vapp]['children'] = []
|
||||
inventory[vm_vapp]['hosts'] = []
|
||||
if vm_vdc not in inventory:
|
||||
inventory[vm_vdc] = {}
|
||||
inventory[vm_vdc]['hosts'] = []
|
||||
inventory[vm_vdc]['children'] = []
|
||||
if vm_template not in inventory:
|
||||
inventory[vm_template] = {}
|
||||
inventory[vm_template]['children'] = []
|
||||
inventory[vm_template]['hosts'] = []
|
||||
if config.getboolean('defaults', 'get_metadata') is True:
|
||||
meta_entity = next(link for link in vmcollection['links'] if link['rel'] == 'metadata')
|
||||
try:
|
||||
metadata = api_get(meta_entity, config)
|
||||
if (config.getfloat("api", "version") >= 3.0):
|
||||
vm_metadata = metadata['metadata']
|
||||
else:
|
||||
vm_metadata = metadata['metadata']['metadata']
|
||||
inventory['_meta']['hostvars'][vm_nic] = vm_metadata
|
||||
except Exception as e:
|
||||
pass
|
||||
|
||||
inventory[vm_vapp]['children'].append(vmcollection['name'])
|
||||
inventory[vm_vdc]['children'].append(vmcollection['name'])
|
||||
inventory[vm_template]['children'].append(vmcollection['name'])
|
||||
inventory['all']['children'].append(vmcollection['name'])
|
||||
inventory[vmcollection['name']] = []
|
||||
inventory[vmcollection['name']].append(vm_nic)
|
||||
|
||||
return inventory
|
||||
except Exception as e:
|
||||
# Return empty hosts output
|
||||
return {'all': {'hosts': []}, '_meta': {'hostvars': {}}}
|
||||
|
||||
|
||||
def get_inventory(enterprise, config):
|
||||
''' Reads the inventory from cache or Abiquo api '''
|
||||
|
||||
if cache_available(config):
|
||||
inv = get_cache('inventory', config)
|
||||
else:
|
||||
default_group = os.path.basename(sys.argv[0]).rstrip('.py')
|
||||
# MAKE ABIQUO API CALLS #
|
||||
inv = generate_inv_from_api(enterprise, config)
|
||||
|
||||
save_cache(inv, config)
|
||||
return json.dumps(inv)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
inventory = {}
|
||||
enterprise = {}
|
||||
|
||||
# Read config
|
||||
config = ConfigParser.SafeConfigParser()
|
||||
for configfilename in [os.path.abspath(sys.argv[0]).rstrip('.py') + '.ini', 'abiquo.ini']:
|
||||
if os.path.exists(configfilename):
|
||||
config.read(configfilename)
|
||||
break
|
||||
|
||||
try:
|
||||
login = api_get(None, config)
|
||||
enterprise = next(link for link in login['links'] if link['rel'] == 'enterprise')
|
||||
except Exception as e:
|
||||
enterprise = None
|
||||
|
||||
if cache_available(config):
|
||||
inventory = get_cache('inventory', config)
|
||||
else:
|
||||
inventory = get_inventory(enterprise, config)
|
||||
|
||||
# return to ansible
|
||||
sys.stdout.write(str(inventory))
|
||||
sys.stdout.flush()
|
||||
348
contrib/inventory/apache-libcloud.py
Executable file
348
contrib/inventory/apache-libcloud.py
Executable file
@ -0,0 +1,348 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# (c) 2013, Sebastien Goasguen <runseb@gmail.com>
|
||||
#
|
||||
# This file is part of Ansible,
|
||||
#
|
||||
# Ansible is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Ansible is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
######################################################################
|
||||
|
||||
'''
|
||||
Apache Libcloud generic external inventory script
|
||||
=================================
|
||||
|
||||
Generates inventory that Ansible can understand by making API request to
|
||||
Cloud providers using the Apache libcloud library.
|
||||
|
||||
This script also assumes there is a libcloud.ini file alongside it
|
||||
|
||||
'''
|
||||
|
||||
import sys
|
||||
import os
|
||||
import argparse
|
||||
import re
|
||||
from time import time
|
||||
import ConfigParser
|
||||
|
||||
from six import iteritems, string_types
|
||||
from libcloud.compute.types import Provider
|
||||
from libcloud.compute.providers import get_driver
|
||||
import libcloud.security as sec
|
||||
|
||||
try:
|
||||
import json
|
||||
except ImportError:
|
||||
import simplejson as json
|
||||
|
||||
|
||||
class LibcloudInventory(object):
|
||||
def __init__(self):
|
||||
''' Main execution path '''
|
||||
|
||||
# Inventory grouped by instance IDs, tags, security groups, regions,
|
||||
# and availability zones
|
||||
self.inventory = {}
|
||||
|
||||
# Index of hostname (address) to instance ID
|
||||
self.index = {}
|
||||
|
||||
# Read settings and parse CLI arguments
|
||||
self.read_settings()
|
||||
self.parse_cli_args()
|
||||
|
||||
# Cache
|
||||
if self.args.refresh_cache:
|
||||
self.do_api_calls_update_cache()
|
||||
elif not self.is_cache_valid():
|
||||
self.do_api_calls_update_cache()
|
||||
|
||||
# Data to print
|
||||
if self.args.host:
|
||||
data_to_print = self.get_host_info()
|
||||
|
||||
elif self.args.list:
|
||||
# Display list of instances for inventory
|
||||
if len(self.inventory) == 0:
|
||||
data_to_print = self.get_inventory_from_cache()
|
||||
else:
|
||||
data_to_print = self.json_format_dict(self.inventory, True)
|
||||
|
||||
print(data_to_print)
|
||||
|
||||
def is_cache_valid(self):
|
||||
''' Determines if the cache files have expired, or if it is still valid '''
|
||||
|
||||
if os.path.isfile(self.cache_path_cache):
|
||||
mod_time = os.path.getmtime(self.cache_path_cache)
|
||||
current_time = time()
|
||||
if (mod_time + self.cache_max_age) > current_time:
|
||||
if os.path.isfile(self.cache_path_index):
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
def read_settings(self):
|
||||
''' Reads the settings from the libcloud.ini file '''
|
||||
|
||||
config = ConfigParser.SafeConfigParser()
|
||||
libcloud_default_ini_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'libcloud.ini')
|
||||
libcloud_ini_path = os.environ.get('LIBCLOUD_INI_PATH', libcloud_default_ini_path)
|
||||
config.read(libcloud_ini_path)
|
||||
|
||||
if not config.has_section('driver'):
|
||||
raise ValueError('libcloud.ini file must contain a [driver] section')
|
||||
|
||||
if config.has_option('driver', 'provider'):
|
||||
self.provider = config.get('driver', 'provider')
|
||||
else:
|
||||
raise ValueError('libcloud.ini does not have a provider defined')
|
||||
|
||||
if config.has_option('driver', 'key'):
|
||||
self.key = config.get('driver', 'key')
|
||||
else:
|
||||
raise ValueError('libcloud.ini does not have a key defined')
|
||||
|
||||
if config.has_option('driver', 'secret'):
|
||||
self.secret = config.get('driver', 'secret')
|
||||
else:
|
||||
raise ValueError('libcloud.ini does not have a secret defined')
|
||||
|
||||
if config.has_option('driver', 'host'):
|
||||
self.host = config.get('driver', 'host')
|
||||
if config.has_option('driver', 'secure'):
|
||||
self.secure = config.get('driver', 'secure')
|
||||
if config.has_option('driver', 'verify_ssl_cert'):
|
||||
self.verify_ssl_cert = config.get('driver', 'verify_ssl_cert')
|
||||
if config.has_option('driver', 'port'):
|
||||
self.port = config.get('driver', 'port')
|
||||
if config.has_option('driver', 'path'):
|
||||
self.path = config.get('driver', 'path')
|
||||
if config.has_option('driver', 'api_version'):
|
||||
self.api_version = config.get('driver', 'api_version')
|
||||
|
||||
Driver = get_driver(getattr(Provider, self.provider))
|
||||
|
||||
self.conn = Driver(key=self.key, secret=self.secret, secure=self.secure,
|
||||
host=self.host, path=self.path)
|
||||
|
||||
# Cache related
|
||||
cache_path = config.get('cache', 'cache_path')
|
||||
self.cache_path_cache = cache_path + "/ansible-libcloud.cache"
|
||||
self.cache_path_index = cache_path + "/ansible-libcloud.index"
|
||||
self.cache_max_age = config.getint('cache', 'cache_max_age')
|
||||
|
||||
def parse_cli_args(self):
|
||||
'''
|
||||
Command line argument processing
|
||||
'''
|
||||
|
||||
parser = argparse.ArgumentParser(description='Produce an Ansible Inventory file based on libcloud supported providers')
|
||||
parser.add_argument('--list', action='store_true', default=True,
|
||||
help='List instances (default: True)')
|
||||
parser.add_argument('--host', action='store',
|
||||
help='Get all the variables about a specific instance')
|
||||
parser.add_argument('--refresh-cache', action='store_true', default=False,
|
||||
help='Force refresh of cache by making API requests to libcloud supported providers (default: False - use cache files)')
|
||||
self.args = parser.parse_args()
|
||||
|
||||
def do_api_calls_update_cache(self):
|
||||
'''
|
||||
Do API calls to a location, and save data in cache files
|
||||
'''
|
||||
|
||||
self.get_nodes()
|
||||
|
||||
self.write_to_cache(self.inventory, self.cache_path_cache)
|
||||
self.write_to_cache(self.index, self.cache_path_index)
|
||||
|
||||
def get_nodes(self):
|
||||
'''
|
||||
Gets the list of all nodes
|
||||
'''
|
||||
|
||||
for node in self.conn.list_nodes():
|
||||
self.add_node(node)
|
||||
|
||||
def get_node(self, node_id):
|
||||
'''
|
||||
Gets details about a specific node
|
||||
'''
|
||||
|
||||
return [node for node in self.conn.list_nodes() if node.id == node_id][0]
|
||||
|
||||
def add_node(self, node):
|
||||
'''
|
||||
Adds a node to the inventory and index, as long as it is
|
||||
addressable
|
||||
'''
|
||||
|
||||
# Only want running instances
|
||||
if node.state != 0:
|
||||
return
|
||||
|
||||
# Select the best destination address
|
||||
if not node.public_ips == []:
|
||||
dest = node.public_ips[0]
|
||||
if not dest:
|
||||
# Skip instances we cannot address (e.g. private VPC subnet)
|
||||
return
|
||||
|
||||
# Add to index
|
||||
self.index[dest] = node.name
|
||||
|
||||
# Inventory: Group by instance ID (always a group of 1)
|
||||
self.inventory[node.name] = [dest]
|
||||
'''
|
||||
# Inventory: Group by region
|
||||
self.push(self.inventory, region, dest)
|
||||
|
||||
# Inventory: Group by availability zone
|
||||
self.push(self.inventory, node.placement, dest)
|
||||
|
||||
# Inventory: Group by instance type
|
||||
self.push(self.inventory, self.to_safe('type_' + node.instance_type), dest)
|
||||
'''
|
||||
# Inventory: Group by key pair
|
||||
if node.extra['key_name']:
|
||||
self.push(self.inventory, self.to_safe('key_' + node.extra['key_name']), dest)
|
||||
|
||||
# Inventory: Group by security group, quick thing to handle single sg
|
||||
if node.extra['security_group']:
|
||||
self.push(self.inventory, self.to_safe('sg_' + node.extra['security_group'][0]), dest)
|
||||
|
||||
# Inventory: Group by tag
|
||||
if node.extra['tags']:
|
||||
for tagkey in node.extra['tags'].keys():
|
||||
self.push(self.inventory, self.to_safe('tag_' + tagkey + '_' + node.extra['tags'][tagkey]), dest)
|
||||
|
||||
def get_host_info(self):
|
||||
'''
|
||||
Get variables about a specific host
|
||||
'''
|
||||
|
||||
if len(self.index) == 0:
|
||||
# Need to load index from cache
|
||||
self.load_index_from_cache()
|
||||
|
||||
if self.args.host not in self.index:
|
||||
# try updating the cache
|
||||
self.do_api_calls_update_cache()
|
||||
if self.args.host not in self.index:
|
||||
# host migh not exist anymore
|
||||
return self.json_format_dict({}, True)
|
||||
|
||||
node_id = self.index[self.args.host]
|
||||
|
||||
node = self.get_node(node_id)
|
||||
instance_vars = {}
|
||||
for key, value in vars(node).items():
|
||||
key = self.to_safe('ec2_' + key)
|
||||
|
||||
# Handle complex types
|
||||
if isinstance(value, (int, bool)):
|
||||
instance_vars[key] = value
|
||||
elif isinstance(value, string_types):
|
||||
instance_vars[key] = value.strip()
|
||||
elif value is None:
|
||||
instance_vars[key] = ''
|
||||
elif key == 'ec2_region':
|
||||
instance_vars[key] = value.name
|
||||
elif key == 'ec2_tags':
|
||||
for k, v in iteritems(value):
|
||||
key = self.to_safe('ec2_tag_' + k)
|
||||
instance_vars[key] = v
|
||||
elif key == 'ec2_groups':
|
||||
group_ids = []
|
||||
group_names = []
|
||||
for group in value:
|
||||
group_ids.append(group.id)
|
||||
group_names.append(group.name)
|
||||
instance_vars["ec2_security_group_ids"] = ','.join(group_ids)
|
||||
instance_vars["ec2_security_group_names"] = ','.join(group_names)
|
||||
else:
|
||||
pass
|
||||
# TODO Product codes if someone finds them useful
|
||||
# print(key)
|
||||
# print(type(value))
|
||||
# print(value)
|
||||
|
||||
return self.json_format_dict(instance_vars, True)
|
||||
|
||||
def push(self, my_dict, key, element):
|
||||
'''
|
||||
Pushed an element onto an array that may not have been defined in
|
||||
the dict
|
||||
'''
|
||||
|
||||
if key in my_dict:
|
||||
my_dict[key].append(element)
|
||||
else:
|
||||
my_dict[key] = [element]
|
||||
|
||||
def get_inventory_from_cache(self):
|
||||
'''
|
||||
Reads the inventory from the cache file and returns it as a JSON
|
||||
object
|
||||
'''
|
||||
|
||||
cache = open(self.cache_path_cache, 'r')
|
||||
json_inventory = cache.read()
|
||||
return json_inventory
|
||||
|
||||
def load_index_from_cache(self):
|
||||
'''
|
||||
Reads the index from the cache file sets self.index
|
||||
'''
|
||||
|
||||
cache = open(self.cache_path_index, 'r')
|
||||
json_index = cache.read()
|
||||
self.index = json.loads(json_index)
|
||||
|
||||
def write_to_cache(self, data, filename):
|
||||
'''
|
||||
Writes data in JSON format to a file
|
||||
'''
|
||||
|
||||
json_data = self.json_format_dict(data, True)
|
||||
cache = open(filename, 'w')
|
||||
cache.write(json_data)
|
||||
cache.close()
|
||||
|
||||
def to_safe(self, word):
|
||||
'''
|
||||
Converts 'bad' characters in a string to underscores so they can be
|
||||
used as Ansible groups
|
||||
'''
|
||||
|
||||
return re.sub("[^A-Za-z0-9\-]", "_", word)
|
||||
|
||||
def json_format_dict(self, data, pretty=False):
|
||||
'''
|
||||
Converts a dict to a JSON object and dumps it as a formatted
|
||||
string
|
||||
'''
|
||||
|
||||
if pretty:
|
||||
return json.dumps(data, sort_keys=True, indent=2)
|
||||
else:
|
||||
return json.dumps(data)
|
||||
|
||||
|
||||
def main():
|
||||
LibcloudInventory()
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
20
contrib/inventory/apstra_aos.ini
Normal file
20
contrib/inventory/apstra_aos.ini
Normal file
@ -0,0 +1,20 @@
|
||||
# Ansible Apstra AOS external inventory script settings
|
||||
# Dynamic Inventory script parameter can be provided using this file
|
||||
# Or by using Environment Variables:
|
||||
# - AOS_SERVER, AOS_PORT, AOS_USERNAME, AOS_PASSWORD, AOS_BLUEPRINT
|
||||
#
|
||||
# This file takes precedence over the Environment Variables
|
||||
#
|
||||
|
||||
[aos]
|
||||
|
||||
# aos_server = 172.20.62.3
|
||||
# port = 8888
|
||||
# username = admin
|
||||
# password = admin
|
||||
|
||||
## Blueprint Mode
|
||||
# to use the inventory in mode Blueprint, you need to define the blueprint name you want to use
|
||||
|
||||
# blueprint = my-blueprint-l2
|
||||
# blueprint_interface = true
|
||||
588
contrib/inventory/apstra_aos.py
Executable file
588
contrib/inventory/apstra_aos.py
Executable file
@ -0,0 +1,588 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# (c) 2017 Apstra Inc, <community@apstra.com>
|
||||
#
|
||||
# This file is part of Ansible
|
||||
#
|
||||
# Ansible is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Ansible is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
"""
|
||||
Apstra AOS external inventory script
|
||||
====================================
|
||||
|
||||
Ansible has a feature where instead of reading from /etc/ansible/hosts
|
||||
as a text file, it can query external programs to obtain the list
|
||||
of hosts, groups the hosts are in, and even variables to assign to each host.
|
||||
|
||||
To use this:
|
||||
- copy this file over /etc/ansible/hosts and chmod +x the file.
|
||||
- Copy both files (.py and .ini) in your preferred directory
|
||||
|
||||
More information about Ansible Dynamic Inventory here
|
||||
http://unix.stackexchange.com/questions/205479/in-ansible-dynamic-inventory-json-can-i-render-hostvars-based-on-the-hostname
|
||||
|
||||
2 modes are currently, supported: **device based** or **blueprint based**:
|
||||
- For **Device based**, the list of device is taken from the global device list
|
||||
the serial ID will be used as the inventory_hostname
|
||||
- For **Blueprint based**, the list of device is taken from the given blueprint
|
||||
the Node name will be used as the inventory_hostname
|
||||
|
||||
Input parameters parameter can be provided using either with the ini file or by using Environment Variables:
|
||||
The following list of Environment Variables are supported: AOS_SERVER, AOS_PORT, AOS_USERNAME, AOS_PASSWORD, AOS_BLUEPRINT
|
||||
The config file takes precedence over the Environment Variables
|
||||
|
||||
Tested with Apstra AOS 1.1
|
||||
|
||||
This script has been inspired by the cobbler.py inventory. thanks
|
||||
|
||||
Author: Damien Garros (@dgarros)
|
||||
Version: 0.2.0
|
||||
"""
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
|
||||
try:
|
||||
import argparse
|
||||
HAS_ARGPARSE = True
|
||||
except ImportError:
|
||||
HAS_ARGPARSE = False
|
||||
|
||||
try:
|
||||
from apstra.aosom.session import Session
|
||||
HAS_AOS_PYEZ = True
|
||||
except ImportError:
|
||||
HAS_AOS_PYEZ = False
|
||||
|
||||
from ansible.module_utils.six.moves import configparser
|
||||
|
||||
|
||||
"""
|
||||
##
|
||||
Expected output format in Device mode
|
||||
{
|
||||
"Cumulus": {
|
||||
"hosts": [
|
||||
"52540073956E",
|
||||
"52540022211A"
|
||||
],
|
||||
"vars": {}
|
||||
},
|
||||
"EOS": {
|
||||
"hosts": [
|
||||
"5254001CAFD8",
|
||||
"525400DDDF72"
|
||||
],
|
||||
"vars": {}
|
||||
},
|
||||
"Generic Model": {
|
||||
"hosts": [
|
||||
"525400E5486D"
|
||||
],
|
||||
"vars": {}
|
||||
},
|
||||
"Ubuntu GNU/Linux": {
|
||||
"hosts": [
|
||||
"525400E5486D"
|
||||
],
|
||||
"vars": {}
|
||||
},
|
||||
"VX": {
|
||||
"hosts": [
|
||||
"52540073956E",
|
||||
"52540022211A"
|
||||
],
|
||||
"vars": {}
|
||||
},
|
||||
"_meta": {
|
||||
"hostvars": {
|
||||
"5254001CAFD8": {
|
||||
"agent_start_time": "2017-02-03T00:49:16.000000Z",
|
||||
"ansible_ssh_host": "172.20.52.6",
|
||||
"aos_hcl_model": "Arista_vEOS",
|
||||
"aos_server": "",
|
||||
"aos_version": "AOS_1.1.1_OB.5",
|
||||
"comm_state": "on",
|
||||
"device_start_time": "2017-02-03T00:47:58.454480Z",
|
||||
"domain_name": "",
|
||||
"error_message": "",
|
||||
"fqdn": "localhost",
|
||||
"hostname": "localhost",
|
||||
"hw_model": "vEOS",
|
||||
"hw_version": "",
|
||||
"is_acknowledged": false,
|
||||
"mgmt_ifname": "Management1",
|
||||
"mgmt_ipaddr": "172.20.52.6",
|
||||
"mgmt_macaddr": "52:54:00:1C:AF:D8",
|
||||
"os_arch": "x86_64",
|
||||
"os_family": "EOS",
|
||||
"os_version": "4.16.6M",
|
||||
"os_version_info": {
|
||||
"build": "6M",
|
||||
"major": "4",
|
||||
"minor": "16"
|
||||
},
|
||||
"serial_number": "5254001CAFD8",
|
||||
"state": "OOS-QUARANTINED",
|
||||
"vendor": "Arista"
|
||||
},
|
||||
"52540022211A": {
|
||||
"agent_start_time": "2017-02-03T00:45:22.000000Z",
|
||||
"ansible_ssh_host": "172.20.52.7",
|
||||
"aos_hcl_model": "Cumulus_VX",
|
||||
"aos_server": "172.20.52.3",
|
||||
"aos_version": "AOS_1.1.1_OB.5",
|
||||
"comm_state": "on",
|
||||
"device_start_time": "2017-02-03T00:45:11.019189Z",
|
||||
"domain_name": "",
|
||||
"error_message": "",
|
||||
"fqdn": "cumulus",
|
||||
"hostname": "cumulus",
|
||||
"hw_model": "VX",
|
||||
"hw_version": "",
|
||||
"is_acknowledged": false,
|
||||
"mgmt_ifname": "eth0",
|
||||
"mgmt_ipaddr": "172.20.52.7",
|
||||
"mgmt_macaddr": "52:54:00:22:21:1a",
|
||||
"os_arch": "x86_64",
|
||||
"os_family": "Cumulus",
|
||||
"os_version": "3.1.1",
|
||||
"os_version_info": {
|
||||
"build": "1",
|
||||
"major": "3",
|
||||
"minor": "1"
|
||||
},
|
||||
"serial_number": "52540022211A",
|
||||
"state": "OOS-QUARANTINED",
|
||||
"vendor": "Cumulus"
|
||||
},
|
||||
"52540073956E": {
|
||||
"agent_start_time": "2017-02-03T00:45:19.000000Z",
|
||||
"ansible_ssh_host": "172.20.52.8",
|
||||
"aos_hcl_model": "Cumulus_VX",
|
||||
"aos_server": "172.20.52.3",
|
||||
"aos_version": "AOS_1.1.1_OB.5",
|
||||
"comm_state": "on",
|
||||
"device_start_time": "2017-02-03T00:45:11.030113Z",
|
||||
"domain_name": "",
|
||||
"error_message": "",
|
||||
"fqdn": "cumulus",
|
||||
"hostname": "cumulus",
|
||||
"hw_model": "VX",
|
||||
"hw_version": "",
|
||||
"is_acknowledged": false,
|
||||
"mgmt_ifname": "eth0",
|
||||
"mgmt_ipaddr": "172.20.52.8",
|
||||
"mgmt_macaddr": "52:54:00:73:95:6e",
|
||||
"os_arch": "x86_64",
|
||||
"os_family": "Cumulus",
|
||||
"os_version": "3.1.1",
|
||||
"os_version_info": {
|
||||
"build": "1",
|
||||
"major": "3",
|
||||
"minor": "1"
|
||||
},
|
||||
"serial_number": "52540073956E",
|
||||
"state": "OOS-QUARANTINED",
|
||||
"vendor": "Cumulus"
|
||||
},
|
||||
"525400DDDF72": {
|
||||
"agent_start_time": "2017-02-03T00:49:07.000000Z",
|
||||
"ansible_ssh_host": "172.20.52.5",
|
||||
"aos_hcl_model": "Arista_vEOS",
|
||||
"aos_server": "",
|
||||
"aos_version": "AOS_1.1.1_OB.5",
|
||||
"comm_state": "on",
|
||||
"device_start_time": "2017-02-03T00:47:46.929921Z",
|
||||
"domain_name": "",
|
||||
"error_message": "",
|
||||
"fqdn": "localhost",
|
||||
"hostname": "localhost",
|
||||
"hw_model": "vEOS",
|
||||
"hw_version": "",
|
||||
"is_acknowledged": false,
|
||||
"mgmt_ifname": "Management1",
|
||||
"mgmt_ipaddr": "172.20.52.5",
|
||||
"mgmt_macaddr": "52:54:00:DD:DF:72",
|
||||
"os_arch": "x86_64",
|
||||
"os_family": "EOS",
|
||||
"os_version": "4.16.6M",
|
||||
"os_version_info": {
|
||||
"build": "6M",
|
||||
"major": "4",
|
||||
"minor": "16"
|
||||
},
|
||||
"serial_number": "525400DDDF72",
|
||||
"state": "OOS-QUARANTINED",
|
||||
"vendor": "Arista"
|
||||
},
|
||||
"525400E5486D": {
|
||||
"agent_start_time": "2017-02-02T18:44:42.000000Z",
|
||||
"ansible_ssh_host": "172.20.52.4",
|
||||
"aos_hcl_model": "Generic_Server_1RU_1x10G",
|
||||
"aos_server": "172.20.52.3",
|
||||
"aos_version": "AOS_1.1.1_OB.5",
|
||||
"comm_state": "on",
|
||||
"device_start_time": "2017-02-02T21:11:25.188734Z",
|
||||
"domain_name": "",
|
||||
"error_message": "",
|
||||
"fqdn": "localhost",
|
||||
"hostname": "localhost",
|
||||
"hw_model": "Generic Model",
|
||||
"hw_version": "pc-i440fx-trusty",
|
||||
"is_acknowledged": false,
|
||||
"mgmt_ifname": "eth0",
|
||||
"mgmt_ipaddr": "172.20.52.4",
|
||||
"mgmt_macaddr": "52:54:00:e5:48:6d",
|
||||
"os_arch": "x86_64",
|
||||
"os_family": "Ubuntu GNU/Linux",
|
||||
"os_version": "14.04 LTS",
|
||||
"os_version_info": {
|
||||
"build": "",
|
||||
"major": "14",
|
||||
"minor": "04"
|
||||
},
|
||||
"serial_number": "525400E5486D",
|
||||
"state": "OOS-QUARANTINED",
|
||||
"vendor": "Generic Manufacturer"
|
||||
}
|
||||
}
|
||||
},
|
||||
"all": {
|
||||
"hosts": [
|
||||
"5254001CAFD8",
|
||||
"52540073956E",
|
||||
"525400DDDF72",
|
||||
"525400E5486D",
|
||||
"52540022211A"
|
||||
],
|
||||
"vars": {}
|
||||
},
|
||||
"vEOS": {
|
||||
"hosts": [
|
||||
"5254001CAFD8",
|
||||
"525400DDDF72"
|
||||
],
|
||||
"vars": {}
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
|
||||
def fail(msg):
|
||||
sys.stderr.write("%s\n" % msg)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
class AosInventory(object):
|
||||
|
||||
def __init__(self):
|
||||
|
||||
""" Main execution path """
|
||||
|
||||
if not HAS_AOS_PYEZ:
|
||||
raise Exception('aos-pyez is not installed. Please see details here: https://github.com/Apstra/aos-pyez')
|
||||
if not HAS_ARGPARSE:
|
||||
raise Exception('argparse is not installed. Please install the argparse library or upgrade to python-2.7')
|
||||
|
||||
# Initialize inventory
|
||||
self.inventory = dict() # A list of groups and the hosts in that group
|
||||
self.inventory['_meta'] = dict()
|
||||
self.inventory['_meta']['hostvars'] = dict()
|
||||
|
||||
# Read settings and parse CLI arguments
|
||||
self.read_settings()
|
||||
self.parse_cli_args()
|
||||
|
||||
# ----------------------------------------------------
|
||||
# Open session to AOS
|
||||
# ----------------------------------------------------
|
||||
aos = Session(server=self.aos_server,
|
||||
port=self.aos_server_port,
|
||||
user=self.aos_username,
|
||||
passwd=self.aos_password)
|
||||
|
||||
aos.login()
|
||||
|
||||
# Save session information in variables of group all
|
||||
self.add_var_to_group('all', 'aos_session', aos.session)
|
||||
|
||||
# Add the AOS server itself in the inventory
|
||||
self.add_host_to_group("all", 'aos')
|
||||
self.add_var_to_host("aos", "ansible_ssh_host", self.aos_server)
|
||||
self.add_var_to_host("aos", "ansible_ssh_pass", self.aos_password)
|
||||
self.add_var_to_host("aos", "ansible_ssh_user", self.aos_username)
|
||||
|
||||
# ----------------------------------------------------
|
||||
# Build the inventory
|
||||
# 2 modes are supported: device based or blueprint based
|
||||
# - For device based, the list of device is taken from the global device list
|
||||
# the serial ID will be used as the inventory_hostname
|
||||
# - For Blueprint based, the list of device is taken from the given blueprint
|
||||
# the Node name will be used as the inventory_hostname
|
||||
# ----------------------------------------------------
|
||||
if self.aos_blueprint:
|
||||
|
||||
bp = aos.Blueprints[self.aos_blueprint]
|
||||
if bp.exists is False:
|
||||
fail("Unable to find the Blueprint: %s" % self.aos_blueprint)
|
||||
|
||||
for dev_name, dev_id in bp.params['devices'].value.items():
|
||||
|
||||
self.add_host_to_group('all', dev_name)
|
||||
device = aos.Devices.find(uid=dev_id)
|
||||
|
||||
if 'facts' in device.value.keys():
|
||||
self.add_device_facts_to_var(dev_name, device)
|
||||
|
||||
# Define admin State and Status
|
||||
if 'user_config' in device.value.keys():
|
||||
if 'admin_state' in device.value['user_config'].keys():
|
||||
self.add_var_to_host(dev_name, 'admin_state', device.value['user_config']['admin_state'])
|
||||
|
||||
self.add_device_status_to_var(dev_name, device)
|
||||
|
||||
# Go over the contents data structure
|
||||
for node in bp.contents['system']['nodes']:
|
||||
if node['display_name'] == dev_name:
|
||||
self.add_host_to_group(node['role'], dev_name)
|
||||
|
||||
# Check for additional attribute to import
|
||||
attributes_to_import = [
|
||||
'loopback_ip',
|
||||
'asn',
|
||||
'role',
|
||||
'position',
|
||||
]
|
||||
for attr in attributes_to_import:
|
||||
if attr in node.keys():
|
||||
self.add_var_to_host(dev_name, attr, node[attr])
|
||||
|
||||
# if blueprint_interface is enabled in the configuration
|
||||
# Collect links information
|
||||
if self.aos_blueprint_int:
|
||||
interfaces = dict()
|
||||
|
||||
for link in bp.contents['system']['links']:
|
||||
# each link has 2 sides [0,1], and it's unknown which one match this device
|
||||
# at first we assume, first side match(0) and peer is (1)
|
||||
peer_id = 1
|
||||
|
||||
for side in link['endpoints']:
|
||||
if side['display_name'] == dev_name:
|
||||
|
||||
# import local information first
|
||||
int_name = side['interface']
|
||||
|
||||
# init dict
|
||||
interfaces[int_name] = dict()
|
||||
if 'ip' in side.keys():
|
||||
interfaces[int_name]['ip'] = side['ip']
|
||||
|
||||
if 'interface' in side.keys():
|
||||
interfaces[int_name]['name'] = side['interface']
|
||||
|
||||
if 'display_name' in link['endpoints'][peer_id].keys():
|
||||
interfaces[int_name]['peer'] = link['endpoints'][peer_id]['display_name']
|
||||
|
||||
if 'ip' in link['endpoints'][peer_id].keys():
|
||||
interfaces[int_name]['peer_ip'] = link['endpoints'][peer_id]['ip']
|
||||
|
||||
if 'type' in link['endpoints'][peer_id].keys():
|
||||
interfaces[int_name]['peer_type'] = link['endpoints'][peer_id]['type']
|
||||
|
||||
else:
|
||||
# if we haven't match the first time, prepare the peer_id
|
||||
# for the second loop iteration
|
||||
peer_id = 0
|
||||
|
||||
self.add_var_to_host(dev_name, 'interfaces', interfaces)
|
||||
|
||||
else:
|
||||
for device in aos.Devices:
|
||||
# If not reacheable, create by key and
|
||||
# If reacheable, create by hostname
|
||||
|
||||
self.add_host_to_group('all', device.name)
|
||||
|
||||
# populate information for this host
|
||||
self.add_device_status_to_var(device.name, device)
|
||||
|
||||
if 'user_config' in device.value.keys():
|
||||
for key, value in device.value['user_config'].items():
|
||||
self.add_var_to_host(device.name, key, value)
|
||||
|
||||
# Based on device status online|offline, collect facts as well
|
||||
if device.value['status']['comm_state'] == 'on':
|
||||
|
||||
if 'facts' in device.value.keys():
|
||||
self.add_device_facts_to_var(device.name, device)
|
||||
|
||||
# Check if device is associated with a blueprint
|
||||
# if it's create a new group
|
||||
if 'blueprint_active' in device.value['status'].keys():
|
||||
if 'blueprint_id' in device.value['status'].keys():
|
||||
bp = aos.Blueprints.find(uid=device.value['status']['blueprint_id'])
|
||||
|
||||
if bp:
|
||||
self.add_host_to_group(bp.name, device.name)
|
||||
|
||||
# ----------------------------------------------------
|
||||
# Convert the inventory and return a JSON String
|
||||
# ----------------------------------------------------
|
||||
data_to_print = ""
|
||||
data_to_print += self.json_format_dict(self.inventory, True)
|
||||
|
||||
print(data_to_print)
|
||||
|
||||
def read_settings(self):
|
||||
""" Reads the settings from the apstra_aos.ini file """
|
||||
|
||||
config = configparser.ConfigParser()
|
||||
config.read(os.path.dirname(os.path.realpath(__file__)) + '/apstra_aos.ini')
|
||||
|
||||
# Default Values
|
||||
self.aos_blueprint = False
|
||||
self.aos_blueprint_int = True
|
||||
self.aos_username = 'admin'
|
||||
self.aos_password = 'admin'
|
||||
self.aos_server_port = 8888
|
||||
|
||||
# Try to reach all parameters from File, if not available try from ENV
|
||||
try:
|
||||
self.aos_server = config.get('aos', 'aos_server')
|
||||
except:
|
||||
if 'AOS_SERVER' in os.environ.keys():
|
||||
self.aos_server = os.environ['AOS_SERVER']
|
||||
|
||||
try:
|
||||
self.aos_server_port = config.get('aos', 'port')
|
||||
except:
|
||||
if 'AOS_PORT' in os.environ.keys():
|
||||
self.aos_server_port = os.environ['AOS_PORT']
|
||||
|
||||
try:
|
||||
self.aos_username = config.get('aos', 'username')
|
||||
except:
|
||||
if 'AOS_USERNAME' in os.environ.keys():
|
||||
self.aos_username = os.environ['AOS_USERNAME']
|
||||
|
||||
try:
|
||||
self.aos_password = config.get('aos', 'password')
|
||||
except:
|
||||
if 'AOS_PASSWORD' in os.environ.keys():
|
||||
self.aos_password = os.environ['AOS_PASSWORD']
|
||||
|
||||
try:
|
||||
self.aos_blueprint = config.get('aos', 'blueprint')
|
||||
except:
|
||||
if 'AOS_BLUEPRINT' in os.environ.keys():
|
||||
self.aos_blueprint = os.environ['AOS_BLUEPRINT']
|
||||
|
||||
try:
|
||||
if config.get('aos', 'blueprint_interface') in ['false', 'no']:
|
||||
self.aos_blueprint_int = False
|
||||
except:
|
||||
pass
|
||||
|
||||
def parse_cli_args(self):
|
||||
""" Command line argument processing """
|
||||
|
||||
parser = argparse.ArgumentParser(description='Produce an Ansible Inventory file based on Apstra AOS')
|
||||
parser.add_argument('--list', action='store_true', default=True, help='List instances (default: True)')
|
||||
parser.add_argument('--host', action='store', help='Get all the variables about a specific instance')
|
||||
self.args = parser.parse_args()
|
||||
|
||||
def json_format_dict(self, data, pretty=False):
|
||||
""" Converts a dict to a JSON object and dumps it as a formatted string """
|
||||
|
||||
if pretty:
|
||||
return json.dumps(data, sort_keys=True, indent=2)
|
||||
else:
|
||||
return json.dumps(data)
|
||||
|
||||
def add_host_to_group(self, group, host):
|
||||
|
||||
# Cleanup group name first
|
||||
clean_group = self.cleanup_group_name(group)
|
||||
|
||||
# Check if the group exist, if not initialize it
|
||||
if clean_group not in self.inventory.keys():
|
||||
self.inventory[clean_group] = {}
|
||||
self.inventory[clean_group]['hosts'] = []
|
||||
self.inventory[clean_group]['vars'] = {}
|
||||
|
||||
self.inventory[clean_group]['hosts'].append(host)
|
||||
|
||||
def add_var_to_host(self, host, var, value):
|
||||
|
||||
# Check if the host exist, if not initialize it
|
||||
if host not in self.inventory['_meta']['hostvars'].keys():
|
||||
self.inventory['_meta']['hostvars'][host] = {}
|
||||
|
||||
self.inventory['_meta']['hostvars'][host][var] = value
|
||||
|
||||
def add_var_to_group(self, group, var, value):
|
||||
|
||||
# Cleanup group name first
|
||||
clean_group = self.cleanup_group_name(group)
|
||||
|
||||
# Check if the group exist, if not initialize it
|
||||
if clean_group not in self.inventory.keys():
|
||||
self.inventory[clean_group] = {}
|
||||
self.inventory[clean_group]['hosts'] = []
|
||||
self.inventory[clean_group]['vars'] = {}
|
||||
|
||||
self.inventory[clean_group]['vars'][var] = value
|
||||
|
||||
def add_device_facts_to_var(self, device_name, device):
|
||||
|
||||
# Populate variables for this host
|
||||
self.add_var_to_host(device_name,
|
||||
'ansible_ssh_host',
|
||||
device.value['facts']['mgmt_ipaddr'])
|
||||
|
||||
self.add_var_to_host(device_name, 'id', device.id)
|
||||
|
||||
# self.add_host_to_group('all', device.name)
|
||||
for key, value in device.value['facts'].items():
|
||||
self.add_var_to_host(device_name, key, value)
|
||||
|
||||
if key == 'os_family':
|
||||
self.add_host_to_group(value, device_name)
|
||||
elif key == 'hw_model':
|
||||
self.add_host_to_group(value, device_name)
|
||||
|
||||
def cleanup_group_name(self, group_name):
|
||||
"""
|
||||
Clean up group name by :
|
||||
- Replacing all non-alphanumeric caracter by underscore
|
||||
- Converting to lowercase
|
||||
"""
|
||||
|
||||
rx = re.compile('\W+')
|
||||
clean_group = rx.sub('_', group_name).lower()
|
||||
|
||||
return clean_group
|
||||
|
||||
def add_device_status_to_var(self, device_name, device):
|
||||
|
||||
if 'status' in device.value.keys():
|
||||
for key, value in device.value['status'].items():
|
||||
self.add_var_to_host(device.name, key, value)
|
||||
|
||||
# Run the script
|
||||
if __name__ == '__main__':
|
||||
AosInventory()
|
||||
22
contrib/inventory/azure_rm.ini
Normal file
22
contrib/inventory/azure_rm.ini
Normal file
@ -0,0 +1,22 @@
|
||||
#
|
||||
# Configuration file for azure_rm.py
|
||||
#
|
||||
[azure]
|
||||
# Control which resource groups are included. By default all resources groups are included.
|
||||
# Set resource_groups to a comma separated list of resource groups names.
|
||||
#resource_groups=
|
||||
|
||||
# Control which tags are included. Set tags to a comma separated list of keys or key:value pairs
|
||||
#tags=
|
||||
|
||||
# Control which locations are included. Set locations to a comma separated list (e.g. eastus,eastus2,westus)
|
||||
#locations=
|
||||
|
||||
# Include powerstate. If you don't need powerstate information, turning it off improves runtime performance.
|
||||
include_powerstate=yes
|
||||
|
||||
# Control grouping with the following boolean flags. Valid values: yes, no, true, false, True, False, 0, 1.
|
||||
group_by_resource_group=yes
|
||||
group_by_location=yes
|
||||
group_by_security_group=yes
|
||||
group_by_tag=yes
|
||||
855
contrib/inventory/azure_rm.py
Executable file
855
contrib/inventory/azure_rm.py
Executable file
@ -0,0 +1,855 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright (c) 2016 Matt Davis, <mdavis@ansible.com>
|
||||
# Chris Houseknecht, <house@redhat.com>
|
||||
#
|
||||
# This file is part of Ansible
|
||||
#
|
||||
# Ansible is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Ansible is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
'''
|
||||
Azure External Inventory Script
|
||||
===============================
|
||||
Generates dynamic inventory by making API requests to the Azure Resource
|
||||
Manager using the Azure Python SDK. For instruction on installing the
|
||||
Azure Python SDK see http://azure-sdk-for-python.readthedocs.org/
|
||||
|
||||
Authentication
|
||||
--------------
|
||||
The order of precedence is command line arguments, environment variables,
|
||||
and finally the [default] profile found in ~/.azure/credentials.
|
||||
|
||||
If using a credentials file, it should be an ini formatted file with one or
|
||||
more sections, which we refer to as profiles. The script looks for a
|
||||
[default] section, if a profile is not specified either on the command line
|
||||
or with an environment variable. The keys in a profile will match the
|
||||
list of command line arguments below.
|
||||
|
||||
For command line arguments and environment variables specify a profile found
|
||||
in your ~/.azure/credentials file, or a service principal or Active Directory
|
||||
user.
|
||||
|
||||
Command line arguments:
|
||||
- profile
|
||||
- client_id
|
||||
- secret
|
||||
- subscription_id
|
||||
- tenant
|
||||
- ad_user
|
||||
- password
|
||||
- cloud_environment
|
||||
|
||||
Environment variables:
|
||||
- AZURE_PROFILE
|
||||
- AZURE_CLIENT_ID
|
||||
- AZURE_SECRET
|
||||
- AZURE_SUBSCRIPTION_ID
|
||||
- AZURE_TENANT
|
||||
- AZURE_AD_USER
|
||||
- AZURE_PASSWORD
|
||||
- AZURE_CLOUD_ENVIRONMENT
|
||||
|
||||
Run for Specific Host
|
||||
-----------------------
|
||||
When run for a specific host using the --host option, a resource group is
|
||||
required. For a specific host, this script returns the following variables:
|
||||
|
||||
{
|
||||
"ansible_host": "XXX.XXX.XXX.XXX",
|
||||
"computer_name": "computer_name2",
|
||||
"fqdn": null,
|
||||
"id": "/subscriptions/subscription-id/resourceGroups/galaxy-production/providers/Microsoft.Compute/virtualMachines/object-name",
|
||||
"image": {
|
||||
"offer": "CentOS",
|
||||
"publisher": "OpenLogic",
|
||||
"sku": "7.1",
|
||||
"version": "latest"
|
||||
},
|
||||
"location": "westus",
|
||||
"mac_address": "00-00-5E-00-53-FE",
|
||||
"name": "object-name",
|
||||
"network_interface": "interface-name",
|
||||
"network_interface_id": "/subscriptions/subscription-id/resourceGroups/galaxy-production/providers/Microsoft.Network/networkInterfaces/object-name1",
|
||||
"network_security_group": null,
|
||||
"network_security_group_id": null,
|
||||
"os_disk": {
|
||||
"name": "object-name",
|
||||
"operating_system_type": "Linux"
|
||||
},
|
||||
"plan": null,
|
||||
"powerstate": "running",
|
||||
"private_ip": "172.26.3.6",
|
||||
"private_ip_alloc_method": "Static",
|
||||
"provisioning_state": "Succeeded",
|
||||
"public_ip": "XXX.XXX.XXX.XXX",
|
||||
"public_ip_alloc_method": "Static",
|
||||
"public_ip_id": "/subscriptions/subscription-id/resourceGroups/galaxy-production/providers/Microsoft.Network/publicIPAddresses/object-name",
|
||||
"public_ip_name": "object-name",
|
||||
"resource_group": "galaxy-production",
|
||||
"security_group": "object-name",
|
||||
"security_group_id": "/subscriptions/subscription-id/resourceGroups/galaxy-production/providers/Microsoft.Network/networkSecurityGroups/object-name",
|
||||
"tags": {
|
||||
"db": "database"
|
||||
},
|
||||
"type": "Microsoft.Compute/virtualMachines",
|
||||
"virtual_machine_size": "Standard_DS4"
|
||||
}
|
||||
|
||||
Groups
|
||||
------
|
||||
When run in --list mode, instances are grouped by the following categories:
|
||||
- azure
|
||||
- location
|
||||
- resource_group
|
||||
- security_group
|
||||
- tag key
|
||||
- tag key_value
|
||||
|
||||
Control groups using azure_rm.ini or set environment variables:
|
||||
|
||||
AZURE_GROUP_BY_RESOURCE_GROUP=yes
|
||||
AZURE_GROUP_BY_LOCATION=yes
|
||||
AZURE_GROUP_BY_SECURITY_GROUP=yes
|
||||
AZURE_GROUP_BY_TAG=yes
|
||||
|
||||
Select hosts within specific resource groups by assigning a comma separated list to:
|
||||
|
||||
AZURE_RESOURCE_GROUPS=resource_group_a,resource_group_b
|
||||
|
||||
Select hosts for specific tag key by assigning a comma separated list of tag keys to:
|
||||
|
||||
AZURE_TAGS=key1,key2,key3
|
||||
|
||||
Select hosts for specific locations:
|
||||
|
||||
AZURE_LOCATIONS=eastus,westus,eastus2
|
||||
|
||||
Or, select hosts for specific tag key:value pairs by assigning a comma separated list key:value pairs to:
|
||||
|
||||
AZURE_TAGS=key1:value1,key2:value2
|
||||
|
||||
If you don't need the powerstate, you can improve performance by turning off powerstate fetching:
|
||||
AZURE_INCLUDE_POWERSTATE=no
|
||||
|
||||
azure_rm.ini
|
||||
------------
|
||||
As mentioned above, you can control execution using environment variables or a .ini file. A sample
|
||||
azure_rm.ini is included. The name of the .ini file is the basename of the inventory script (in this case
|
||||
'azure_rm') with a .ini extension. It also assumes the .ini file is alongside the script. To specify
|
||||
a different path for the .ini file, define the AZURE_INI_PATH environment variable:
|
||||
|
||||
export AZURE_INI_PATH=/path/to/custom.ini
|
||||
|
||||
Powerstate:
|
||||
-----------
|
||||
The powerstate attribute indicates whether or not a host is running. If the value is 'running', the machine is
|
||||
up. If the value is anything other than 'running', the machine is down, and will be unreachable.
|
||||
|
||||
Examples:
|
||||
---------
|
||||
Execute /bin/uname on all instances in the galaxy-qa resource group
|
||||
$ ansible -i azure_rm.py galaxy-qa -m shell -a "/bin/uname -a"
|
||||
|
||||
Use the inventory script to print instance specific information
|
||||
$ contrib/inventory/azure_rm.py --host my_instance_host_name --pretty
|
||||
|
||||
Use with a playbook
|
||||
$ ansible-playbook -i contrib/inventory/azure_rm.py my_playbook.yml --limit galaxy-qa
|
||||
|
||||
|
||||
Insecure Platform Warning
|
||||
-------------------------
|
||||
If you receive InsecurePlatformWarning from urllib3, install the
|
||||
requests security packages:
|
||||
|
||||
pip install requests[security]
|
||||
|
||||
|
||||
author:
|
||||
- Chris Houseknecht (@chouseknecht)
|
||||
- Matt Davis (@nitzmahone)
|
||||
|
||||
Company: Ansible by Red Hat
|
||||
|
||||
Version: 1.0.0
|
||||
'''
|
||||
|
||||
import argparse
|
||||
import ConfigParser
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
import inspect
|
||||
import traceback
|
||||
|
||||
|
||||
from packaging.version import Version
|
||||
|
||||
from os.path import expanduser
|
||||
import ansible.module_utils.six.moves.urllib.parse as urlparse
|
||||
|
||||
HAS_AZURE = True
|
||||
HAS_AZURE_EXC = None
|
||||
|
||||
try:
|
||||
from msrestazure.azure_exceptions import CloudError
|
||||
from msrestazure import azure_cloud
|
||||
from azure.mgmt.compute import __version__ as azure_compute_version
|
||||
from azure.common import AzureMissingResourceHttpError, AzureHttpError
|
||||
from azure.common.credentials import ServicePrincipalCredentials, UserPassCredentials
|
||||
from azure.mgmt.network import NetworkManagementClient
|
||||
from azure.mgmt.resource.resources import ResourceManagementClient
|
||||
from azure.mgmt.compute import ComputeManagementClient
|
||||
except ImportError as exc:
|
||||
HAS_AZURE_EXC = exc
|
||||
HAS_AZURE = False
|
||||
|
||||
|
||||
AZURE_CREDENTIAL_ENV_MAPPING = dict(
|
||||
profile='AZURE_PROFILE',
|
||||
subscription_id='AZURE_SUBSCRIPTION_ID',
|
||||
client_id='AZURE_CLIENT_ID',
|
||||
secret='AZURE_SECRET',
|
||||
tenant='AZURE_TENANT',
|
||||
ad_user='AZURE_AD_USER',
|
||||
password='AZURE_PASSWORD',
|
||||
cloud_environment='AZURE_CLOUD_ENVIRONMENT',
|
||||
)
|
||||
|
||||
AZURE_CONFIG_SETTINGS = dict(
|
||||
resource_groups='AZURE_RESOURCE_GROUPS',
|
||||
tags='AZURE_TAGS',
|
||||
locations='AZURE_LOCATIONS',
|
||||
include_powerstate='AZURE_INCLUDE_POWERSTATE',
|
||||
group_by_resource_group='AZURE_GROUP_BY_RESOURCE_GROUP',
|
||||
group_by_location='AZURE_GROUP_BY_LOCATION',
|
||||
group_by_security_group='AZURE_GROUP_BY_SECURITY_GROUP',
|
||||
group_by_tag='AZURE_GROUP_BY_TAG'
|
||||
)
|
||||
|
||||
AZURE_MIN_VERSION = "2.0.0"
|
||||
|
||||
|
||||
def azure_id_to_dict(id):
|
||||
pieces = re.sub(r'^\/', '', id).split('/')
|
||||
result = {}
|
||||
index = 0
|
||||
while index < len(pieces) - 1:
|
||||
result[pieces[index]] = pieces[index + 1]
|
||||
index += 1
|
||||
return result
|
||||
|
||||
|
||||
class AzureRM(object):
|
||||
|
||||
def __init__(self, args):
|
||||
self._args = args
|
||||
self._cloud_environment = None
|
||||
self._compute_client = None
|
||||
self._resource_client = None
|
||||
self._network_client = None
|
||||
|
||||
self.debug = False
|
||||
if args.debug:
|
||||
self.debug = True
|
||||
|
||||
self.credentials = self._get_credentials(args)
|
||||
if not self.credentials:
|
||||
self.fail("Failed to get credentials. Either pass as parameters, set environment variables, "
|
||||
"or define a profile in ~/.azure/credentials.")
|
||||
|
||||
# if cloud_environment specified, look up/build Cloud object
|
||||
raw_cloud_env = self.credentials.get('cloud_environment')
|
||||
if not raw_cloud_env:
|
||||
self._cloud_environment = azure_cloud.AZURE_PUBLIC_CLOUD # SDK default
|
||||
else:
|
||||
# try to look up "well-known" values via the name attribute on azure_cloud members
|
||||
all_clouds = [x[1] for x in inspect.getmembers(azure_cloud) if isinstance(x[1], azure_cloud.Cloud)]
|
||||
matched_clouds = [x for x in all_clouds if x.name == raw_cloud_env]
|
||||
if len(matched_clouds) == 1:
|
||||
self._cloud_environment = matched_clouds[0]
|
||||
elif len(matched_clouds) > 1:
|
||||
self.fail("Azure SDK failure: more than one cloud matched for cloud_environment name '{0}'".format(raw_cloud_env))
|
||||
else:
|
||||
if not urlparse.urlparse(raw_cloud_env).scheme:
|
||||
self.fail("cloud_environment must be an endpoint discovery URL or one of {0}".format([x.name for x in all_clouds]))
|
||||
try:
|
||||
self._cloud_environment = azure_cloud.get_cloud_from_metadata_endpoint(raw_cloud_env)
|
||||
except Exception as e:
|
||||
self.fail("cloud_environment {0} could not be resolved: {1}".format(raw_cloud_env, e.message))
|
||||
|
||||
if self.credentials.get('subscription_id', None) is None:
|
||||
self.fail("Credentials did not include a subscription_id value.")
|
||||
self.log("setting subscription_id")
|
||||
self.subscription_id = self.credentials['subscription_id']
|
||||
|
||||
if self.credentials.get('client_id') is not None and \
|
||||
self.credentials.get('secret') is not None and \
|
||||
self.credentials.get('tenant') is not None:
|
||||
self.azure_credentials = ServicePrincipalCredentials(client_id=self.credentials['client_id'],
|
||||
secret=self.credentials['secret'],
|
||||
tenant=self.credentials['tenant'],
|
||||
cloud_environment=self._cloud_environment)
|
||||
elif self.credentials.get('ad_user') is not None and self.credentials.get('password') is not None:
|
||||
tenant = self.credentials.get('tenant')
|
||||
if not tenant:
|
||||
tenant = 'common'
|
||||
self.azure_credentials = UserPassCredentials(self.credentials['ad_user'],
|
||||
self.credentials['password'],
|
||||
tenant=tenant,
|
||||
cloud_environment=self._cloud_environment)
|
||||
else:
|
||||
self.fail("Failed to authenticate with provided credentials. Some attributes were missing. "
|
||||
"Credentials must include client_id, secret and tenant or ad_user and password.")
|
||||
|
||||
def log(self, msg):
|
||||
if self.debug:
|
||||
print(msg + u'\n')
|
||||
|
||||
def fail(self, msg):
|
||||
raise Exception(msg)
|
||||
|
||||
def _get_profile(self, profile="default"):
|
||||
path = expanduser("~")
|
||||
path += "/.azure/credentials"
|
||||
try:
|
||||
config = ConfigParser.ConfigParser()
|
||||
config.read(path)
|
||||
except Exception as exc:
|
||||
self.fail("Failed to access {0}. Check that the file exists and you have read "
|
||||
"access. {1}".format(path, str(exc)))
|
||||
credentials = dict()
|
||||
for key in AZURE_CREDENTIAL_ENV_MAPPING:
|
||||
try:
|
||||
credentials[key] = config.get(profile, key, raw=True)
|
||||
except:
|
||||
pass
|
||||
|
||||
if credentials.get('client_id') is not None or credentials.get('ad_user') is not None:
|
||||
return credentials
|
||||
|
||||
return None
|
||||
|
||||
def _get_env_credentials(self):
|
||||
env_credentials = dict()
|
||||
for attribute, env_variable in AZURE_CREDENTIAL_ENV_MAPPING.items():
|
||||
env_credentials[attribute] = os.environ.get(env_variable, None)
|
||||
|
||||
if env_credentials['profile'] is not None:
|
||||
credentials = self._get_profile(env_credentials['profile'])
|
||||
return credentials
|
||||
|
||||
if env_credentials['client_id'] is not None or env_credentials['ad_user'] is not None:
|
||||
return env_credentials
|
||||
|
||||
return None
|
||||
|
||||
def _get_credentials(self, params):
|
||||
# Get authentication credentials.
|
||||
# Precedence: cmd line parameters-> environment variables-> default profile in ~/.azure/credentials.
|
||||
|
||||
self.log('Getting credentials')
|
||||
|
||||
arg_credentials = dict()
|
||||
for attribute, env_variable in AZURE_CREDENTIAL_ENV_MAPPING.items():
|
||||
arg_credentials[attribute] = getattr(params, attribute)
|
||||
|
||||
# try module params
|
||||
if arg_credentials['profile'] is not None:
|
||||
self.log('Retrieving credentials with profile parameter.')
|
||||
credentials = self._get_profile(arg_credentials['profile'])
|
||||
return credentials
|
||||
|
||||
if arg_credentials['client_id'] is not None:
|
||||
self.log('Received credentials from parameters.')
|
||||
return arg_credentials
|
||||
|
||||
if arg_credentials['ad_user'] is not None:
|
||||
self.log('Received credentials from parameters.')
|
||||
return arg_credentials
|
||||
|
||||
# try environment
|
||||
env_credentials = self._get_env_credentials()
|
||||
if env_credentials:
|
||||
self.log('Received credentials from env.')
|
||||
return env_credentials
|
||||
|
||||
# try default profile from ~./azure/credentials
|
||||
default_credentials = self._get_profile()
|
||||
if default_credentials:
|
||||
self.log('Retrieved default profile credentials from ~/.azure/credentials.')
|
||||
return default_credentials
|
||||
|
||||
return None
|
||||
|
||||
def _register(self, key):
|
||||
try:
|
||||
# We have to perform the one-time registration here. Otherwise, we receive an error the first
|
||||
# time we attempt to use the requested client.
|
||||
resource_client = self.rm_client
|
||||
resource_client.providers.register(key)
|
||||
except Exception as exc:
|
||||
self.log("One-time registration of {0} failed - {1}".format(key, str(exc)))
|
||||
self.log("You might need to register {0} using an admin account".format(key))
|
||||
self.log(("To register a provider using the Python CLI: "
|
||||
"https://docs.microsoft.com/azure/azure-resource-manager/"
|
||||
"resource-manager-common-deployment-errors#noregisteredproviderfound"))
|
||||
|
||||
@property
|
||||
def network_client(self):
|
||||
self.log('Getting network client')
|
||||
if not self._network_client:
|
||||
self._network_client = NetworkManagementClient(
|
||||
self.azure_credentials,
|
||||
self.subscription_id,
|
||||
base_url=self._cloud_environment.endpoints.resource_manager,
|
||||
api_version='2017-06-01'
|
||||
)
|
||||
self._register('Microsoft.Network')
|
||||
return self._network_client
|
||||
|
||||
@property
|
||||
def rm_client(self):
|
||||
self.log('Getting resource manager client')
|
||||
if not self._resource_client:
|
||||
self._resource_client = ResourceManagementClient(
|
||||
self.azure_credentials,
|
||||
self.subscription_id,
|
||||
base_url=self._cloud_environment.endpoints.resource_manager,
|
||||
api_version='2017-05-10'
|
||||
)
|
||||
return self._resource_client
|
||||
|
||||
@property
|
||||
def compute_client(self):
|
||||
self.log('Getting compute client')
|
||||
if not self._compute_client:
|
||||
self._compute_client = ComputeManagementClient(
|
||||
self.azure_credentials,
|
||||
self.subscription_id,
|
||||
base_url=self._cloud_environment.endpoints.resource_manager,
|
||||
api_version='2017-03-30'
|
||||
)
|
||||
self._register('Microsoft.Compute')
|
||||
return self._compute_client
|
||||
|
||||
|
||||
class AzureInventory(object):
|
||||
|
||||
def __init__(self):
|
||||
|
||||
self._args = self._parse_cli_args()
|
||||
|
||||
try:
|
||||
rm = AzureRM(self._args)
|
||||
except Exception as e:
|
||||
sys.exit("{0}".format(str(e)))
|
||||
|
||||
self._compute_client = rm.compute_client
|
||||
self._network_client = rm.network_client
|
||||
self._resource_client = rm.rm_client
|
||||
self._security_groups = None
|
||||
|
||||
self.resource_groups = []
|
||||
self.tags = None
|
||||
self.locations = None
|
||||
self.replace_dash_in_groups = False
|
||||
self.group_by_resource_group = True
|
||||
self.group_by_location = True
|
||||
self.group_by_security_group = True
|
||||
self.group_by_tag = True
|
||||
self.include_powerstate = True
|
||||
|
||||
self._inventory = dict(
|
||||
_meta=dict(
|
||||
hostvars=dict()
|
||||
),
|
||||
azure=[]
|
||||
)
|
||||
|
||||
self._get_settings()
|
||||
|
||||
if self._args.resource_groups:
|
||||
self.resource_groups = self._args.resource_groups.split(',')
|
||||
|
||||
if self._args.tags:
|
||||
self.tags = self._args.tags.split(',')
|
||||
|
||||
if self._args.locations:
|
||||
self.locations = self._args.locations.split(',')
|
||||
|
||||
if self._args.no_powerstate:
|
||||
self.include_powerstate = False
|
||||
|
||||
self.get_inventory()
|
||||
print(self._json_format_dict(pretty=self._args.pretty))
|
||||
sys.exit(0)
|
||||
|
||||
def _parse_cli_args(self):
|
||||
# Parse command line arguments
|
||||
parser = argparse.ArgumentParser(
|
||||
description='Produce an Ansible Inventory file for an Azure subscription')
|
||||
parser.add_argument('--list', action='store_true', default=True,
|
||||
help='List instances (default: True)')
|
||||
parser.add_argument('--debug', action='store_true', default=False,
|
||||
help='Send debug messages to STDOUT')
|
||||
parser.add_argument('--host', action='store',
|
||||
help='Get all information about an instance')
|
||||
parser.add_argument('--pretty', action='store_true', default=False,
|
||||
help='Pretty print JSON output(default: False)')
|
||||
parser.add_argument('--profile', action='store',
|
||||
help='Azure profile contained in ~/.azure/credentials')
|
||||
parser.add_argument('--subscription_id', action='store',
|
||||
help='Azure Subscription Id')
|
||||
parser.add_argument('--client_id', action='store',
|
||||
help='Azure Client Id ')
|
||||
parser.add_argument('--secret', action='store',
|
||||
help='Azure Client Secret')
|
||||
parser.add_argument('--tenant', action='store',
|
||||
help='Azure Tenant Id')
|
||||
parser.add_argument('--ad_user', action='store',
|
||||
help='Active Directory User')
|
||||
parser.add_argument('--password', action='store',
|
||||
help='password')
|
||||
parser.add_argument('--cloud_environment', action='store',
|
||||
help='Azure Cloud Environment name or metadata discovery URL')
|
||||
parser.add_argument('--resource-groups', action='store',
|
||||
help='Return inventory for comma separated list of resource group names')
|
||||
parser.add_argument('--tags', action='store',
|
||||
help='Return inventory for comma separated list of tag key:value pairs')
|
||||
parser.add_argument('--locations', action='store',
|
||||
help='Return inventory for comma separated list of locations')
|
||||
parser.add_argument('--no-powerstate', action='store_true', default=False,
|
||||
help='Do not include the power state of each virtual host')
|
||||
return parser.parse_args()
|
||||
|
||||
def get_inventory(self):
|
||||
if len(self.resource_groups) > 0:
|
||||
# get VMs for requested resource groups
|
||||
for resource_group in self.resource_groups:
|
||||
try:
|
||||
virtual_machines = self._compute_client.virtual_machines.list(resource_group)
|
||||
except Exception as exc:
|
||||
sys.exit("Error: fetching virtual machines for resource group {0} - {1}".format(resource_group, str(exc)))
|
||||
if self._args.host or self.tags:
|
||||
selected_machines = self._selected_machines(virtual_machines)
|
||||
self._load_machines(selected_machines)
|
||||
else:
|
||||
self._load_machines(virtual_machines)
|
||||
else:
|
||||
# get all VMs within the subscription
|
||||
try:
|
||||
virtual_machines = self._compute_client.virtual_machines.list_all()
|
||||
except Exception as exc:
|
||||
sys.exit("Error: fetching virtual machines - {0}".format(str(exc)))
|
||||
|
||||
if self._args.host or self.tags or self.locations:
|
||||
selected_machines = self._selected_machines(virtual_machines)
|
||||
self._load_machines(selected_machines)
|
||||
else:
|
||||
self._load_machines(virtual_machines)
|
||||
|
||||
def _load_machines(self, machines):
|
||||
for machine in machines:
|
||||
id_dict = azure_id_to_dict(machine.id)
|
||||
|
||||
# TODO - The API is returning an ID value containing resource group name in ALL CAPS. If/when it gets
|
||||
# fixed, we should remove the .lower(). Opened Issue
|
||||
# #574: https://github.com/Azure/azure-sdk-for-python/issues/574
|
||||
resource_group = id_dict['resourceGroups'].lower()
|
||||
|
||||
if self.group_by_security_group:
|
||||
self._get_security_groups(resource_group)
|
||||
|
||||
host_vars = dict(
|
||||
ansible_host=None,
|
||||
private_ip=None,
|
||||
private_ip_alloc_method=None,
|
||||
public_ip=None,
|
||||
public_ip_name=None,
|
||||
public_ip_id=None,
|
||||
public_ip_alloc_method=None,
|
||||
fqdn=None,
|
||||
location=machine.location,
|
||||
name=machine.name,
|
||||
type=machine.type,
|
||||
id=machine.id,
|
||||
tags=machine.tags,
|
||||
network_interface_id=None,
|
||||
network_interface=None,
|
||||
resource_group=resource_group,
|
||||
mac_address=None,
|
||||
plan=(machine.plan.name if machine.plan else None),
|
||||
virtual_machine_size=machine.hardware_profile.vm_size,
|
||||
computer_name=(machine.os_profile.computer_name if machine.os_profile else None),
|
||||
provisioning_state=machine.provisioning_state,
|
||||
)
|
||||
|
||||
host_vars['os_disk'] = dict(
|
||||
name=machine.storage_profile.os_disk.name,
|
||||
operating_system_type=machine.storage_profile.os_disk.os_type.value
|
||||
)
|
||||
|
||||
if self.include_powerstate:
|
||||
host_vars['powerstate'] = self._get_powerstate(resource_group, machine.name)
|
||||
|
||||
if machine.storage_profile.image_reference:
|
||||
host_vars['image'] = dict(
|
||||
offer=machine.storage_profile.image_reference.offer,
|
||||
publisher=machine.storage_profile.image_reference.publisher,
|
||||
sku=machine.storage_profile.image_reference.sku,
|
||||
version=machine.storage_profile.image_reference.version
|
||||
)
|
||||
|
||||
# Add windows details
|
||||
if machine.os_profile is not None and machine.os_profile.windows_configuration is not None:
|
||||
host_vars['windows_auto_updates_enabled'] = \
|
||||
machine.os_profile.windows_configuration.enable_automatic_updates
|
||||
host_vars['windows_timezone'] = machine.os_profile.windows_configuration.time_zone
|
||||
host_vars['windows_rm'] = None
|
||||
if machine.os_profile.windows_configuration.win_rm is not None:
|
||||
host_vars['windows_rm'] = dict(listeners=None)
|
||||
if machine.os_profile.windows_configuration.win_rm.listeners is not None:
|
||||
host_vars['windows_rm']['listeners'] = []
|
||||
for listener in machine.os_profile.windows_configuration.win_rm.listeners:
|
||||
host_vars['windows_rm']['listeners'].append(dict(protocol=listener.protocol,
|
||||
certificate_url=listener.certificate_url))
|
||||
|
||||
for interface in machine.network_profile.network_interfaces:
|
||||
interface_reference = self._parse_ref_id(interface.id)
|
||||
network_interface = self._network_client.network_interfaces.get(
|
||||
interface_reference['resourceGroups'],
|
||||
interface_reference['networkInterfaces'])
|
||||
if network_interface.primary:
|
||||
if self.group_by_security_group and \
|
||||
self._security_groups[resource_group].get(network_interface.id, None):
|
||||
host_vars['security_group'] = \
|
||||
self._security_groups[resource_group][network_interface.id]['name']
|
||||
host_vars['security_group_id'] = \
|
||||
self._security_groups[resource_group][network_interface.id]['id']
|
||||
host_vars['network_interface'] = network_interface.name
|
||||
host_vars['network_interface_id'] = network_interface.id
|
||||
host_vars['mac_address'] = network_interface.mac_address
|
||||
for ip_config in network_interface.ip_configurations:
|
||||
host_vars['private_ip'] = ip_config.private_ip_address
|
||||
host_vars['private_ip_alloc_method'] = ip_config.private_ip_allocation_method
|
||||
if ip_config.public_ip_address:
|
||||
public_ip_reference = self._parse_ref_id(ip_config.public_ip_address.id)
|
||||
public_ip_address = self._network_client.public_ip_addresses.get(
|
||||
public_ip_reference['resourceGroups'],
|
||||
public_ip_reference['publicIPAddresses'])
|
||||
host_vars['ansible_host'] = public_ip_address.ip_address
|
||||
host_vars['public_ip'] = public_ip_address.ip_address
|
||||
host_vars['public_ip_name'] = public_ip_address.name
|
||||
host_vars['public_ip_alloc_method'] = public_ip_address.public_ip_allocation_method
|
||||
host_vars['public_ip_id'] = public_ip_address.id
|
||||
if public_ip_address.dns_settings:
|
||||
host_vars['fqdn'] = public_ip_address.dns_settings.fqdn
|
||||
|
||||
self._add_host(host_vars)
|
||||
|
||||
def _selected_machines(self, virtual_machines):
|
||||
selected_machines = []
|
||||
for machine in virtual_machines:
|
||||
if self._args.host and self._args.host == machine.name:
|
||||
selected_machines.append(machine)
|
||||
if self.tags and self._tags_match(machine.tags, self.tags):
|
||||
selected_machines.append(machine)
|
||||
if self.locations and machine.location in self.locations:
|
||||
selected_machines.append(machine)
|
||||
return selected_machines
|
||||
|
||||
def _get_security_groups(self, resource_group):
|
||||
''' For a given resource_group build a mapping of network_interface.id to security_group name '''
|
||||
if not self._security_groups:
|
||||
self._security_groups = dict()
|
||||
if not self._security_groups.get(resource_group):
|
||||
self._security_groups[resource_group] = dict()
|
||||
for group in self._network_client.network_security_groups.list(resource_group):
|
||||
if group.network_interfaces:
|
||||
for interface in group.network_interfaces:
|
||||
self._security_groups[resource_group][interface.id] = dict(
|
||||
name=group.name,
|
||||
id=group.id
|
||||
)
|
||||
|
||||
def _get_powerstate(self, resource_group, name):
|
||||
try:
|
||||
vm = self._compute_client.virtual_machines.get(resource_group,
|
||||
name,
|
||||
expand='instanceview')
|
||||
except Exception as exc:
|
||||
sys.exit("Error: fetching instanceview for host {0} - {1}".format(name, str(exc)))
|
||||
|
||||
return next((s.code.replace('PowerState/', '')
|
||||
for s in vm.instance_view.statuses if s.code.startswith('PowerState')), None)
|
||||
|
||||
def _add_host(self, vars):
|
||||
|
||||
host_name = self._to_safe(vars['name'])
|
||||
resource_group = self._to_safe(vars['resource_group'])
|
||||
security_group = None
|
||||
if vars.get('security_group'):
|
||||
security_group = self._to_safe(vars['security_group'])
|
||||
|
||||
if self.group_by_resource_group:
|
||||
if not self._inventory.get(resource_group):
|
||||
self._inventory[resource_group] = []
|
||||
self._inventory[resource_group].append(host_name)
|
||||
|
||||
if self.group_by_location:
|
||||
if not self._inventory.get(vars['location']):
|
||||
self._inventory[vars['location']] = []
|
||||
self._inventory[vars['location']].append(host_name)
|
||||
|
||||
if self.group_by_security_group and security_group:
|
||||
if not self._inventory.get(security_group):
|
||||
self._inventory[security_group] = []
|
||||
self._inventory[security_group].append(host_name)
|
||||
|
||||
self._inventory['_meta']['hostvars'][host_name] = vars
|
||||
self._inventory['azure'].append(host_name)
|
||||
|
||||
if self.group_by_tag and vars.get('tags'):
|
||||
for key, value in vars['tags'].items():
|
||||
safe_key = self._to_safe(key)
|
||||
safe_value = safe_key + '_' + self._to_safe(value)
|
||||
if not self._inventory.get(safe_key):
|
||||
self._inventory[safe_key] = []
|
||||
if not self._inventory.get(safe_value):
|
||||
self._inventory[safe_value] = []
|
||||
self._inventory[safe_key].append(host_name)
|
||||
self._inventory[safe_value].append(host_name)
|
||||
|
||||
def _json_format_dict(self, pretty=False):
|
||||
# convert inventory to json
|
||||
if pretty:
|
||||
return json.dumps(self._inventory, sort_keys=True, indent=2)
|
||||
else:
|
||||
return json.dumps(self._inventory)
|
||||
|
||||
def _get_settings(self):
|
||||
# Load settings from the .ini, if it exists. Otherwise,
|
||||
# look for environment values.
|
||||
file_settings = self._load_settings()
|
||||
if file_settings:
|
||||
for key in AZURE_CONFIG_SETTINGS:
|
||||
if key in ('resource_groups', 'tags', 'locations') and file_settings.get(key):
|
||||
values = file_settings.get(key).split(',')
|
||||
if len(values) > 0:
|
||||
setattr(self, key, values)
|
||||
elif file_settings.get(key):
|
||||
val = self._to_boolean(file_settings[key])
|
||||
setattr(self, key, val)
|
||||
else:
|
||||
env_settings = self._get_env_settings()
|
||||
for key in AZURE_CONFIG_SETTINGS:
|
||||
if key in('resource_groups', 'tags', 'locations') and env_settings.get(key):
|
||||
values = env_settings.get(key).split(',')
|
||||
if len(values) > 0:
|
||||
setattr(self, key, values)
|
||||
elif env_settings.get(key, None) is not None:
|
||||
val = self._to_boolean(env_settings[key])
|
||||
setattr(self, key, val)
|
||||
|
||||
def _parse_ref_id(self, reference):
|
||||
response = {}
|
||||
keys = reference.strip('/').split('/')
|
||||
for index in range(len(keys)):
|
||||
if index < len(keys) - 1 and index % 2 == 0:
|
||||
response[keys[index]] = keys[index + 1]
|
||||
return response
|
||||
|
||||
def _to_boolean(self, value):
|
||||
if value in ['Yes', 'yes', 1, 'True', 'true', True]:
|
||||
result = True
|
||||
elif value in ['No', 'no', 0, 'False', 'false', False]:
|
||||
result = False
|
||||
else:
|
||||
result = True
|
||||
return result
|
||||
|
||||
def _get_env_settings(self):
|
||||
env_settings = dict()
|
||||
for attribute, env_variable in AZURE_CONFIG_SETTINGS.items():
|
||||
env_settings[attribute] = os.environ.get(env_variable, None)
|
||||
return env_settings
|
||||
|
||||
def _load_settings(self):
|
||||
basename = os.path.splitext(os.path.basename(__file__))[0]
|
||||
default_path = os.path.join(os.path.dirname(__file__), (basename + '.ini'))
|
||||
path = os.path.expanduser(os.path.expandvars(os.environ.get('AZURE_INI_PATH', default_path)))
|
||||
config = None
|
||||
settings = None
|
||||
try:
|
||||
config = ConfigParser.ConfigParser()
|
||||
config.read(path)
|
||||
except:
|
||||
pass
|
||||
|
||||
if config is not None:
|
||||
settings = dict()
|
||||
for key in AZURE_CONFIG_SETTINGS:
|
||||
try:
|
||||
settings[key] = config.get('azure', key, raw=True)
|
||||
except:
|
||||
pass
|
||||
|
||||
return settings
|
||||
|
||||
def _tags_match(self, tag_obj, tag_args):
|
||||
'''
|
||||
Return True if the tags object from a VM contains the requested tag values.
|
||||
|
||||
:param tag_obj: Dictionary of string:string pairs
|
||||
:param tag_args: List of strings in the form key=value
|
||||
:return: boolean
|
||||
'''
|
||||
|
||||
if not tag_obj:
|
||||
return False
|
||||
|
||||
matches = 0
|
||||
for arg in tag_args:
|
||||
arg_key = arg
|
||||
arg_value = None
|
||||
if re.search(r':', arg):
|
||||
arg_key, arg_value = arg.split(':')
|
||||
if arg_value and tag_obj.get(arg_key, None) == arg_value:
|
||||
matches += 1
|
||||
elif not arg_value and tag_obj.get(arg_key, None) is not None:
|
||||
matches += 1
|
||||
if matches == len(tag_args):
|
||||
return True
|
||||
return False
|
||||
|
||||
def _to_safe(self, word):
|
||||
''' Converts 'bad' characters in a string to underscores so they can be used as Ansible groups '''
|
||||
regex = "[^A-Za-z0-9\_"
|
||||
if not self.replace_dash_in_groups:
|
||||
regex += "\-"
|
||||
return re.sub(regex + "]", "_", word)
|
||||
|
||||
|
||||
def main():
|
||||
if not HAS_AZURE:
|
||||
sys.exit("The Azure python sdk is not installed (try `pip install 'azure>={0}' --upgrade`) - {1}".format(AZURE_MIN_VERSION, HAS_AZURE_EXC))
|
||||
|
||||
AzureInventory()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
39
contrib/inventory/brook.ini
Normal file
39
contrib/inventory/brook.ini
Normal file
@ -0,0 +1,39 @@
|
||||
# Copyright 2016 Doalitic.
|
||||
#
|
||||
# This file is part of Ansible
|
||||
#
|
||||
# Ansible is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Ansible is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
# The Brook.io inventory script has the following dependencies:
|
||||
# 1. A working Brook.io account
|
||||
# See https://brook.io
|
||||
# 2. A valid token generated through the 'API token' panel of Brook.io
|
||||
# 3. The libbrook python libray.
|
||||
# See https://github.com/doalitic/libbrook
|
||||
#
|
||||
# Author: Francisco Ros <fjros@doalitic.com>
|
||||
|
||||
[brook]
|
||||
# Valid API token (required).
|
||||
# E.g. 'Aed342a12A60433697281FeEe1a4037C'
|
||||
#
|
||||
api_token =
|
||||
|
||||
# Project id within Brook.io, as obtained from the project settings (optional). If provided, the
|
||||
# generated inventory will just include the hosts that belong to such project. Otherwise, it will
|
||||
# include all hosts in projects the requesting user has access to. The response includes groups
|
||||
# 'project_x', being 'x' the project name.
|
||||
# E.g. '2e8e099e1bc34cc0979d97ac34e9577b'
|
||||
#
|
||||
project_id =
|
||||
264
contrib/inventory/brook.py
Executable file
264
contrib/inventory/brook.py
Executable file
@ -0,0 +1,264 @@
|
||||
#!/usr/bin/env python
|
||||
# Copyright 2016 Doalitic.
|
||||
#
|
||||
# This file is part of Ansible
|
||||
#
|
||||
# Ansible is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Ansible is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
"""
|
||||
Brook.io external inventory script
|
||||
==================================
|
||||
|
||||
Generates inventory that Ansible can understand by making API requests to Brook.io via the libbrook
|
||||
library. Hence, such dependency must be installed in the system to run this script.
|
||||
|
||||
The default configuration file is named 'brook.ini' and is located alongside this script. You can
|
||||
choose any other file by setting the BROOK_INI_PATH environment variable.
|
||||
|
||||
If param 'project_id' is left blank in 'brook.ini', the inventory includes all the instances in
|
||||
projects where the requesting user belongs. Otherwise, only instances from the given project are
|
||||
included, provided the requesting user belongs to it.
|
||||
|
||||
The following variables are established for every host. They can be retrieved from the hostvars
|
||||
dictionary.
|
||||
- brook_pid: str
|
||||
- brook_name: str
|
||||
- brook_description: str
|
||||
- brook_project: str
|
||||
- brook_template: str
|
||||
- brook_region: str
|
||||
- brook_zone: str
|
||||
- brook_status: str
|
||||
- brook_tags: list(str)
|
||||
- brook_internal_ips: list(str)
|
||||
- brook_external_ips: list(str)
|
||||
- brook_created_at
|
||||
- brook_updated_at
|
||||
- ansible_ssh_host
|
||||
|
||||
Instances are grouped by the following categories:
|
||||
- tag:
|
||||
A group is created for each tag. E.g. groups 'tag_foo' and 'tag_bar' are created if there exist
|
||||
instances with tags 'foo' and/or 'bar'.
|
||||
- project:
|
||||
A group is created for each project. E.g. group 'project_test' is created if a project named
|
||||
'test' exist.
|
||||
- status:
|
||||
A group is created for each instance state. E.g. groups 'status_RUNNING' and 'status_PENDING'
|
||||
are created if there are instances in running and pending state.
|
||||
|
||||
Examples:
|
||||
Execute uname on all instances in project 'test'
|
||||
$ ansible -i brook.py project_test -m shell -a "/bin/uname -a"
|
||||
|
||||
Install nginx on all debian web servers tagged with 'www'
|
||||
$ ansible -i brook.py tag_www -m apt -a "name=nginx state=present"
|
||||
|
||||
Run site.yml playbook on web servers
|
||||
$ ansible-playbook -i brook.py site.yml -l tag_www
|
||||
|
||||
Support:
|
||||
This script is tested on Python 2.7 and 3.4. It may work on other versions though.
|
||||
|
||||
Author: Francisco Ros <fjros@doalitic.com>
|
||||
Version: 0.2
|
||||
"""
|
||||
|
||||
|
||||
import sys
|
||||
import os
|
||||
|
||||
try:
|
||||
from ConfigParser import SafeConfigParser as ConfigParser
|
||||
except ImportError:
|
||||
from configparser import ConfigParser
|
||||
|
||||
try:
|
||||
import json
|
||||
except ImportError:
|
||||
import simplejson as json
|
||||
|
||||
try:
|
||||
import libbrook
|
||||
except:
|
||||
sys.exit('Brook.io inventory script requires libbrook. See https://github.com/doalitic/libbrook')
|
||||
|
||||
|
||||
class BrookInventory:
|
||||
|
||||
_API_ENDPOINT = 'https://api.brook.io'
|
||||
|
||||
def __init__(self):
|
||||
self._configure_from_file()
|
||||
self.client = self.get_api_client()
|
||||
self.inventory = self.get_inventory()
|
||||
|
||||
def _configure_from_file(self):
|
||||
"""Initialize from .ini file.
|
||||
|
||||
Configuration file is assumed to be named 'brook.ini' and to be located on the same
|
||||
directory than this file, unless the environment variable BROOK_INI_PATH says otherwise.
|
||||
"""
|
||||
|
||||
brook_ini_default_path = \
|
||||
os.path.join(os.path.dirname(os.path.realpath(__file__)), 'brook.ini')
|
||||
brook_ini_path = os.environ.get('BROOK_INI_PATH', brook_ini_default_path)
|
||||
|
||||
config = ConfigParser(defaults={
|
||||
'api_token': '',
|
||||
'project_id': ''
|
||||
})
|
||||
config.read(brook_ini_path)
|
||||
self.api_token = config.get('brook', 'api_token')
|
||||
self.project_id = config.get('brook', 'project_id')
|
||||
|
||||
if not self.api_token:
|
||||
sys.exit('You must provide (at least) your Brook.io API token to generate the dynamic '
|
||||
'inventory.')
|
||||
|
||||
def get_api_client(self):
|
||||
"""Authenticate user via the provided credentials and return the corresponding API client.
|
||||
"""
|
||||
|
||||
# Get JWT token from API token
|
||||
#
|
||||
unauthenticated_client = libbrook.ApiClient(host=self._API_ENDPOINT)
|
||||
auth_api = libbrook.AuthApi(unauthenticated_client)
|
||||
api_token = libbrook.AuthTokenRequest()
|
||||
api_token.token = self.api_token
|
||||
jwt = auth_api.auth_token(token=api_token)
|
||||
|
||||
# Create authenticated API client
|
||||
#
|
||||
return libbrook.ApiClient(host=self._API_ENDPOINT,
|
||||
header_name='Authorization',
|
||||
header_value='Bearer %s' % jwt.token)
|
||||
|
||||
def get_inventory(self):
|
||||
"""Generate Ansible inventory.
|
||||
"""
|
||||
|
||||
groups = dict()
|
||||
meta = dict()
|
||||
meta['hostvars'] = dict()
|
||||
|
||||
instances_api = libbrook.InstancesApi(self.client)
|
||||
projects_api = libbrook.ProjectsApi(self.client)
|
||||
templates_api = libbrook.TemplatesApi(self.client)
|
||||
|
||||
# If no project is given, get all projects the requesting user has access to
|
||||
#
|
||||
if not self.project_id:
|
||||
projects = [project.id for project in projects_api.index_projects()]
|
||||
else:
|
||||
projects = [self.project_id]
|
||||
|
||||
# Build inventory from instances in all projects
|
||||
#
|
||||
for project_id in projects:
|
||||
project = projects_api.show_project(project_id=project_id)
|
||||
for instance in instances_api.index_instances(project_id=project_id):
|
||||
# Get template used for this instance if known
|
||||
template = templates_api.show_template(template_id=instance.template) if instance.template else None
|
||||
|
||||
# Update hostvars
|
||||
try:
|
||||
meta['hostvars'][instance.name] = \
|
||||
self.hostvars(project, instance, template, instances_api)
|
||||
except libbrook.rest.ApiException:
|
||||
continue
|
||||
|
||||
# Group by project
|
||||
project_group = 'project_%s' % project.name
|
||||
if project_group in groups:
|
||||
groups[project_group].append(instance.name)
|
||||
else:
|
||||
groups[project_group] = [instance.name]
|
||||
|
||||
# Group by status
|
||||
status_group = 'status_%s' % meta['hostvars'][instance.name]['brook_status']
|
||||
if status_group in groups:
|
||||
groups[status_group].append(instance.name)
|
||||
else:
|
||||
groups[status_group] = [instance.name]
|
||||
|
||||
# Group by tags
|
||||
tags = meta['hostvars'][instance.name]['brook_tags']
|
||||
for tag in tags:
|
||||
tag_group = 'tag_%s' % tag
|
||||
if tag_group in groups:
|
||||
groups[tag_group].append(instance.name)
|
||||
else:
|
||||
groups[tag_group] = [instance.name]
|
||||
|
||||
groups['_meta'] = meta
|
||||
return groups
|
||||
|
||||
def hostvars(self, project, instance, template, api):
|
||||
"""Return the hostvars dictionary for the given instance.
|
||||
|
||||
Raise libbrook.rest.ApiException if it cannot retrieve all required information from the
|
||||
Brook.io API.
|
||||
"""
|
||||
|
||||
hostvars = instance.to_dict()
|
||||
hostvars['brook_pid'] = hostvars.pop('pid')
|
||||
hostvars['brook_name'] = hostvars.pop('name')
|
||||
hostvars['brook_description'] = hostvars.pop('description')
|
||||
hostvars['brook_project'] = hostvars.pop('project')
|
||||
hostvars['brook_template'] = hostvars.pop('template')
|
||||
hostvars['brook_region'] = hostvars.pop('region')
|
||||
hostvars['brook_zone'] = hostvars.pop('zone')
|
||||
hostvars['brook_created_at'] = hostvars.pop('created_at')
|
||||
hostvars['brook_updated_at'] = hostvars.pop('updated_at')
|
||||
del hostvars['id']
|
||||
del hostvars['key']
|
||||
del hostvars['provider']
|
||||
del hostvars['image']
|
||||
|
||||
# Substitute identifiers for names
|
||||
#
|
||||
hostvars['brook_project'] = project.name
|
||||
hostvars['brook_template'] = template.name if template else None
|
||||
|
||||
# Retrieve instance state
|
||||
#
|
||||
status = api.status_instance(project_id=project.id, instance_id=instance.id)
|
||||
hostvars.update({'brook_status': status.state})
|
||||
|
||||
# Retrieve instance tags
|
||||
#
|
||||
tags = api.instance_tags(project_id=project.id, instance_id=instance.id)
|
||||
hostvars.update({'brook_tags': tags})
|
||||
|
||||
# Retrieve instance addresses
|
||||
#
|
||||
addresses = api.instance_addresses(project_id=project.id, instance_id=instance.id)
|
||||
internal_ips = [address.address for address in addresses if address.scope == 'internal']
|
||||
external_ips = [address.address for address in addresses
|
||||
if address.address and address.scope == 'external']
|
||||
hostvars.update({'brook_internal_ips': internal_ips})
|
||||
hostvars.update({'brook_external_ips': external_ips})
|
||||
try:
|
||||
hostvars.update({'ansible_ssh_host': external_ips[0]})
|
||||
except IndexError:
|
||||
raise libbrook.rest.ApiException(status='502', reason='Instance without public IP')
|
||||
|
||||
return hostvars
|
||||
|
||||
|
||||
# Run the script
|
||||
#
|
||||
brook = BrookInventory()
|
||||
print(json.dumps(brook.inventory))
|
||||
33
contrib/inventory/cloudforms.ini
Normal file
33
contrib/inventory/cloudforms.ini
Normal file
@ -0,0 +1,33 @@
|
||||
[cloudforms]
|
||||
|
||||
# the version of CloudForms ; currently not used, but tested with
|
||||
version = 4.1
|
||||
|
||||
# This should be the hostname of the CloudForms server
|
||||
url = https://cfme.example.com
|
||||
|
||||
# This will more than likely need to be a local CloudForms username
|
||||
username = <set your username here>
|
||||
|
||||
# The password for said username
|
||||
password = <set your password here>
|
||||
|
||||
# True = verify SSL certificate / False = trust anything
|
||||
ssl_verify = True
|
||||
|
||||
# limit the number of vms returned per request
|
||||
limit = 100
|
||||
|
||||
# purge the CloudForms actions from hosts
|
||||
purge_actions = True
|
||||
|
||||
# Clean up group names (from tags and other groupings so Ansible doesn't complain)
|
||||
clean_group_keys = True
|
||||
|
||||
# Explode tags into nested groups / subgroups
|
||||
nest_tags = False
|
||||
|
||||
[cache]
|
||||
|
||||
# Maximum time to trust the cache in seconds
|
||||
max_age = 600
|
||||
461
contrib/inventory/cloudforms.py
Executable file
461
contrib/inventory/cloudforms.py
Executable file
@ -0,0 +1,461 @@
|
||||
#!/usr/bin/env python
|
||||
# vim: set fileencoding=utf-8 :
|
||||
#
|
||||
# Copyright (C) 2016 Guido Günther <agx@sigxcpu.org>
|
||||
#
|
||||
# This script is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Ansible is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with it. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
# This is loosely based on the foreman inventory script
|
||||
# -- Josh Preston <jpreston@redhat.com>
|
||||
#
|
||||
|
||||
from __future__ import print_function
|
||||
import argparse
|
||||
import ConfigParser
|
||||
import os
|
||||
import re
|
||||
from time import time
|
||||
import requests
|
||||
from requests.auth import HTTPBasicAuth
|
||||
import warnings
|
||||
|
||||
try:
|
||||
import json
|
||||
except ImportError:
|
||||
import simplejson as json
|
||||
|
||||
|
||||
class CloudFormsInventory(object):
|
||||
def __init__(self):
|
||||
"""
|
||||
Main execution path
|
||||
"""
|
||||
self.inventory = dict() # A list of groups and the hosts in that group
|
||||
self.hosts = dict() # Details about hosts in the inventory
|
||||
|
||||
# Parse CLI arguments
|
||||
self.parse_cli_args()
|
||||
|
||||
# Read settings
|
||||
self.read_settings()
|
||||
|
||||
# Cache
|
||||
if self.args.refresh_cache or not self.is_cache_valid():
|
||||
self.update_cache()
|
||||
else:
|
||||
self.load_inventory_from_cache()
|
||||
self.load_hosts_from_cache()
|
||||
|
||||
data_to_print = ""
|
||||
|
||||
# Data to print
|
||||
if self.args.host:
|
||||
if self.args.debug:
|
||||
print("Fetching host [%s]" % self.args.host)
|
||||
data_to_print += self.get_host_info(self.args.host)
|
||||
else:
|
||||
self.inventory['_meta'] = {'hostvars': {}}
|
||||
for hostname in self.hosts:
|
||||
self.inventory['_meta']['hostvars'][hostname] = {
|
||||
'cloudforms': self.hosts[hostname],
|
||||
}
|
||||
# include the ansible_ssh_host in the top level
|
||||
if 'ansible_ssh_host' in self.hosts[hostname]:
|
||||
self.inventory['_meta']['hostvars'][hostname]['ansible_ssh_host'] = self.hosts[hostname]['ansible_ssh_host']
|
||||
|
||||
data_to_print += self.json_format_dict(self.inventory, self.args.pretty)
|
||||
|
||||
print(data_to_print)
|
||||
|
||||
def is_cache_valid(self):
|
||||
"""
|
||||
Determines if the cache files have expired, or if it is still valid
|
||||
"""
|
||||
if self.args.debug:
|
||||
print("Determining if cache [%s] is still valid (< %s seconds old)" % (self.cache_path_hosts, self.cache_max_age))
|
||||
|
||||
if os.path.isfile(self.cache_path_hosts):
|
||||
mod_time = os.path.getmtime(self.cache_path_hosts)
|
||||
current_time = time()
|
||||
if (mod_time + self.cache_max_age) > current_time:
|
||||
if os.path.isfile(self.cache_path_inventory):
|
||||
if self.args.debug:
|
||||
print("Cache is still valid!")
|
||||
return True
|
||||
|
||||
if self.args.debug:
|
||||
print("Cache is stale or does not exist.")
|
||||
|
||||
return False
|
||||
|
||||
def read_settings(self):
|
||||
"""
|
||||
Reads the settings from the cloudforms.ini file
|
||||
"""
|
||||
config = ConfigParser.SafeConfigParser()
|
||||
config_paths = [
|
||||
os.path.dirname(os.path.realpath(__file__)) + '/cloudforms.ini',
|
||||
"/etc/ansible/cloudforms.ini",
|
||||
]
|
||||
|
||||
env_value = os.environ.get('CLOUDFORMS_INI_PATH')
|
||||
if env_value is not None:
|
||||
config_paths.append(os.path.expanduser(os.path.expandvars(env_value)))
|
||||
|
||||
if self.args.debug:
|
||||
for config_path in config_paths:
|
||||
print("Reading from configuration file [%s]" % config_path)
|
||||
|
||||
config.read(config_paths)
|
||||
|
||||
# CloudForms API related
|
||||
if config.has_option('cloudforms', 'url'):
|
||||
self.cloudforms_url = config.get('cloudforms', 'url')
|
||||
else:
|
||||
self.cloudforms_url = None
|
||||
|
||||
if not self.cloudforms_url:
|
||||
warnings.warn("No url specified, expected something like 'https://cfme.example.com'")
|
||||
|
||||
if config.has_option('cloudforms', 'username'):
|
||||
self.cloudforms_username = config.get('cloudforms', 'username')
|
||||
else:
|
||||
self.cloudforms_username = None
|
||||
|
||||
if not self.cloudforms_username:
|
||||
warnings.warn("No username specified, you need to specify a CloudForms username.")
|
||||
|
||||
if config.has_option('cloudforms', 'password'):
|
||||
self.cloudforms_pw = config.get('cloudforms', 'password')
|
||||
else:
|
||||
self.cloudforms_pw = None
|
||||
|
||||
if not self.cloudforms_pw:
|
||||
warnings.warn("No password specified, you need to specify a password for the CloudForms user.")
|
||||
|
||||
if config.has_option('cloudforms', 'ssl_verify'):
|
||||
self.cloudforms_ssl_verify = config.getboolean('cloudforms', 'ssl_verify')
|
||||
else:
|
||||
self.cloudforms_ssl_verify = True
|
||||
|
||||
if config.has_option('cloudforms', 'version'):
|
||||
self.cloudforms_version = config.get('cloudforms', 'version')
|
||||
else:
|
||||
self.cloudforms_version = None
|
||||
|
||||
if config.has_option('cloudforms', 'limit'):
|
||||
self.cloudforms_limit = config.getint('cloudforms', 'limit')
|
||||
else:
|
||||
self.cloudforms_limit = 100
|
||||
|
||||
if config.has_option('cloudforms', 'purge_actions'):
|
||||
self.cloudforms_purge_actions = config.getboolean('cloudforms', 'purge_actions')
|
||||
else:
|
||||
self.cloudforms_purge_actions = True
|
||||
|
||||
if config.has_option('cloudforms', 'clean_group_keys'):
|
||||
self.cloudforms_clean_group_keys = config.getboolean('cloudforms', 'clean_group_keys')
|
||||
else:
|
||||
self.cloudforms_clean_group_keys = True
|
||||
|
||||
if config.has_option('cloudforms', 'nest_tags'):
|
||||
self.cloudforms_nest_tags = config.getboolean('cloudforms', 'nest_tags')
|
||||
else:
|
||||
self.cloudforms_nest_tags = False
|
||||
|
||||
# Ansible related
|
||||
try:
|
||||
group_patterns = config.get('ansible', 'group_patterns')
|
||||
except (ConfigParser.NoOptionError, ConfigParser.NoSectionError):
|
||||
group_patterns = "[]"
|
||||
|
||||
self.group_patterns = eval(group_patterns)
|
||||
|
||||
# Cache related
|
||||
try:
|
||||
cache_path = os.path.expanduser(config.get('cache', 'path'))
|
||||
except (ConfigParser.NoOptionError, ConfigParser.NoSectionError):
|
||||
cache_path = '.'
|
||||
(script, ext) = os.path.splitext(os.path.basename(__file__))
|
||||
self.cache_path_hosts = cache_path + "/%s.hosts" % script
|
||||
self.cache_path_inventory = cache_path + "/%s.inventory" % script
|
||||
self.cache_max_age = config.getint('cache', 'max_age')
|
||||
|
||||
if self.args.debug:
|
||||
print("CloudForms settings:")
|
||||
print("cloudforms_url = %s" % self.cloudforms_url)
|
||||
print("cloudforms_username = %s" % self.cloudforms_username)
|
||||
print("cloudforms_pw = %s" % self.cloudforms_pw)
|
||||
print("cloudforms_ssl_verify = %s" % self.cloudforms_ssl_verify)
|
||||
print("cloudforms_version = %s" % self.cloudforms_version)
|
||||
print("cloudforms_limit = %s" % self.cloudforms_limit)
|
||||
print("cloudforms_purge_actions = %s" % self.cloudforms_purge_actions)
|
||||
print("Cache settings:")
|
||||
print("cache_max_age = %s" % self.cache_max_age)
|
||||
print("cache_path_hosts = %s" % self.cache_path_hosts)
|
||||
print("cache_path_inventory = %s" % self.cache_path_inventory)
|
||||
|
||||
def parse_cli_args(self):
|
||||
"""
|
||||
Command line argument processing
|
||||
"""
|
||||
parser = argparse.ArgumentParser(description='Produce an Ansible Inventory file based on CloudForms managed VMs')
|
||||
parser.add_argument('--list', action='store_true', default=True, help='List instances (default: True)')
|
||||
parser.add_argument('--host', action='store', help='Get all the variables about a specific instance')
|
||||
parser.add_argument('--pretty', action='store_true', default=False, help='Pretty print JSON output (default: False)')
|
||||
parser.add_argument('--refresh-cache', action='store_true', default=False,
|
||||
help='Force refresh of cache by making API requests to CloudForms (default: False - use cache files)')
|
||||
parser.add_argument('--debug', action='store_true', default=False, help='Show debug output while running (default: False)')
|
||||
self.args = parser.parse_args()
|
||||
|
||||
def _get_json(self, url):
|
||||
"""
|
||||
Make a request and return the JSON
|
||||
"""
|
||||
results = []
|
||||
|
||||
ret = requests.get(url,
|
||||
auth=HTTPBasicAuth(self.cloudforms_username, self.cloudforms_pw),
|
||||
verify=self.cloudforms_ssl_verify)
|
||||
|
||||
ret.raise_for_status()
|
||||
|
||||
try:
|
||||
results = json.loads(ret.text)
|
||||
except ValueError:
|
||||
warnings.warn("Unexpected response from {0} ({1}): {2}".format(self.cloudforms_url, ret.status_code, ret.reason))
|
||||
results = {}
|
||||
|
||||
if self.args.debug:
|
||||
print("=======================================================================")
|
||||
print("=======================================================================")
|
||||
print("=======================================================================")
|
||||
print(ret.text)
|
||||
print("=======================================================================")
|
||||
print("=======================================================================")
|
||||
print("=======================================================================")
|
||||
|
||||
return results
|
||||
|
||||
def _get_hosts(self):
|
||||
"""
|
||||
Get all hosts by paging through the results
|
||||
"""
|
||||
limit = self.cloudforms_limit
|
||||
|
||||
page = 0
|
||||
last_page = False
|
||||
|
||||
results = []
|
||||
|
||||
while not last_page:
|
||||
offset = page * limit
|
||||
ret = self._get_json("%s/api/vms?offset=%s&limit=%s&expand=resources,tags,hosts,&attributes=ipaddresses" % (self.cloudforms_url, offset, limit))
|
||||
results += ret['resources']
|
||||
if ret['subcount'] < limit:
|
||||
last_page = True
|
||||
page += 1
|
||||
|
||||
return results
|
||||
|
||||
def update_cache(self):
|
||||
"""
|
||||
Make calls to cloudforms and save the output in a cache
|
||||
"""
|
||||
self.groups = dict()
|
||||
self.hosts = dict()
|
||||
|
||||
if self.args.debug:
|
||||
print("Updating cache...")
|
||||
|
||||
for host in self._get_hosts():
|
||||
# Ignore VMs that are not powered on
|
||||
if host['power_state'] != 'on':
|
||||
if self.args.debug:
|
||||
print("Skipping %s because power_state = %s" % (host['name'], host['power_state']))
|
||||
continue
|
||||
|
||||
# purge actions
|
||||
if self.cloudforms_purge_actions and 'actions' in host:
|
||||
del host['actions']
|
||||
|
||||
# Create ansible groups for tags
|
||||
if 'tags' in host:
|
||||
|
||||
# Create top-level group
|
||||
if 'tags' not in self.inventory:
|
||||
self.inventory['tags'] = dict(children=[], vars={}, hosts=[])
|
||||
|
||||
if not self.cloudforms_nest_tags:
|
||||
# don't expand tags, just use them in a safe way
|
||||
for group in host['tags']:
|
||||
# Add sub-group, as a child of top-level
|
||||
safe_key = self.to_safe(group['name'])
|
||||
if safe_key:
|
||||
if self.args.debug:
|
||||
print("Adding sub-group '%s' to parent 'tags'" % safe_key)
|
||||
|
||||
if safe_key not in self.inventory['tags']['children']:
|
||||
self.push(self.inventory['tags'], 'children', safe_key)
|
||||
|
||||
self.push(self.inventory, safe_key, host['name'])
|
||||
|
||||
if self.args.debug:
|
||||
print("Found tag [%s] for host which will be mapped to [%s]" % (group['name'], safe_key))
|
||||
else:
|
||||
# expand the tags into nested groups / sub-groups
|
||||
# Create nested groups for tags
|
||||
safe_parent_tag_name = 'tags'
|
||||
for tag in host['tags']:
|
||||
tag_hierarchy = tag['name'][1:].split('/')
|
||||
|
||||
if self.args.debug:
|
||||
print("Working on list %s" % tag_hierarchy)
|
||||
|
||||
for tag_name in tag_hierarchy:
|
||||
if self.args.debug:
|
||||
print("Working on tag_name = %s" % tag_name)
|
||||
|
||||
safe_tag_name = self.to_safe(tag_name)
|
||||
if self.args.debug:
|
||||
print("Using sanitized name %s" % safe_tag_name)
|
||||
|
||||
# Create sub-group
|
||||
if safe_tag_name not in self.inventory:
|
||||
self.inventory[safe_tag_name] = dict(children=[], vars={}, hosts=[])
|
||||
|
||||
# Add sub-group, as a child of top-level
|
||||
if safe_parent_tag_name:
|
||||
if self.args.debug:
|
||||
print("Adding sub-group '%s' to parent '%s'" % (safe_tag_name, safe_parent_tag_name))
|
||||
|
||||
if safe_tag_name not in self.inventory[safe_parent_tag_name]['children']:
|
||||
self.push(self.inventory[safe_parent_tag_name], 'children', safe_tag_name)
|
||||
|
||||
# Make sure the next one uses this one as it's parent
|
||||
safe_parent_tag_name = safe_tag_name
|
||||
|
||||
# Add the host to the last tag
|
||||
self.push(self.inventory[safe_parent_tag_name], 'hosts', host['name'])
|
||||
|
||||
# Set ansible_ssh_host to the first available ip address
|
||||
if 'ipaddresses' in host and host['ipaddresses'] and isinstance(host['ipaddresses'], list):
|
||||
host['ansible_ssh_host'] = host['ipaddresses'][0]
|
||||
|
||||
# Create additional groups
|
||||
for key in ('location', 'type', 'vendor'):
|
||||
safe_key = self.to_safe(host[key])
|
||||
|
||||
# Create top-level group
|
||||
if key not in self.inventory:
|
||||
self.inventory[key] = dict(children=[], vars={}, hosts=[])
|
||||
|
||||
# Create sub-group
|
||||
if safe_key not in self.inventory:
|
||||
self.inventory[safe_key] = dict(children=[], vars={}, hosts=[])
|
||||
|
||||
# Add sub-group, as a child of top-level
|
||||
if safe_key not in self.inventory[key]['children']:
|
||||
self.push(self.inventory[key], 'children', safe_key)
|
||||
|
||||
if key in host:
|
||||
# Add host to sub-group
|
||||
self.push(self.inventory[safe_key], 'hosts', host['name'])
|
||||
|
||||
self.hosts[host['name']] = host
|
||||
self.push(self.inventory, 'all', host['name'])
|
||||
|
||||
if self.args.debug:
|
||||
print("Saving cached data")
|
||||
|
||||
self.write_to_cache(self.hosts, self.cache_path_hosts)
|
||||
self.write_to_cache(self.inventory, self.cache_path_inventory)
|
||||
|
||||
def get_host_info(self, host):
|
||||
"""
|
||||
Get variables about a specific host
|
||||
"""
|
||||
if not self.hosts or len(self.hosts) == 0:
|
||||
# Need to load cache from cache
|
||||
self.load_hosts_from_cache()
|
||||
|
||||
if host not in self.hosts:
|
||||
if self.args.debug:
|
||||
print("[%s] not found in cache." % host)
|
||||
|
||||
# try updating the cache
|
||||
self.update_cache()
|
||||
|
||||
if host not in self.hosts:
|
||||
if self.args.debug:
|
||||
print("[%s] does not exist after cache update." % host)
|
||||
# host might not exist anymore
|
||||
return self.json_format_dict({}, self.args.pretty)
|
||||
|
||||
return self.json_format_dict(self.hosts[host], self.args.pretty)
|
||||
|
||||
def push(self, d, k, v):
|
||||
"""
|
||||
Safely puts a new entry onto an array.
|
||||
"""
|
||||
if k in d:
|
||||
d[k].append(v)
|
||||
else:
|
||||
d[k] = [v]
|
||||
|
||||
def load_inventory_from_cache(self):
|
||||
"""
|
||||
Reads the inventory from the cache file sets self.inventory
|
||||
"""
|
||||
cache = open(self.cache_path_inventory, 'r')
|
||||
json_inventory = cache.read()
|
||||
self.inventory = json.loads(json_inventory)
|
||||
|
||||
def load_hosts_from_cache(self):
|
||||
"""
|
||||
Reads the cache from the cache file sets self.hosts
|
||||
"""
|
||||
cache = open(self.cache_path_hosts, 'r')
|
||||
json_cache = cache.read()
|
||||
self.hosts = json.loads(json_cache)
|
||||
|
||||
def write_to_cache(self, data, filename):
|
||||
"""
|
||||
Writes data in JSON format to a file
|
||||
"""
|
||||
json_data = self.json_format_dict(data, True)
|
||||
cache = open(filename, 'w')
|
||||
cache.write(json_data)
|
||||
cache.close()
|
||||
|
||||
def to_safe(self, word):
|
||||
"""
|
||||
Converts 'bad' characters in a string to underscores so they can be used as Ansible groups
|
||||
"""
|
||||
if self.cloudforms_clean_group_keys:
|
||||
regex = "[^A-Za-z0-9\_]"
|
||||
return re.sub(regex, "_", word.replace(" ", ""))
|
||||
else:
|
||||
return word
|
||||
|
||||
def json_format_dict(self, data, pretty=False):
|
||||
"""
|
||||
Converts a dict to a JSON object and dumps it as a formatted string
|
||||
"""
|
||||
if pretty:
|
||||
return json.dumps(data, sort_keys=True, indent=2)
|
||||
else:
|
||||
return json.dumps(data)
|
||||
|
||||
CloudFormsInventory()
|
||||
5
contrib/inventory/cloudstack.ini
Normal file
5
contrib/inventory/cloudstack.ini
Normal file
@ -0,0 +1,5 @@
|
||||
[cloudstack]
|
||||
#endpoint = https://api.exoscale.ch/compute
|
||||
endpoint = https://cloud.example.com/client/api
|
||||
key = cloudstack api key
|
||||
secret = cloudstack api secret
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user