From 6594566e036961d86e8474e31661c144376540df Mon Sep 17 00:00:00 2001 From: Jeff Geerling Date: Wed, 12 Aug 2020 14:52:43 -0500 Subject: [PATCH 01/22] Fix broken molecule test on older Travis CI default Docker version. --- tests/molecule.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/molecule.sh b/tests/molecule.sh index 7c7e1500..62af8268 100755 --- a/tests/molecule.sh +++ b/tests/molecule.sh @@ -8,6 +8,9 @@ sudo apt-get update sudo apt-get install -y python3-pip python3-setuptools pip3 install --upgrade setuptools pip +# Upgrade Docker to work with docker-py. +curl https://gist.githubusercontent.com/geerlingguy/ce883ad4aec6a5f1187ef93bd338511e/raw/36612d28981d92863f839c5aefe5b7dd7193d6c6/travis-ci-docker-upgrade.sh | sudo bash + # Install dependencies. sudo pip3 install ansible molecule ansible-lint yamllint docker From 583d2cb4f0fde042eae522a95878624d804a4082 Mon Sep 17 00:00:00 2001 From: Jeff Geerling Date: Fri, 14 Aug 2020 10:24:57 -0500 Subject: [PATCH 02/22] Fixes #314: Explicitly define 'mode' for web page molecule example. --- molecule/main.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/molecule/main.yml b/molecule/main.yml index dddde73e..cdf75a80 100644 --- a/molecule/main.yml +++ b/molecule/main.yml @@ -34,6 +34,7 @@ Hello world! dest: "/var/www/html/index.html" + mode: 0664 notify: restart apache - name: Ensure Apache is running and starts at boot. From 6c0ea316ca70a7fab9e9efa2c4afe164d7102b42 Mon Sep 17 00:00:00 2001 From: Jeff Geerling Date: Mon, 31 Aug 2020 10:56:21 -0500 Subject: [PATCH 03/22] Don't use sudo with pip3 installs in test environments. --- tests/collection.sh | 2 +- tests/molecule.sh | 2 +- tests/orchestration.sh | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/collection.sh b/tests/collection.sh index 77cfa7b9..d7ed65a1 100755 --- a/tests/collection.sh +++ b/tests/collection.sh @@ -9,7 +9,7 @@ sudo apt-get install -y python3-pip python3-setuptools pip3 install --upgrade setuptools pip # Install dependencies. -sudo pip3 install ansible +pip3 install ansible cd collection diff --git a/tests/molecule.sh b/tests/molecule.sh index 62af8268..dd24428d 100755 --- a/tests/molecule.sh +++ b/tests/molecule.sh @@ -12,7 +12,7 @@ pip3 install --upgrade setuptools pip curl https://gist.githubusercontent.com/geerlingguy/ce883ad4aec6a5f1187ef93bd338511e/raw/36612d28981d92863f839c5aefe5b7dd7193d6c6/travis-ci-docker-upgrade.sh | sudo bash # Install dependencies. -sudo pip3 install ansible molecule ansible-lint yamllint docker +pip3 install ansible molecule ansible-lint yamllint docker cd molecule diff --git a/tests/orchestration.sh b/tests/orchestration.sh index e602bac2..5dced5ba 100755 --- a/tests/orchestration.sh +++ b/tests/orchestration.sh @@ -9,7 +9,7 @@ sudo apt-get install -y python3-pip python3-setuptools pip3 install --upgrade setuptools pip # Install dependencies. -sudo pip3 install ansible +pip3 install ansible cd orchestration/scripts From 28c2b5f4d5afc4a347f225884eeab87431ec915a Mon Sep 17 00:00:00 2001 From: Jeff Geerling Date: Mon, 31 Aug 2020 11:10:15 -0500 Subject: [PATCH 04/22] Attempt to fix pip3 installs of ansible and molecule. --- tests/collection.sh | 1 - tests/molecule.sh | 1 - tests/orchestration.sh | 1 - 3 files changed, 3 deletions(-) diff --git a/tests/collection.sh b/tests/collection.sh index d7ed65a1..f41f51d2 100755 --- a/tests/collection.sh +++ b/tests/collection.sh @@ -6,7 +6,6 @@ set -e # Make sure pip3 is available. sudo apt-get update sudo apt-get install -y python3-pip python3-setuptools -pip3 install --upgrade setuptools pip # Install dependencies. pip3 install ansible diff --git a/tests/molecule.sh b/tests/molecule.sh index dd24428d..f841a121 100755 --- a/tests/molecule.sh +++ b/tests/molecule.sh @@ -6,7 +6,6 @@ set -e # Make sure pip3 is available. sudo apt-get update sudo apt-get install -y python3-pip python3-setuptools -pip3 install --upgrade setuptools pip # Upgrade Docker to work with docker-py. curl https://gist.githubusercontent.com/geerlingguy/ce883ad4aec6a5f1187ef93bd338511e/raw/36612d28981d92863f839c5aefe5b7dd7193d6c6/travis-ci-docker-upgrade.sh | sudo bash diff --git a/tests/orchestration.sh b/tests/orchestration.sh index 5dced5ba..6ee6cfcd 100755 --- a/tests/orchestration.sh +++ b/tests/orchestration.sh @@ -6,7 +6,6 @@ set -e # Make sure pip3 is available. sudo apt-get update sudo apt-get install -y python3-pip python3-setuptools -pip3 install --upgrade setuptools pip # Install dependencies. pip3 install ansible From 281b96b1ca8f17145292b9ebb14ff8cba34e1667 Mon Sep 17 00:00:00 2001 From: Jeff Geerling Date: Mon, 31 Aug 2020 13:47:55 -0500 Subject: [PATCH 05/22] Try manually installing wheel for molecule Travis CI test. --- tests/molecule.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/molecule.sh b/tests/molecule.sh index f841a121..f32028d1 100755 --- a/tests/molecule.sh +++ b/tests/molecule.sh @@ -11,7 +11,7 @@ sudo apt-get install -y python3-pip python3-setuptools curl https://gist.githubusercontent.com/geerlingguy/ce883ad4aec6a5f1187ef93bd338511e/raw/36612d28981d92863f839c5aefe5b7dd7193d6c6/travis-ci-docker-upgrade.sh | sudo bash # Install dependencies. -pip3 install ansible molecule ansible-lint yamllint docker +pip3 install wheel ansible molecule ansible-lint yamllint docker cd molecule From 1933758ff50d29e4a7590763ff81016424010e96 Mon Sep 17 00:00:00 2001 From: Jeff Geerling Date: Mon, 31 Aug 2020 14:08:54 -0500 Subject: [PATCH 06/22] Update build environment to focal fossa. --- .travis.yml | 1 + tests/collection.sh | 4 ---- tests/molecule.sh | 9 +-------- tests/orchestration.sh | 4 ---- 4 files changed, 2 insertions(+), 16 deletions(-) diff --git a/.travis.yml b/.travis.yml index 85dee5ff..3320e7fc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,6 @@ --- services: docker +dist: focal branches: only: diff --git a/tests/collection.sh b/tests/collection.sh index f41f51d2..b65cd37a 100755 --- a/tests/collection.sh +++ b/tests/collection.sh @@ -3,10 +3,6 @@ # Collection playbook tests. set -e -# Make sure pip3 is available. -sudo apt-get update -sudo apt-get install -y python3-pip python3-setuptools - # Install dependencies. pip3 install ansible diff --git a/tests/molecule.sh b/tests/molecule.sh index f32028d1..6de86bc6 100755 --- a/tests/molecule.sh +++ b/tests/molecule.sh @@ -3,15 +3,8 @@ # Molecule playbook tests. set -e -# Make sure pip3 is available. -sudo apt-get update -sudo apt-get install -y python3-pip python3-setuptools - -# Upgrade Docker to work with docker-py. -curl https://gist.githubusercontent.com/geerlingguy/ce883ad4aec6a5f1187ef93bd338511e/raw/36612d28981d92863f839c5aefe5b7dd7193d6c6/travis-ci-docker-upgrade.sh | sudo bash - # Install dependencies. -pip3 install wheel ansible molecule ansible-lint yamllint docker +pip3 install ansible molecule ansible-lint yamllint docker cd molecule diff --git a/tests/orchestration.sh b/tests/orchestration.sh index 6ee6cfcd..b221b94a 100755 --- a/tests/orchestration.sh +++ b/tests/orchestration.sh @@ -3,10 +3,6 @@ # Orchestration tests. set -e -# Make sure pip3 is available. -sudo apt-get update -sudo apt-get install -y python3-pip python3-setuptools - # Install dependencies. pip3 install ansible From 5f2aee8fcf7fb6bcf6b5af793cd9fc62d73052e7 Mon Sep 17 00:00:00 2001 From: Jeff Geerling Date: Fri, 11 Sep 2020 11:30:18 -0500 Subject: [PATCH 07/22] Test if molecule[docker] works correctly. --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bf79ab7c..a54e34c3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,7 +27,7 @@ jobs: python-version: '3.x' - name: Install test dependencies. - run: pip3 install molecule docker yamllint ansible-lint + run: pip3 install molecule[docker] yamllint ansible-lint - name: Run Molecule tests. run: molecule test From d7365df79b6412be2d2e7cea2d8e50729a3e8320 Mon Sep 17 00:00:00 2001 From: Jeff Geerling Date: Wed, 23 Sep 2020 14:38:01 -0500 Subject: [PATCH 08/22] Make sure apt caches are updated more frequently for deployments and elk tests. --- tests/deployments.yml | 6 ++++++ tests/elk.yml | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/tests/deployments.yml b/tests/deployments.yml index e2f342b8..f8a67636 100644 --- a/tests/deployments.yml +++ b/tests/deployments.yml @@ -1,4 +1,10 @@ --- +- hosts: all + + pre_tasks: + - name: Update the apt cache. + apt: update_cache=yes cache_valid_time=600 + # Deployments test. - import_playbook: ../deployments/playbooks/provision.yml - import_playbook: ../deployments/playbooks/deploy.yml diff --git a/tests/elk.yml b/tests/elk.yml index 1806156d..387a9870 100644 --- a/tests/elk.yml +++ b/tests/elk.yml @@ -1,6 +1,10 @@ --- - hosts: all + pre_tasks: + - name: Update the apt cache. + apt: update_cache=yes cache_valid_time=600 + tasks: - add_host: name: localhost From deae30739b10f02aef9722437427a7415ea1054b Mon Sep 17 00:00:00 2001 From: Jeff Geerling Date: Mon, 28 Sep 2020 11:11:34 -0500 Subject: [PATCH 09/22] Bump Elasticsearch role requirement version. --- elk/requirements.yml | 2 +- tests/requirements.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/elk/requirements.yml b/elk/requirements.yml index 86772909..99ccad88 100644 --- a/elk/requirements.yml +++ b/elk/requirements.yml @@ -4,7 +4,7 @@ roles: - name: geerlingguy.nginx - name: geerlingguy.pip - name: geerlingguy.elasticsearch - version: 4.1.1 + version: 5.0.0 - name: geerlingguy.elasticsearch-curator version: 2.1.0 - name: geerlingguy.kibana diff --git a/tests/requirements.yml b/tests/requirements.yml index 54546552..77305aab 100644 --- a/tests/requirements.yml +++ b/tests/requirements.yml @@ -18,7 +18,7 @@ roles: - name: geerlingguy.solr - name: geerlingguy.elasticsearch - version: 4.1.1 + version: 5.0.0 - name: geerlingguy.elasticsearch-curator version: 2.1.0 - name: geerlingguy.kibana From 4492e96a2c8f79471cc3b308c777cbd9426598f2 Mon Sep 17 00:00:00 2001 From: Jeff Geerling Date: Fri, 16 Oct 2020 11:54:28 -0500 Subject: [PATCH 10/22] Fix broken test build due to molecule docker dependency missing. --- tests/molecule.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/molecule.sh b/tests/molecule.sh index 6de86bc6..57d0c697 100755 --- a/tests/molecule.sh +++ b/tests/molecule.sh @@ -4,7 +4,7 @@ set -e # Install dependencies. -pip3 install ansible molecule ansible-lint yamllint docker +pip3 install ansible molecule[docker] ansible-lint yamllint docker cd molecule From 50913b62dd8f396fddbec214a58e3ee2f45daf04 Mon Sep 17 00:00:00 2001 From: Jeff Geerling Date: Mon, 26 Oct 2020 20:03:32 -0500 Subject: [PATCH 11/22] Switch from travis-ci.org to travis-ci.com. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5a874a8f..5abb4db4 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Ansible for DevOps Examples -[![Build Status](https://travis-ci.org/geerlingguy/ansible-for-devops.svg?branch=master)](https://travis-ci.org/geerlingguy/ansible-for-devops) [![GitHub CI](https://github.com/geerlingguy/ansible-for-devops/workflows/CI/badge.svg?branch=master&event=push)](https://github.com/geerlingguy/ansible-for-devops/actions) +[![Build Status](https://travis-ci.com/geerlingguy/ansible-for-devops.svg?branch=master)](https://travis-ci.com/geerlingguy/ansible-for-devops) [![GitHub CI](https://github.com/geerlingguy/ansible-for-devops/workflows/CI/badge.svg?branch=master&event=push)](https://github.com/geerlingguy/ansible-for-devops/actions) This repository contains Ansible examples developed to support different sections of [Ansible for DevOps](https://www.ansiblefordevops.com/), a book on [Ansible](http://www.ansible.com/) by [Jeff Geerling](https://www.jeffgeerling.com/). From 12259fbef65b1228493815548cf29fa6036897fa Mon Sep 17 00:00:00 2001 From: Jeff Geerling Date: Mon, 7 Dec 2020 22:48:21 -0600 Subject: [PATCH 12/22] Issue #359: Convert tests to use GitHub Actions for CI. --- .github/workflows/ci.yml | 129 ++++++++++++++++++++++++++---- .github/workflows/molecule-ci.yml | 38 +++++++++ .travis.yml | 110 ------------------------- README.md | 4 +- 4 files changed, 152 insertions(+), 129 deletions(-) create mode 100644 .github/workflows/molecule-ci.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a54e34c3..a34a617c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -5,34 +5,129 @@ name: CI push: branches: - master + schedule: + - cron: "10 2 * * 0" jobs: + scripts: + name: Scripts + runs-on: ubuntu-latest + strategy: + matrix: + include: + - test_script: collection + - test_script: molecule + - test_script: orchestration + + steps: + - uses: actions/checkout@v2 + + - uses: actions/setup-python@v2 + with: + python-version: '3.x' - test: - name: Molecule + - name: Run test script. + run: tests/${{ matrix.test_script }}.sh + + playbooks: + name: Playbooks runs-on: ubuntu-latest strategy: matrix: - distro: - - centos8 - - debian10 + include: + - playbook: deployments.yml + distro: ubuntu2004 + test_idempotence: false + + # TODO: Not easy to test in CI at this time. + # - playbook: deployments-balancer.yml + # distro: ubuntu2004 + + - playbook: deployments-rolling.yml + distro: ubuntu2004 + + - playbook: docker.yml + distro: ubuntu2004 + test_idempotence: false + + - playbook: docker-flask.yml + distro: ubuntu2004 + test_idempotence: false + + - playbook: docker-hubot.yml + distro: ubuntu2004 + test_idempotence: false + + - playbook: drupal.yml + distro: ubuntu2004 + + # TODO: Not easy to test in CI at this time. + # - playbook: dynamic-inventory.yml + # distro: ubuntu2004 + + - playbook: elk.yml + distro: ubuntu2004 + + - playbook: first-ansible-playbook.yml + distro: centos7 + + - playbook: galaxy-role-servers.yml + distro: ubuntu2004 + + # TODO: Not easy to test in CI at this time. + # - playbook: gluster.yml + # distro: ubuntu2004 + + - playbook: https-self-signed.yml + distro: ubuntu2004 + + - playbook: https-nginx-proxy.yml + distro: debian10 + + - playbook: includes.yml + distro: ubuntu2004 + + - playbook: jenkins.yml + distro: ubuntu2004 + + # TODO: Not easy to test in CI at this time. + # - playbook: kubernetes.yml + # distro: debian9 + + # TODO: Not easy to test in CI at this time. + # - playbook: lamp-infrastructure.yml + # distro: ubuntu2004 + + - playbook: nodejs.yml + distro: centos7 + + - playbook: nodejs-role.yml + distro: centos7 + + - playbook: security.yml + distro: centos8 + + - playbook: solr.yml + distro: ubuntu2004 + + - playbook: test-plugin.yml + distro: centos7 steps: - - name: Check out the codebase. - uses: actions/checkout@v2 + - uses: actions/checkout@v2 - - name: Set up Python 3. - uses: actions/setup-python@v2 + - uses: actions/setup-python@v2 with: python-version: '3.x' - - name: Install test dependencies. - run: pip3 install molecule[docker] yamllint ansible-lint + - name: Download test shim. + run: | + wget -O tests/test.sh https://gist.githubusercontent.com/geerlingguy/73ef1e5ee45d8694570f334be385e181/raw/ + chmod +x tests/test.sh - - name: Run Molecule tests. - run: molecule test + - name: Run playbook with test shim. + run: tests/test.sh env: - PY_COLORS: '1' - ANSIBLE_FORCE_COLOR: '1' - MOLECULE_DISTRO: ${{ matrix.distro }} - working-directory: molecule + playbook: ${{ matrix.playbook }} + distro: ${{ matrix.distro }} + test_idempotence: ${{ matrix.test_idempotence }} diff --git a/.github/workflows/molecule-ci.yml b/.github/workflows/molecule-ci.yml new file mode 100644 index 00000000..a54e34c3 --- /dev/null +++ b/.github/workflows/molecule-ci.yml @@ -0,0 +1,38 @@ +--- +name: CI +'on': + pull_request: + push: + branches: + - master + +jobs: + + test: + name: Molecule + runs-on: ubuntu-latest + strategy: + matrix: + distro: + - centos8 + - debian10 + + steps: + - name: Check out the codebase. + uses: actions/checkout@v2 + + - name: Set up Python 3. + uses: actions/setup-python@v2 + with: + python-version: '3.x' + + - name: Install test dependencies. + run: pip3 install molecule[docker] yamllint ansible-lint + + - name: Run Molecule tests. + run: molecule test + env: + PY_COLORS: '1' + ANSIBLE_FORCE_COLOR: '1' + MOLECULE_DISTRO: ${{ matrix.distro }} + working-directory: molecule diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 3320e7fc..00000000 --- a/.travis.yml +++ /dev/null @@ -1,110 +0,0 @@ ---- -services: docker -dist: focal - -branches: - only: - - master - -env: - - shell_script: collection.sh - - # Run each test playbook in a separate environment. - - playbook: deployments.yml - distro: ubuntu2004 - test_idempotence: false - - # TODO: Not easy to test in CI at this time. - # - playbook: deployments-balancer.yml - # distro: ubuntu2004 - - - playbook: deployments-rolling.yml - distro: ubuntu2004 - - - playbook: docker.yml - distro: ubuntu2004 - test_idempotence: false - - - playbook: docker-flask.yml - distro: ubuntu2004 - test_idempotence: false - - - playbook: docker-hubot.yml - distro: ubuntu2004 - test_idempotence: false - - - playbook: drupal.yml - distro: ubuntu2004 - - # TODO: Not easy to test in CI at this time. - # - playbook: dynamic-inventory.yml - # distro: ubuntu2004 - - - playbook: elk.yml - distro: ubuntu2004 - - - playbook: first-ansible-playbook.yml - distro: centos7 - - - playbook: galaxy-role-servers.yml - distro: ubuntu2004 - - # TODO: Not easy to test in CI at this time. - # - playbook: gluster.yml - # distro: ubuntu2004 - - - playbook: https-self-signed.yml - distro: ubuntu2004 - - - playbook: https-nginx-proxy.yml - distro: debian10 - - - playbook: includes.yml - distro: ubuntu2004 - - - playbook: jenkins.yml - distro: ubuntu2004 - - # TODO: Not easy to test in CI at this time. - # - playbook: kubernetes.yml - # distro: debian9 - - # TODO: Not easy to test in CI at this time. - # - playbook: lamp-infrastructure.yml - # distro: ubuntu2004 - - - shell_script: molecule.sh - - - playbook: nodejs.yml - distro: centos7 - - - playbook: nodejs-role.yml - distro: centos7 - - - shell_script: orchestration.sh - - - playbook: security.yml - distro: centos8 - - - playbook: solr.yml - distro: ubuntu2004 - - - playbook: test-plugin.yml - distro: centos7 - -script: - # Use test shim and run playbook if playbook is provided. - - | - if [ ! -z "$playbook" ]; then - # Download test shim. - wget -O ${PWD}/tests/test.sh https://gist.githubusercontent.com/geerlingguy/73ef1e5ee45d8694570f334be385e181/raw/ - chmod +x ${PWD}/tests/test.sh - # Run tests. - ${PWD}/tests/test.sh - fi - - # Run script directly if script is provided. - - | - if [ ! -z "$shell_script" ]; then - ${PWD}/tests/${shell_script} - fi diff --git a/README.md b/README.md index 5abb4db4..baabf067 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Ansible for DevOps Examples -[![Build Status](https://travis-ci.com/geerlingguy/ansible-for-devops.svg?branch=master)](https://travis-ci.com/geerlingguy/ansible-for-devops) [![GitHub CI](https://github.com/geerlingguy/ansible-for-devops/workflows/CI/badge.svg?branch=master&event=push)](https://github.com/geerlingguy/ansible-for-devops/actions) +[![CI](https://github.com/geerlingguy/ansible-for-devops/workflows/CI/badge.svg?branch=master&event=push)](https://github.com/geerlingguy/ansible-for-devops/actions?query=workflow%3ACI) [![Molecule CI](https://github.com/geerlingguy/ansible-for-devops/workflows/Molecule%20CI/badge.svg?branch=master&event=push)](https://github.com/geerlingguy/ansible-for-devops/actions) This repository contains Ansible examples developed to support different sections of [Ansible for DevOps](https://www.ansiblefordevops.com/), a book on [Ansible](http://www.ansible.com/) by [Jeff Geerling](https://www.jeffgeerling.com/). @@ -72,7 +72,7 @@ Here is an outline of all the examples contained in this repository, by chapter: ### Chapter 13 - [`molecule`](molecule/): A Molecule example used for testing and developing an Ansible playbook, or for testing in a Continuous Integration (CI) environment. - - [`ci.yml` GitHub Actions workflow](.github/workflows/ci.yml): A GitHub Actions workflow which runs the `molecule` example in a CI environment. + - [`molecule-ci.yml` GitHub Actions workflow](.github/workflows/molecule-ci.yml): A GitHub Actions workflow which runs the `molecule` example in a CI environment. ### Chapter 14 From 3a24b6f548e18c05d28bdff828f3a754ec70f5be Mon Sep 17 00:00:00 2001 From: Jeff Geerling Date: Mon, 7 Dec 2020 23:06:51 -0600 Subject: [PATCH 13/22] Minor tweaks to naming things. --- .github/workflows/molecule-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/molecule-ci.yml b/.github/workflows/molecule-ci.yml index a54e34c3..dbf100cd 100644 --- a/.github/workflows/molecule-ci.yml +++ b/.github/workflows/molecule-ci.yml @@ -1,5 +1,5 @@ --- -name: CI +name: Molecule CI 'on': pull_request: push: From ff701b4a3c0a776efc49d786488681f704b0a28d Mon Sep 17 00:00:00 2001 From: Jeff Geerling Date: Mon, 7 Dec 2020 23:11:36 -0600 Subject: [PATCH 14/22] Issue #359: Disable currently-failing test. --- .github/workflows/ci.yml | 6 ++++-- README.md | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a34a617c..71168c87 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -43,8 +43,10 @@ jobs: # - playbook: deployments-balancer.yml # distro: ubuntu2004 - - playbook: deployments-rolling.yml - distro: ubuntu2004 + # TODO: This started failing on GitHub Actions. + # See: https://github.com/geerlingguy/ansible-for-devops/issues/359 + # - playbook: deployments-rolling.yml + # distro: ubuntu2004 - playbook: docker.yml distro: ubuntu2004 diff --git a/README.md b/README.md index baabf067..294e3bcb 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Ansible for DevOps Examples -[![CI](https://github.com/geerlingguy/ansible-for-devops/workflows/CI/badge.svg?branch=master&event=push)](https://github.com/geerlingguy/ansible-for-devops/actions?query=workflow%3ACI) [![Molecule CI](https://github.com/geerlingguy/ansible-for-devops/workflows/Molecule%20CI/badge.svg?branch=master&event=push)](https://github.com/geerlingguy/ansible-for-devops/actions) +[![CI](https://github.com/geerlingguy/ansible-for-devops/workflows/CI/badge.svg?event=push)](https://github.com/geerlingguy/ansible-for-devops/actions?query=workflow%3ACI) [![Molecule CI](https://github.com/geerlingguy/ansible-for-devops/workflows/Molecule%20CI/badge.svg?event=push)](https://github.com/geerlingguy/ansible-for-devops/actions?query=workflow%3A%22Molecule+CI%22) This repository contains Ansible examples developed to support different sections of [Ansible for DevOps](https://www.ansiblefordevops.com/), a book on [Ansible](http://www.ansible.com/) by [Jeff Geerling](https://www.jeffgeerling.com/). From fc55174824268feb8a18f57e99cbe4bf05d7ee3e Mon Sep 17 00:00:00 2001 From: Jeff Geerling Date: Mon, 7 Dec 2020 23:26:39 -0600 Subject: [PATCH 15/22] Issue #359: Disable failing Jenkins test. --- .github/workflows/ci.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 71168c87..42152064 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -89,8 +89,10 @@ jobs: - playbook: includes.yml distro: ubuntu2004 - - playbook: jenkins.yml - distro: ubuntu2004 + # TODO: This started failing on GitHub Actions. + # See: https://github.com/geerlingguy/ansible-for-devops/issues/359 + # - playbook: jenkins.yml + # distro: ubuntu2004 # TODO: Not easy to test in CI at this time. # - playbook: kubernetes.yml From 8929b080959b083356d5dc516ea5754e2374e74a Mon Sep 17 00:00:00 2001 From: Jeff Geerling Date: Mon, 7 Dec 2020 23:35:42 -0600 Subject: [PATCH 16/22] Issue #359: Disable includes.yml Drupal install playbook due to failures. --- .github/workflows/ci.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 42152064..256a9750 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -86,8 +86,10 @@ jobs: - playbook: https-nginx-proxy.yml distro: debian10 - - playbook: includes.yml - distro: ubuntu2004 + # TODO: This started failing on GitHub Actions. + # See: https://github.com/geerlingguy/ansible-for-devops/issues/359 + # - playbook: includes.yml + # distro: ubuntu2004 # TODO: This started failing on GitHub Actions. # See: https://github.com/geerlingguy/ansible-for-devops/issues/359 From 05cce29bf55d1f3a30702f3e7ca40d360c5be6a6 Mon Sep 17 00:00:00 2001 From: Michael Lynch Date: Thu, 14 Jan 2021 06:41:10 -0500 Subject: [PATCH 17/22] Add TinyPilot as a proud sponsor of geerlingguy --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 294e3bcb..6a73a0ae 100644 --- a/README.md +++ b/README.md @@ -94,6 +94,10 @@ Here is an outline of all the examples contained in this repository, by chapter: MIT +## Sponsors + +* [TinyPilot](https://tinypilotkvm.com): An open-source, low-cost KVM over IP for managing your servers. + ## Buy the Book [![Ansible for DevOps Cover](https://s3.amazonaws.com/titlepages.leanpub.com/ansible-for-devops/medium)](https://www.ansiblefordevops.com/) From 333a83bdbf7e5ff28ab69fbf012cbad325e443c0 Mon Sep 17 00:00:00 2001 From: Jeff Geerling Date: Thu, 14 Jan 2021 15:04:50 -0600 Subject: [PATCH 18/22] PR #375: Added note about GitHub sponsors to new sponsor section. --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 6a73a0ae..fc0f33a2 100644 --- a/README.md +++ b/README.md @@ -98,6 +98,8 @@ MIT * [TinyPilot](https://tinypilotkvm.com): An open-source, low-cost KVM over IP for managing your servers. +The above sponsor is [sponsoring Jeff Geerling on GitHub Sponsors](https://github.com/sponsors/geerlingguy). You can sponsor Jeff's work too, to help him continue improving this book and Ansible open source work! + ## Buy the Book [![Ansible for DevOps Cover](https://s3.amazonaws.com/titlepages.leanpub.com/ansible-for-devops/medium)](https://www.ansiblefordevops.com/) From ef08acc51aa2081a7b19eedff3455f49f095923b Mon Sep 17 00:00:00 2001 From: martinliu Date: Sat, 30 Jan 2021 02:56:22 +0800 Subject: [PATCH 19/22] add cn readme.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 待测试 --- first-ansible-playbook/README_CN.md | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 first-ansible-playbook/README_CN.md diff --git a/first-ansible-playbook/README_CN.md b/first-ansible-playbook/README_CN.md new file mode 100644 index 00000000..33c92266 --- /dev/null +++ b/first-ansible-playbook/README_CN.md @@ -0,0 +1,29 @@ +# 第一个 Ansible Playbook 演示虚拟机 + +这个项目旋创建一个虚拟机,并演示了一个非常简单的 Ansible Playbook。 + +## 快速入门指南 + +### 1 - 安装依赖关系(VirtualBox, Vagrant, Ansible)。 + + 1. 下载并安装【VirtualBox】(https://www.virtualbox.org/wiki/Downloads)。 + 2. 下载并安装 [Vagrant](http://www.vagrantup.com/downloads.html)。 + 3. [仅限 Mac/Linux]安装[Ansible](http://docs.ansible.com/intro_installation.html)。 + +Windows用户注意。*本指南假设您使用的是Mac或Linux主机。目前不支持Windows主机。* + +### 2 - 构建虚拟机 + + 1. 下载这个项目,并把它放在你想放的地方。 + 2. 打开终端,cd 到这个目录。 + 4. 4.输入`vagrant up`,让Vagrant发挥它的魔力。 + +注意: *如果在运行`vagrant up`的过程中出现任何错误,并且它让你回到命令提示符,只需运行`vagrant provision`继续从你离开的地方构建虚拟机。如果这样做了几次之后仍然有错误,请在GitHub上的项目问题队列中发布一个问题,并注明错误。* + +## 注意 + + - 要关闭虚拟机,在终端中输入 "vagrant halt",在同一个文件夹中输入 "Vagrantfile"。要完全销毁它(如果你想节省一点磁盘空间,或者想用 "vagrant up "从头开始重建),输入 "vagrant destroy"。 + +## 关于作者 + +这个项目是由[Jeff Geerling](https://www.jeffgeerling.com/)创建的,作为[Ansible for DevOps](https://www.ansiblefordevops.com/)的一个例子。 From f9a7813b58d6bf8f7ec03259f318d13cf35c02da Mon Sep 17 00:00:00 2001 From: martinliu Date: Sat, 30 Jan 2021 03:34:06 +0800 Subject: [PATCH 20/22] added short description * won't change your code. * using less words * only list some Ansbile points --- first-ansible-playbook/README_CN.md | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/first-ansible-playbook/README_CN.md b/first-ansible-playbook/README_CN.md index 33c92266..ea38b39e 100644 --- a/first-ansible-playbook/README_CN.md +++ b/first-ansible-playbook/README_CN.md @@ -20,6 +20,35 @@ Windows用户注意。*本指南假设您使用的是Mac或Linux主机。目前 注意: *如果在运行`vagrant up`的过程中出现任何错误,并且它让你回到命令提示符,只需运行`vagrant provision`继续从你离开的地方构建虚拟机。如果这样做了几次之后仍然有错误,请在GitHub上的项目问题队列中发布一个问题,并注明错误。* +### 代码说明 + +```yml +--- +- hosts: all # 执行所有目标 host + become: yes # 提升管理员权限 + + tasks: + - name: Ensure chrony (for time synchronization) is installed. + yum: # 软件包管理 + name: chrony + state: present #存在 + + - name: Ensure chrony is running. + service: # 系统服务管理 + name: chronyd + state: started #启动服务 + enabled: yes # 开机启动 + +# The same as the above play, but in super-compact form! +# 这是超级简洁的无废话编写模式,功能和上一样 +- hosts: all + become: yes + tasks: + - yum: name=chrony state=present + - service: name=chronyd state=started enabled=yes +``` + + ## 注意 - 要关闭虚拟机,在终端中输入 "vagrant halt",在同一个文件夹中输入 "Vagrantfile"。要完全销毁它(如果你想节省一点磁盘空间,或者想用 "vagrant up "从头开始重建),输入 "vagrant destroy"。 From 0eb85f88bae4b6207edafbfa794b14a7c0682535 Mon Sep 17 00:00:00 2001 From: martinliu Date: Sat, 1 May 2021 22:03:34 +0800 Subject: [PATCH 21/22] add chinese steps. --- first-ansible-playbook/README_CN.md | 8 ++-- orchestration/README_CN.md | 73 +++++++++++++++++++++++++++++ orchestration/Vagrantfile | 2 +- orchestration/ansible.cfg | 2 + 4 files changed, 80 insertions(+), 5 deletions(-) create mode 100644 orchestration/README_CN.md diff --git a/first-ansible-playbook/README_CN.md b/first-ansible-playbook/README_CN.md index ea38b39e..0d180cb7 100644 --- a/first-ansible-playbook/README_CN.md +++ b/first-ansible-playbook/README_CN.md @@ -1,6 +1,6 @@ # 第一个 Ansible Playbook 演示虚拟机 -这个项目旋创建一个虚拟机,并演示了一个非常简单的 Ansible Playbook。 +这个项目创建一个虚拟机,并演示了一个非常简单的 Ansible Playbook。 ## 快速入门指南 @@ -10,7 +10,7 @@ 2. 下载并安装 [Vagrant](http://www.vagrantup.com/downloads.html)。 3. [仅限 Mac/Linux]安装[Ansible](http://docs.ansible.com/intro_installation.html)。 -Windows用户注意。*本指南假设您使用的是Mac或Linux主机。目前不支持Windows主机。* +Windows请用户注意。*本指南假设您使用的是Mac或Linux主机。目前不支持Windows主机。如报错请自行调试。* ### 2 - 构建虚拟机 @@ -20,7 +20,7 @@ Windows用户注意。*本指南假设您使用的是Mac或Linux主机。目前 注意: *如果在运行`vagrant up`的过程中出现任何错误,并且它让你回到命令提示符,只需运行`vagrant provision`继续从你离开的地方构建虚拟机。如果这样做了几次之后仍然有错误,请在GitHub上的项目问题队列中发布一个问题,并注明错误。* -### 代码说明 +### 3 - 代码说明 ```yml --- @@ -40,7 +40,7 @@ Windows用户注意。*本指南假设您使用的是Mac或Linux主机。目前 enabled: yes # 开机启动 # The same as the above play, but in super-compact form! -# 这是超级简洁的无废话编写模式,功能和上一样 +# 这是超级简洁的无废话代码,功能和上面的代码一样 - hosts: all become: yes tasks: diff --git a/orchestration/README_CN.md b/orchestration/README_CN.md new file mode 100644 index 00000000..0c02ca35 --- /dev/null +++ b/orchestration/README_CN.md @@ -0,0 +1,73 @@ +# 简单的 Ansible 基础架构编排实例 + +Ansible Planybook 灵活而强大。但有时,你只需要在一组主机上运行一条命令。这时,简单的`ansible`命令就派上用场了。 + +就像《Ender's Game》中的设备一样,`ansible`命令允许你在一台或一百台服务器上立即运行命令或调用Ansible模块。 + +这个项目使用Vagrant和VirtualBox配置了三个虚拟机。`app1`、`app2`和`db`,以模拟一个小规模的真实世界基础设施(两个应用服务器和一个数据库服务器),因此您可以练习在它们之间运行`ansible`命令,并在一个灵活的Ansible清单上工作。 + +## 快速入门指南 + +### 1 - 安装依赖关系(VirtualBox, Vagrant, Ansible)。 + + 1. 下载并安装【VirtualBox】(https://www.virtualbox.org/wiki/Downloads)。 + 2. 下载并安装 [Vagrant](http://www.vagrantup.com/downloads.html)。 + 3. 仅限Mac/Linux]安装[Ansible](http://docs.ansible.com/intro_installation.html)。 + +Windows用户注意。*本指南假设您使用的是Mac或Linux主机。目前不支持Windows主机。 + +### 2 - 构建虚拟机 + + 1. 下载这个项目,并把它放在你想放的地方。 + 2. 打开终端,cd到这个目录(包含`Vagrantfile`和这个README文件)。 + 3. 输入`vagrant up`,让Vagrant发挥它的魔力。 + +注意: *如果在运行`vagrant up`的过程中出现任何错误,并且它将您丢回命令提示符,只需运行`vagrant provision`命令,它将继续从您报错的地方构建虚拟机。如果做了几次后仍然有错误,请在GitHub上的项目问题队列中发布一个问题并注明错误。 + + +#### ansible.cfg + +定义当前目录下执行 ansible 命令的配置参数, cfg 文件中调用了 当前目录下的 hosts.ini 清单文件。 +``` +[defaults] +inventory = hosts.ini +nocows = True +``` + +#### hosts.ini + +``` +# Application servers +# 应用服务器组 +[app] +192.168.60.4 +192.168.60.5 + +# Database server +# 数据库服务器组 +[db] +192.168.60.6 + +# Group 'multi' with all servers +# 名为 multi 的嵌套组 +[multi:children] +app +db + +# Variables that will be applied to all servers +# 给嵌套组定义变量,应用于所有服务器 +[multi:vars] +ansible_user=vagrant +ansible_ssh_private_key_file=~/.vagrant.d/insecure_private_key +ansible_ssh_common_args='-o StrictHostKeyChecking=no' +``` + + + +### 3 - 创建一个清单文件,并运行`ansible`命令。 + +详情请阅读【Ansible for DevOps】(https://www.ansiblefordevops.com/)第三章。 + +## 关于作者 + +这个项目是由[Jeff Geerling](https://www.jeffgeerling.com/)创建的,作为[Ansible for DevOps](https://www.ansiblefordevops.com/)的一个例子。 \ No newline at end of file diff --git a/orchestration/Vagrantfile b/orchestration/Vagrantfile index 87881891..c4c6d09d 100644 --- a/orchestration/Vagrantfile +++ b/orchestration/Vagrantfile @@ -5,7 +5,7 @@ VAGRANTFILE_API_VERSION = "2" Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| # General Vagrant VM configuration. - config.vm.box = "geerlingguy/centos8" + config.vm.box = "geerlingguy/centos7" config.ssh.insert_key = false config.vm.synced_folder ".", "/vagrant", disabled: true config.vm.provider :virtualbox do |v| diff --git a/orchestration/ansible.cfg b/orchestration/ansible.cfg index 7ff255cd..9caacd10 100644 --- a/orchestration/ansible.cfg +++ b/orchestration/ansible.cfg @@ -1,3 +1,5 @@ [defaults] inventory = hosts.ini nocows = True +deprecation_warnings=False +command_warnings=False \ No newline at end of file From 7b8c4dcd4c4a1564066959daa6856cc073e87c79 Mon Sep 17 00:00:00 2001 From: martinliu Date: Sat, 1 May 2021 23:08:42 +0800 Subject: [PATCH 22/22] finished ch3 --- orchestration/README_CN.md | 152 +++++++++++++++++++++++++++++++++++++ orchestration/Vagrantfile | 2 +- orchestration/ansible.cfg | 3 +- 3 files changed, 155 insertions(+), 2 deletions(-) diff --git a/orchestration/README_CN.md b/orchestration/README_CN.md index 0c02ca35..3f9c7c7c 100644 --- a/orchestration/README_CN.md +++ b/orchestration/README_CN.md @@ -28,6 +28,7 @@ Windows用户注意。*本指南假设您使用的是Mac或Linux主机。目前 #### ansible.cfg 定义当前目录下执行 ansible 命令的配置参数, cfg 文件中调用了 当前目录下的 hosts.ini 清单文件。 + ``` [defaults] inventory = hosts.ini @@ -36,6 +37,10 @@ nocows = True #### hosts.ini +被管理服务器定义清单文件 inventory 。 + + + ``` # Application servers # 应用服务器组 @@ -64,10 +69,157 @@ ansible_ssh_common_args='-o StrictHostKeyChecking=no' + + ### 3 - 创建一个清单文件,并运行`ansible`命令。 详情请阅读【Ansible for DevOps】(https://www.ansiblefordevops.com/)第三章。 + +### 运行 ad-hoc 命令 + +运行多次下面的命令,了解多线程并发的特性 + +ansible multi -a "hostname" +ansible multi -a "hostname" +ansible multi -a "hostname" + +ansible multi -a "hostname" -f 1 +ansible multi -a "hostname" -f 1 +ansible multi -a "hostname" -f 1 + +环境状况检查 + +ansible multi -a "df -h" + +ansible multi -a "free -m" + +ansible multi -a "date" + +使用 Ansible 模块做变更 + +ansible multi -b -m yum -a "name=chrony state=present" + +ansible multi -b -m service -a "name=chronyd state=started enabled=yes" + +ansible multi -b -a "chronyc tracking" + +ansible multi -a "date" + +配置服务器组和单一服务器 + +配置应用服务器:安装 python3 和 django + +ansible app -b -m yum -a "name=python3-pip state=present" + +ansible app -b -m pip -a "name=django<4 state=present" + + +ansible app -a "python -m django --version" + +配置数据库服务器 + +ansible db -b -m yum -a "name=mariadb-server state=present" + +ansible db -b -m service -a "name=mariadb state=started enabled=yes" + +ansible db -b -m yum -a "name=firewalld state=present" + +ansible db -b -m service -a "name=firewalld state=started enabled=yes" + +ansible db -b -m firewalld -a "zone=database state=present permanent=yes" + +ansible db -b -m firewalld -a "source=192.168.60.0/24 zone=database state=enabled permanent=yes" + +ansible db -b -m firewalld -a "port=3306/tcp zone=database state=enabled permanent=yes" + +ansible db -b -m yum -a "name=python3-PyMySQL state=present" + +ansible db -b -m mysql_user -a "name=django host=% password=12345 priv=*.*:ALL state=present" + +对服务器组中的某一个执行命令 + +ansible app -b -a "service chronyd restart" --limit "192.168.60.4" + +用星号匹配 + +ansible app -b -a "service ntpd restart" --limit "*.4" + +用正则表达式匹配 + +ansible app -b -a "service ntpd restart" --limit ~".*\.4" + + +管理用户和组 + +ansible app -b -m group -a "name=admin state=present" + +ansible app -b -m user -a "name=johndoe group=admin createhome=yes" + +ansible app -b -m user -a "name=johndoe state=absent remove=yes" + +管理软件包 + +ansible app -b -m package -a "name=git state=present" + +管理文件和目录 + +查看文件属性 + +ansible multi -m stat -a "path=/etc/environment" + +从本地复制文件到服务器 + +ansible multi -m copy -a "src=/etc/hosts dest=/tmp/hosts" + +从服务器上下载文件 + +ansible multi -b -m fetch -a "src=/etc/hosts dest=/tmp" + +创建目录和文件 + +ansible multi -m file -a "dest=/tmp/test mode=644 state=directory" + +ansible multi -m file -a "src=/src/file dest=/dest/symlink state=link" + +删除目录和文件 + +ansible multi -m file -a "dest=/tmp/test state=absent" + +用异步作业异步的更新服务器 + +ansible multi -b -B 3600 -P 0 -a "yum -y update" + +ansible multi -b -m async_status -a "jid=169825235950.3572" + +查看日志的方法 + +ansible multi -b -a "tail /var/log/messages" + +ansible multi -b -m shell -a "tail /var/log/messages | \ +grep ansible-command | wc -l" + +管理 cron 作业 + +ansible multi -b -m cron -a "name='daily-cron-all-servers' \ +hour=4 job='/path/to/daily-script.sh'" + +ansible multi -b -m cron -a "name='daily-cron-all-servers' \ +state=absent" + +部署版本控制的应用 + +ansible app -b -m git -a "repo=git://example.com/path/to/repo.git \ +dest=/opt/myapp update=yes version=1.2.4" + +ansible app -b -a "/opt/myapp/update.sh" + +Ansible 的 SSH 连接历史 + + + + + ## 关于作者 这个项目是由[Jeff Geerling](https://www.jeffgeerling.com/)创建的,作为[Ansible for DevOps](https://www.ansiblefordevops.com/)的一个例子。 \ No newline at end of file diff --git a/orchestration/Vagrantfile b/orchestration/Vagrantfile index c4c6d09d..87881891 100644 --- a/orchestration/Vagrantfile +++ b/orchestration/Vagrantfile @@ -5,7 +5,7 @@ VAGRANTFILE_API_VERSION = "2" Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| # General Vagrant VM configuration. - config.vm.box = "geerlingguy/centos7" + config.vm.box = "geerlingguy/centos8" config.ssh.insert_key = false config.vm.synced_folder ".", "/vagrant", disabled: true config.vm.provider :virtualbox do |v| diff --git a/orchestration/ansible.cfg b/orchestration/ansible.cfg index 9caacd10..22527ef0 100644 --- a/orchestration/ansible.cfg +++ b/orchestration/ansible.cfg @@ -2,4 +2,5 @@ inventory = hosts.ini nocows = True deprecation_warnings=False -command_warnings=False \ No newline at end of file +command_warnings=False +pipelining=True \ No newline at end of file