UNPKG

@installdoc/ansible-gas-station

Version:

An Ansible playbook that provisions your network with software from GitHub Awesome lists, developed with disaster recovery in mind ⛽🔥🤤

828 lines (736 loc) 31.1 kB
--- version: '3' vars: MOLECULE_LOGS_PATH: molecule/.results/logs MOLECULE_TEST_OPTIONS: ANSIBLE_STDOUT_CALLBACK=community.general.yaml ANSIBLE_CALLBACKS_ENABLED="junit, ansible.posix.profile_tasks, ansible.posix.timer" JUNIT_OUTPUT_DIR="molecule/.results/junit" JUNIT_FAIL_ON_CHANGE=true JUNIT_HIDE_TASK_ARGUMENTS=true tasks: allure:report: deps: - :install:software:allure log: error: Failed to generate and/or open the unit test report start: Generating and opening unit test report success: Successfully generated and opened unit test report cmds: - allure generate molecule/.results/junit --output allure-reports --clean - mkdir -p molecule/.results/junit - cp -rf allure-reports/history/ molecule/.results/junit/ - allure open allure-reports default: log: start: Running default Ansible test cmds: - task: molecule:docker:matrix local: desc: Run the Ansible play on the local machine (or via WSL - see task summary) hide: '{{ne (print .REPOSITORY_TYPE "-" .REPOSITORY_SUBTYPE) "ansible-playbook"}}' summary: | # Run the Ansible play on the local machine This task will use the inventory stored in `test/<OS>/inventory`, the playbook file stored in `test/<OS>/test.yml`, and the Ansible configuration file stored in `test/<OS>/ansible.cfg` to run the play. At the beginning of the play, you will be prompted for the sudo password. cmds: - task: local:test local:test: deps: - :symlink:{{.REPOSITORY_SUBTYPE}} - :install:software:sentry - task: :install:python:requirements env: INSTALL_OPTIONS: --no-dev log: error: Encountered error while testing the Ansible playbook locally start: Testing the Ansible playbook locally success: Successfully tested the Ansible playbook locally cmds: - cp test/{{OS}}/inventory inventory - if [ ! -f ansible.cfg.bak ]; then cp ansible.cfg ansible.cfg.bak; fi - cp test/{{OS}}/ansible.cfg ansible.cfg - | .config/log info 'Prompting for sudo password (required)' set -o pipefail {{.PYTHON_HANDLE}}ansible-playbook --ask-sudo-pass test/{{OS}}/test.yml 2&>1 | tee debug.log || EXIT_CODE=$? - mv ansible.cfg.bak ansible.cfg - rm inventory molecule:dependencies: deps: - :install:python:requirements log: error: Encountered error while installing Ansible Galaxy requirements defined in `requirements.yml` start: Installing Ansible Galaxy requirements defined in `requirements.yml` success: Installed Ansible Galaxy requirements defined in `requirements.yml` cmds: - '{{.PYTHON_HANDLE}} ansible-galaxy install --ignore-errors -r requirements.yml' - task: :symlink:{{.REPOSITORY_SUBTYPE}} molecule:docker: desc: Runs a Docker Molecule test hide: '{{ne .REPOSITORY_TYPE "ansible"}}' summary: | # Runs a Docker Molecule test This task runs the project's Molecule tests using Docker. It only tests against Linux systems. **Opens a prompt:** `task ansible:test:molecule:docker` **Runs the test against the "CentOS-8" group directly:** `task ansible:test:molecule:docker -- CentOS-8` **Save test results for use with auto-generating compatibility chart:** `task ansible:test:molecule:docker:matrix` cmds: - task: molecule:docker:{{if .CLI_ARGS}}cli{{else}}prompt{{end}} molecule:docker:cli: deps: - molecule:dependencies - :install:software:docker - :install:software:sentry - :install:software:sshpass log: error: The `{{.CLI_ARGS}}` Docker Molecule test finished with errors start: Running Docker Molecule test on containers in the `{{.CLI_ARGS}}` group success: Successfully ran the `{{.CLI_ARGS}}` Docker Molecule test cmds: - | set -o pipefail {{.MOLECULE_TEST_OPTIONS}} MOLECULE_GROUP="{{.CLI_ARGS}}" {{.PYTHON_HANDLE}}molecule test -s docker \ -- --skip-tags skipdockertest 2>&1 | tee debug.log || EXIT_CODE=$? molecule:docker:matrix: deps: - molecule:dependencies - :install:software:docker - :install:software:sentry - :install:software:sshpass vars: MOLECULE_DATE: sh: date '+%Y-%m-%d' log: error: There were errors while running the test (results were logged to `{{.MOLECULE_LOGS_PATH}}/{{.MOLECULE_DATE}}-$SCENARIO.txt`) start: Running Docker Molecule test with results teed to `{{.MOLECULE_LOGS_PATH}}/{{.MOLECULE_DATE}}-$SCENARIO.txt` success: Finished running the test (results were logged to `{{.MOLECULE_LOGS_PATH}}/{{.MOLECULE_DATE}}-$SCENARIO.txt`) cmds: - mkdir -p {{.MOLECULE_LOGS_PATH}} - | SCENARIO="Linux" if grep -Ril 'community.general.snap:' ./tasks; then SCENARIO="Snap" .config/log warn 'Running Docker Molecule tests on the Docker containers that are compatible with `snap` since the role has references to `snap`' fi set -o pipefail PY_COLORS=0 {{.MOLECULE_TEST_OPTIONS}} MOLECULE_GROUP="$SCENARIO" {{.PYTHON_HANDLE}}molecule test -s docker -- --skip-tags skipdockertest 2>&1 | \ tee "{{.MOLECULE_LOGS_PATH}}/{{.MOLECULE_DATE}}-$SCENARIO.txt" || EXIT_CODE=$? molecule:docker:prompt: vars: MARKDOWN: | # Ansible Molecule Test via Docker Choose a container group from the options below to begin the Molecule test. The choices should be mostly self-explanatory. The `Snap` group is a special group that should be used to test roles that contain `snap` logic. Only recent versions of Debian and Ubuntu support snap installations inside a Docker container. Docker tests are a quick way to test Ansible plays without consuming a large amount of system resources. Granted, to fully test an Ansible play, a VirtualBox method should be used instead. cmds: - task: :log:markdown vars: MARKDOWN: '{{.MARKDOWN}}' - task: molecule:docker:prompt:continue molecule:docker:prompt:continue: interactive: true deps: - :install:software:jq - :install:software:yq vars: DOCKER_OPTIONS: sh: yq eval -o=j '.groups' molecule/docker/molecule.yml | jq -r 'keys' prompt: type: select message: Which environment(s) would you like to run the test on? options: '{{.DOCKER_OPTIONS}}' answer: cmds: - task: molecule:docker:cli vars: CLI_ARGS: '{{.ANSWER}}' env: ANSIBLE_ENABLE_TASK_DEBUGGER: 'true' - task: allure:report preconditions: - sh: test -f molecule/docker/molecule.yml msg: The `molecule/docker/molecule.yml` file must be present and in the proper format molecule:gcp: deps: - molecule:dependencies - :install:software:gcloud - :install:software:sentry log: error: Encountered error(s) while running the Google Cloud Platform Molecule test start: Running Google Cloud Platform Molecule test success: Finished running Google Cloud Platform Molecule test cmds: - task: molecule:gcp:preconditions - | set -o pipefail {{.PYTHON_HANDLE}}molecule test -s gcp | tee debug.log || EXIT_CODE=$? molecule:gcp:matrix: deps: - molecule:dependencies - :install:software:gcloud - :install:software:sentry - :install:software:yq vars: MOLECULE_DATE: sh: date '+%Y-%m-%d' log: error: An error occurred while running the Google Cloud Platform Molecule test sequence start: Running Docker Molecule test with results teed to `{{.MOLECULE_LOGS_PATH}}/{{.MOLECULE_DATE}}-$SCENARIO.txt` success: Finished running and formatting the results of the Google Cloud Platform molecule test cmds: - task: molecule:gcp:preconditions - mkdir -p {{.MOLECULE_LOGS_PATH}} - | set -o pipefail EXIT_CODE=0 PY_COLORS=0 {{.PYTHON_HANDLE}}molecule test -s gcp 2>&1 | tee "{{.MOLECULE_LOGS_PATH}}/{{.MOLECULE_DATE}}-gcp.txt" || EXIT_CODE=$? if [ "$EXIT_CODE" != '0' ]; then exit 1 else .config/log success 'Finished running the test (results were logged to `{{.MOLECULE_LOGS_PATH}}/{{.MOLECULE_DATE}}-gcp.txt`)' fi - | RESULTS="{{.MOLECULE_LOGS_PATH}}/{{.MOLECULE_DATE}}-gcp.txt" PLATFORM_LENGTH="$(yq e '.platforms | length' molecule/gcp/molecule.yml)" INDEX=0 while [ $INDEX -lt $PLATFORM_LENGTH ]; do NAME="$(yq e '.platforms['$INDEX'].name' molecule/gcp/molecule.yml)" ALIAS="$(yq e '.platforms['$INDEX'].alias' molecule/gcp/molecule.yml)" sed -i -- 's/'"$NAME"'/'"$ALIAS"'/g' "$RESULTS" INDEX=$((INDEX+1)) done molecule:gcp:preconditions: preconditions: - sh: '[ -n "$GCE_SERVICE_ACCOUNT_EMAIL" ]' msg: The GCE_SERVICE_ACCOUNT_EMAIL environment variable must be set (e.g. export GCE_SERVICE_ACCOUNT_EMAIL=molecule@megabyte-labs.iam.gserviceaccount.com). - sh: '[ -n "$GCE_CREDENTIALS_FILE" ]' msg: The GCE_CREDENTIALS_FILE environment variable must be set and pointing to the GCP service account JSON key (e.g. export GCE_CREDENTIALS_FILE=~/.config/gcp.json). - sh: test -f "$GCE_CREDENTIALS_FILE" msg: The GCE_CREDENTIALS_FILE environment variable is defined but is not pointing to a file that exists. - sh: '[ -n "$GCE_PROJECT_ID" ]' msg: The GCE_PROJECT_ID environment variable must be set (e.g. export GCE_PROJECT_ID=megabyte-labs) molecule:local: desc: Runs a Molecule test on the localhost hide: '{{ne .REPOSITORY_TYPE "ansible"}}' summary: | # Run a local Molecule test This option is the same as running the play on the localhost with the added benefit of incorporating Molecule's test for idempotency and other tests. **Opens a prompt:** `task ansible:test:local` cmds: - task: molecule:local:{{if .CLI_ARGS}}test{{else}}prompt{{end}} molecule:local:prompt: vars: MARKDOWN: | # Run Molecule Locally This testing option is provided for cases where you would like to locally test the Ansible play with Molecule. This option assumes that the current user has sudo privileges. ## Sudo Password A sudo password is required for all roles because Molecule has a step where it ensures Python is installed with `become: true`. The sudo password could potentially be logged in clear text if logging is in verbose mode so be careful when using this method. ## Running Locally Without Molecule If you only want to install the play (without leveraging Molecule's features like testing for idempotency and running test cases), then a more secure method would be to run "ansible localhost --ask-sudo-pass -m include_role -a name=<role_name>" after installing the role and its dependencies with ansible-galaxy. cmds: - task: :log:markdown vars: MARKDOWN: '{{.MARKDOWN}}' - task: molecule:local:prompt:continue molecule:local:prompt:continue: interactive: true prompt: type: input message: What is the sudo password for the current user? answer: cmds: - task: molecule:local:test env: ANSIBLE_ENABLE_TASK_DEBUGGER: 'true' TEST_PASSWORD: '{{.ANSWER}}' - task: allure:report molecule:local:test: deps: - molecule:dependencies - :install:software:sentry log: error: There was an error while running the Molecule test locally start: Running the Molecule test locally success: The local Molecule test was successfully run cmds: - | set -o pipefail PATH="$(poetry env info | grep 'Python: /' | sed 's/Python: //' | sed 's/$/\/bin/'):$PATH" \ {{.MOLECULE_TEST_OPTIONS}} {{.PYTHON_HANDLE}}molecule test -s local 2&>1 | tee debug.log || EXIT_CODE=$? molecule:ssh: desc: Runs a Molecule test over SSH hide: '{{ne .REPOSITORY_TYPE "ansible"}}' summary: | # Run an SSH Molecule test This option allows you to run the Molecule test against a single SSH host. **Opens a prompt:** `task ansible:test:molecule:ssh` cmds: - task: molecule:ssh:{{if .CLI_ARGS}}cli{{else}}prompt{{end}} molecule:ssh:cli: deps: - molecule:dependencies - :install:software:sentry log: error: Errors encountered while running the SSH Molecule test start: Running the Molecule test over SSH success: Successfully ran the Molecule test over SSH cmds: - | set -o pipefail {{.MOLECULE_TEST_OPTIONS}} {{.PYTHON_HANDLE}}molecule test -s remote 2&>1 | tee debug.log || EXIT_CODE=$? molecule:ssh:prompt: vars: MARKDOWN: | # Remote Ansible Molecule Test via SSH This testing option is provided for cases where you would like to remotely test the Ansible play on remote machines via SSH. The prompts will ask you for the host IP address or FQDN, user, and password. Before running this test, you should ensure that you can already connect to the machine via SSH (i.e. the ~/.ssh keys should already be set up). This test assumes that SSH does not require any passwords to establish the connection. cmds: - task: :log:markdown vars: MARKDOWN: '{{.MARKDOWN}}' - echo 'This is incomplete - try again another time' - exit 1 - task: molecule:ssh:prompt:continue molecule:ssh:prompt:continue: interactive: true todo: https://gitlab.com/megabyte-labs/common/ansible/-/blob/310e721494c7395e2dae0c95462a42d9240fc167/.config/scripts/prompts/molecule/ssh.js prompt: type: input message: What is the target's IP address or FQDN? validate: sh: > [[ '{{.ANSWER}}' =~ ^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$ ]] || [[ '{{.ANSWER}}' =~ ^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$ ]] answer: vars: TARGET_HOST: '{{.ANSWER}}' prompt: type: input message: What port should the SSH connection be made over? default: 22 validate: sh: > [[ '{{.ANSWER}}' =~ ^[0-9]*$ ]] answer: vars: TARGET_PORT: '{{.ANSWER}}' prompt: type: input message: What is the username of a user that has both sudo and SSH privileges? default: root validate: sh: > [[ '{{.ANSWER}}' =~ ^[a-z_]([a-z0-9_-]{0,31}|[a-z0-9_-]{0,30}\$)$ ]] answer: env: PASSWORD_TMP: sh: mktemp cmds: - | if [ '{{.ANSWER}}' != 'root' ]; then task ansible:test:molecule:ssh:prompt:password -- "$PASSWORD_TMP" fi - task: molecule:ssh:cli env: ANSIBLE_ENABLE_TASK_DEBUGGER: 'true' TEST_BECOME_PASSWORD: sh: cat "$PASSWORD_TMP" TEST_HOST: '{{.TARGET_HOST}}' TEST_PASSWORD: sh: cat "$PASSWORD_TMP" TEST_PORT: sh: '{{.TARGET_PORT}}' TEST_SSH_USER: '{{.ANSWER}}' TEST_USER: '{{.ANSWER}}' molecule:ssh:prompt:password: interactive: true prompt: type: input message: What is the user's sudo password? answer: cmds: - echo '{{.ANSWER}}' > {{.CLI_ARGS}} molecule:virtualbox: desc: Runs a full E2E Molecule test for all supported operating systems hide: '{{ne .REPOSITORY_TYPE "ansible"}}' summary: | # Run a full E2E Molecule test for all supported operating systems This task uses VirtualBox to run tests for all of our supported operating systems in parallel. It is very RAM intensive so, if you want to run this, your computer should have _at least 32GB of RAM_. **Opens a prompt:** `task ansible:test:molecule:virtualbox` **Generate the compatibility matrix used in the README.md:** `task ansible:test:molecule:virtualbox:matrix` cmds: - task: molecule:virtualbox:{{if .CLI_ARGS}}cli{{else}}prompt{{end}} # yamllint disable rule:truthy molecule:virtualbox:cli: deps: - molecule:dependencies - :install:software:sentry - :install:software:sshpass - :install:software:vagrant - :install:software:virtualbox env: OBJC_DISABLE_INITIALIZE_FORK_SAFETY: YES log: error: Errors encountered while running the `{{.CLI_ARGS}}` VirtualBox Molecule test start: Running a VirtualBox Molecule test on platforms in the `{{.CLI_ARGS}}` group success: Finished running the `{{.CLI_ARGS}}` VirtualBox Molecule test cmds: - | {{.MOLECULE_TEST_OPTIONS}} MOLECULE_GROUP="{{.CLI_ARGS}}" {{.PYTHON_HANDLE}}molecule test 2&>1 | tee debug.log || EXIT_CODE=$? molecule:virtualbox:converge: desc: Provisions a desktop VirtualBox VM and then runs a Molecule test hide: '{{ne .REPOSITORY_TYPE "ansible"}}' summary: | # Provision a desktop VirtualBox VM and then run a Molecule test This task opens a VM with an operating system of your choosing and then tests the project's play against it. It then leaves the VM open for inspection. **Example with interactive prompt for VM type:** `task test:molecule` **Example usage bypassing prompt:** `task test:molecule -- ArchLinux` ## Available scenarios: * ArchLinux * CentOS * Debian * Fedora * macOS * Ubuntu * Windows cmds: - task: molecule:virtualbox:converge:{{if .CLI_ARGS}}cli{{else}}prompt{{end}} molecule:virtualbox:converge:cli: deps: - molecule:dependencies - :install:software:sentry - :install:software:sshpass - :install:software:vagrant - :install:software:virtualbox env: OBJC_DISABLE_INITIALIZE_FORK_SAFETY: YES log: error: Errors were encountered while running the `{{.CLI_ARGS}}` VirtualBox Molecule converge play start: Running the `{{.CLI_ARGS}}` VirtualBox Molecule converge play (this will leave the VirtualBox instance open for inspection) success: Finished running the `{{.CLI_ARGS}}` VirtualBox Molecule converge play (you are encouraged to inspect the VM) cmds: - | set -o pipefail {{.MOLECULE_TEST_OPTIONS}} MOLECULE_GROUP={{.CLI_ARGS}} {{.PYTHON_HANDLE}}molecule converge -s desktop 2&>1 | tee debug.log || EXIT_CODE=$? molecule:virtualbox:converge:prompt: vars: MARKDOWN: | # Desktop Ansible Molecule Test via VirtualBox Choose a desktop environment below to run the Ansible play on. After choosing, a VirtualBox VM will be created. Then, the Ansible play will run on the VM. After it is done, the VM will be left open for inspection. Please do get carried away ensuring everything is working as expected and looking for configuration optimizations that can be made. The operating systems should all be the latest stable release but might not always be the latest version. cmds: - task: :log:markdown vars: MARKDOWN: '{{.MARKDOWN}}' - task: molecule:virtualbox:converge:prompt:continue molecule:virtualbox:converge:prompt:continue: interactive: true deps: - :install:software:jq - :install:software:yq vars: VIRTUALBOX_OPTIONS: sh: yq eval -o=j '.groups' molecule/desktop/molecule.yml | jq -r 'keys' prompt: type: select message: Which desktop operating system would you like to test the Ansible play against? options: '{{.VIRTUALBOX_OPTIONS}}' answer: cmds: - task: molecule:virtualbox:converge:cli vars: CLI_ARGS: '{{.ANSWER}}' env: ANSIBLE_ENABLE_TASK_DEBUGGER: 'true' - task: allure:report preconditions: - sh: test -f molecule/desktop/molecule.yml msg: The `molecule/desktop/molecule.yml` file must be present and in the proper format molecule:virtualbox:matrix: deps: - molecule:dependencies - :install:software:sentry - :install:software:sshpass - :install:software:vagrant - :install:software:virtualbox vars: MOLECULE_DATE: sh: date '+%Y-%m-%d' OBJC_DISABLE_INITIALIZE_FORK_SAFETY: YES log: error: Errors were encountered while running the full E2E test (see `{{.MOLECULE_LOGS_PATH}}/{{.MOLECULE_DATE}}-default.txt` for details) start: Running a full E2E test with VirtualBox (results will be saved to `{{.MOLECULE_LOGS_PATH}}/{{.MOLECULE_DATE}}-default.txt`) success: Finished running the full E2E test (results are in `{{.MOLECULE_LOGS_PATH}}/{{.MOLECULE_DATE}}-default.txt`) cmds: - mkdir -p {{.MOLECULE_LOGS_PATH}} - | set -o pipefail PY_COLORS=0 {{.MOLECULE_TEST_OPTIONS}} {{.PYTHON_HANDLE}}molecule test 2&>1 | \ tee '{{.MOLECULE_LOGS_PATH}}/{{.MOLECULE_DATE}}-default.txt' || EXIT_CODE=$? # yamllint enable rule:truthy molecule:virtualbox:prompt: vars: MARKDOWN: | # Ansible Molecule Test via Headless VirtualBox Instances This particular type of test is the best method for testing Ansible plays. It uses VirtualBox and utilizes headless images. Despite that, running the test across all the supported operating systems is RAM intensive. Ideally, you should have at least 16GB of RAM to run all the tests at once. This type of test is used to generate the compatibility chart so the results of this type of test have the final say. You do not need to run the tests on all instances at once. Use the prompt below to narrow your test scope. cmds: - task: :log:markdown vars: MARKDOWN: '{{.MARKDOWN}}' - task: molecule:virtualbox:prompt:continue molecule:virtualbox:prompt:continue: interactive: true deps: - :install:software:jq - :install:software:yq vars: VIRTUALBOX_OPTIONS: sh: yq eval -o=j '.groups' molecule/default/molecule.yml | jq -r 'keys' prompt: type: select message: What environment(s) would you like to target with this test? options: '{{.VIRTUALBOX_OPTIONS}}' answer: cmds: - task: molecule:virtualbox:cli vars: CLI_ARGS: '{{.ANSWER}}' env: ANSIBLE_ENABLE_TASK_DEBUGGER: 'true' - task: allure:report preconditions: - sh: test -f molecule/default/molecule.yml msg: The `molecule/default/molecule.yml` file must be present and in the proper format prompt: vars: MARKDOWN: | # Molecule Test There are currently six different options for running Molecule tests. ## 1. VirtualBox Headless Runs tests using VirtualBox headless VMs. It is the test type used to generate the compatibility chart. ## 2. VirtualBox Desktop Runs tests using a VirtualBox desktop version VM. Use this type of test to run the Ansible play and then open the VirtualBox VM to smoke test the software. ## 3. Docker Utilizes Docker to test the Ansible play. It has some limitations such as not being able to test snap installations on all operating systems. It also can only run tests on Linux environments. This is, however, the fastest way to test roles and requires the least amount of RAM. ## 4. Local Runs the Ansible play on the local machine. Use this to run the Ansible play on your local machine. You might use this if you want to inspect the software after running the play. ## 5. SSH Runs the Ansible play on a remote machine after connecting via SSH. This requires that you already have the SSH credentials configured (i.e. ~/.ssh is setup). ## 6. Google Cloud Platform Provisions Google Cloud Platform instances and tests the Ansible play on them. This test requires that you have access to a GCP account and that the proper credentials are in place. For help, see [this guide](https://github.com/ProfessorManhattan/molecule-ansible-google-cloud/blob/master/README.md). Without the environment variables mentioned in the guide set, this task will fail. ## Note on Debugging All of the tests below (except GCP) enable the built-in Ansible debugger. If a task fails, the STDOUT will freeze and you will be able to enter a few different commands. For example, if you enter "r", then Ansible will run the task again. For more information on the Ansible debugger (including available commands), see https://docs.ansible.com/ansible/latest/user_guide/playbooks_debugger.html#available-debug-commands. cmds: - task: :log:markdown vars: MARKDOWN: '{{.MARKDOWN}}' - task: prompt:continue prompt:continue: interactive: true prompt: type: select message: What type of test would you like to perform? options: - VirtualBox Headless - VirtualBox Desktop - Docker - Local - SSH - Google Cloud Platform answer: cmds: - task: prompt:continue:task vars: MOLECULE_TASK: sh: | if [ {{.ANSWER}} == 'VirtualBox Headless' ]; then echo 'virtualbox:prompt' elif [ '{{.ANSWER}}' == 'VirtualBox Desktop' ]; then echo 'virtualbox:converge:prompt' elif [ '{{.ANSWER}}' == 'Docker' ]; then echo 'docker:prompt' elif [ '{{.ANSWER}}' == 'Local' ]; then echo 'local' elif [ '{{.ANSWER}}' == 'SSH' ]; then echo 'ssh:prompt' elif [ '{{.ANSWER}}' == 'Google Cloud Platform' ]; then echo 'gcp' fi - task: allure:report prompt:continue:task: cmds: - task: molecule:{{.MOLECULE_TASK}} env: ANSIBLE_ENABLE_TASK_DEBUGGER: 'true' vagrant: desc: Runs the playbook using Vagrant hide: '{{ne (print .REPOSITORY_TYPE "-" .REPOSITORY_SUBTYPE) "ansible-role"}}' summary: | # Run the playbook using Vagrant Using Vagrant, you can pick and choose which operating system and virtualization provider you want to use to test the playbook. ## Possible virtualization providers: * hyperv * libvirt * parallels * virtualbox * vmware_fusion * vmware_workstation ## Possible operating systems: * archlinux * centos * debian * fedora * macos * ubuntu * windows **Example opening interactive prompt:** `task test:vagrant` **Example bypassing interactive prompt:** `task test:vagrant -- --provider=vmware_workstation windows` cmds: - task: vagrant:{{if .CLI_ARGS}}cli{{else}}prompt{{end}} vagrant:cli: deps: - task: :install:python:requirements vars: INSTALL_OPTIONS: --no-dev - :install:software:sentry - :install:software:sshpass - :install:software:vagrant - :install:software:virtualbox log: error: Encountered error when running `vagrant up {{.CLI_ARGS}}` start: Running `vagrant up {{.CLI_ARGS}}` success: Successfully ran `vagrant up {{.CLI_ARGS}}` cmds: - | set -o pipefail vagrant up {{.CLI_ARGS}} 2&>1 | tee debug.log || EXIT_CODE=$? if [ "$EXIT_CODE" != '0' ]; then fi vagrant:prompt: vars: MARKDOWN: | # Launch VM via Vagrant and Run Playbook Use the following prompts to select the type of operating system and the virtualization platform you wish to use with Vagrant. After you make your choice the corresponding environment will be provisioned with Vagrant. The options are generated by inspecting your system for which virtualization platforms are installed. The supported virtualization platforms are: * **KVM** - Shows if `qemu-system-x86_64` command is available * **Parallels** (macOS only) - Shows if `Parallels Desktop.app` is installed * **VirtualBox** - Shows if `vboxmanage` command is available * **VMWare Fusion** (macOS only) - Shows if `vmrun` command is available * **VMWare Workstation** (Linux only) - Shows if `vmware` command is available cmds: - task: :log:markdown vars: MARKDOWN: '{{.MARKDOWN}}' - task: vagrant:prompt:continue vagrant:prompt:continue: deps: - :install:software:jq interactive: true vars: PROMPT_OPTIONS: sh: | TMP="$(mktemp)" if type qemu-system-x86_64 &> /dev/null; then echo 'KVM' > "$TMP" fi if [ '{{OS}}' == 'darwin' ] && mdfind -name 'Parallels Desktop.app' &> /dev/null; then echo 'Parallels' > "$TMP" fi if type vboxmanage &> /dev/null; then echo 'VirtualBox' > "$TMP" fi if [ '{{OS}}' == 'linux' ] && type vmware &> /dev/null; then echo 'VMWare Workstation' > "$TMP" fi if [ '{{OS}}' == 'darwin' ] && type vmrun &> /dev/null; then echo 'VMWare Fusion' > "$TMP" fi jq -R -s -c 'split("\n")' < "$TMP" prompt: type: select message: Which virtualization platform would you like to use? options: '{{.PROMPT_OPTIONS}}' answer: vars: VIRTUALIZATION_PLATFORM: '{{.ANSWER}}' prompt: type: select message: Which desktop operating system would you like to provision? options: - ArchLinux - CentOS - Debian - Fedora - macOS - Ubuntu - Windows answer: cmds: - task: vagrant:cli vars: CLI_ARGS: --provider={{.VIRTUALIZATION_PLATFORM}} {{.ANSWER}}