From aa7e58a1fb3264b1866351803a5b598fd3346563 Mon Sep 17 00:00:00 2001 From: Roberto Polli Date: Mon, 2 Feb 2026 20:18:01 +0100 Subject: [PATCH] yamlfmt --- .github/workflows/publish.yaml | 2 - .pre-commit-config.yaml | 113 ++++++---- .travis.yml | 8 +- ansible-101/deleteme-digitalocean.yml | 24 +- ansible-101/docker-compose.yml | 66 +++--- .../exercise-00/python-course-test.yml | 4 +- ansible-101/notebooks/exercise-00/site.yml | 4 +- .../notebooks/exercise-03/conditions.yml | 4 - .../notebooks/exercise-03/environment.yml | 3 +- .../notebooks/exercise-03/fileglob.yml | 5 +- .../exercise-03/get-facts-solution.yml | 6 +- .../notebooks/exercise-03/get-facts.yml | 11 +- .../notebooks/exercise-03/vars-and-facts.yml | 7 +- .../notebooks/exercise-07/.add_key.yml | 55 +++-- .../notebooks/exercise-07/changed-when.yml | 14 +- ansible-101/notebooks/exercise-07/debug.yml | 23 +- .../notebooks/exercise-07/files-content.yml | 106 ++++----- .../notebooks/exercise-07/hostvars.yml | 54 ++--- ansible-101/notebooks/exercise-07/lookup.yml | 9 +- .../notebooks/exercise-07/mount-bind.yml | 21 +- .../notebooks/exercise-07/shell-output-01.yml | 29 ++- .../notebooks/exercise-07/shell-output-02.yml | 59 +++-- ansible-101/notebooks/exercise-08/dumper.yaml | 9 +- .../notebooks/exercise-09/documentroot.yml | 3 - ansible-101/notebooks/exercise-09/web-1.yml | 14 +- ansible-101/notebooks/exercise-09/web-2.yml | 7 +- ansible-101/site-digitalocean.yml | 212 +++++++++--------- connexion-101/api/logging.yaml | 2 +- connexion-101/api/simple.yaml | 45 ++-- connexion-101/deleteme-digitalocean.yml | 47 ++-- .../notebooks/oas3/ex-01-info-ok.yaml | 3 - .../notebooks/oas3/ex-02-servers.yaml | 2 - .../notebooks/oas3/ex-03-02-path-ok.yaml | 8 +- .../notebooks/oas3/ex-05-01-bundle-ok.yaml | 15 +- .../notebooks/oas3/ex-05-01-bundle.yaml | 22 +- .../oas3/ex-07-01-throttling-ok.yaml | 26 +-- .../notebooks/oas3/ex-08-pagination-ok.yaml | 67 +++--- connexion-101/notebooks/oas3/store.yaml | 17 +- connexion-101/site-digitalocean.yml | 163 +++++++------- mongodb-101/docker-compose.yml | 23 +- mongodb-101/site-digitalocean.yml | 173 +++++++------- .../ansible/initialize-innodbcluster.yml | 89 ++++---- mysql-101/ansible/install-mysql.yml | 61 +++-- python-basic/docker-compose.yml | 33 ++- python-for-sysadmin/docker-compose.yml | 44 ++-- .../notebooks/ansible/python-course-test.yml | 4 +- python-for-sysadmin/notebooks/logger.yml | 3 - sparql-101/docker-compose.yaml | 10 +- .../notebooks/guestbook-all-in-one.yaml | 88 ++++---- 49 files changed, 844 insertions(+), 973 deletions(-) diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index 522ac99..a2d70e0 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -1,5 +1,4 @@ name: CI Test and Publish Workflow - on: push: branches: [main] @@ -16,7 +15,6 @@ env: IMAGE_NAME: ${{ github.repository }} DOCKER_BUILDKIT: "1" TERM: linux - jobs: security: strategy: diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 50bb064..46cc533 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -6,57 +6,74 @@ # # See https://pre-commit.com for more information # See https://pre-commit.com/hooks.html for more hooks +default_stages: + - pre-commit repos: -- repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.5.0 - hooks: - - id: trailing-whitespace - - id: end-of-file-fixer - - id: check-yaml - args: [--allow-multiple-documents] - - id: check-added-large-files -- repo: https://github.com/myint/autoflake - rev: v2.2.1 +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v6.0.0 hooks: - - id: autoflake - args: - - --in-place - - --remove-unused-variables - - --remove-all-unused-imports -- repo: https://github.com/psf/black - rev: 23.11.0 - hooks: - - id: black -- repo: https://github.com/pycqa/isort - rev: 5.12.0 + # Manage spaces. + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-added-large-files + - id: check-symlinks + - id: mixed-line-ending + args: [--fix=lf] + # Check file syntax/format + - id: check-xml + - id: check-json + - id: check-yaml + args: [--allow-multiple-documents] + # Security checks. + - id: detect-private-key + - id: detect-aws-credentials + args: + # See https://github.com/pre-commit/pre-commit-hooks/issues/174 + - --allow-missing-credentials +- repo: https://github.com/google/yamlfmt + rev: v0.21.0 hooks: - - id: isort - name: isort (python) - # Use black profile for isort to avoid conflicts - # see https://github.com/PyCQA/isort/issues/1518 - args: ["--profile", "black"] - - id: isort - name: isort (cython) - types: [cython] - - id: isort - name: isort (pyi) - types: [pyi] -- repo: https://github.com/pycqa/flake8 - rev: 6.1.0 + - id: yamlfmt + files: \.(yaml|yml)$ + exclude: 'config\.yaml' +# +# Python linters. +# +- repo: https://github.com/astral-sh/ruff-pre-commit + # Ruff version. + rev: v0.14.13 + hooks: + # Run the linter. + - id: ruff + args: [--fix] + files: ^python-high-school/ + exclude: ^ansible-101/|python-for-sysadmin|\.ipynb$ + - # Run the formatter. + id: ruff-format + files: ^python-high-school/ + exclude: ^ansible-101/|python-for-sysadmin|\.ipynb$ +- repo: https://github.com/pre-commit/mirrors-mypy + rev: v1.19.1 hooks: - - id: flake8 -- repo: https://github.com/PyCQA/bandit - rev: 1.7.5 + - id: mypy + additional_dependencies: [types-PyYAML] + exclude: ^tests/ +# +# Security linters. +# +- repo: https://github.com/bridgecrewio/checkov.git + rev: 3.2.497 # change to tag or sha hooks: - - id: bandit - name: bandit - args: ["-c", ".bandit.yaml"] - description: 'Bandit is a tool for finding common security issues in Python code' - entry: bandit - language: python - language_version: python3 - types: [python] -- repo: https://github.com/Lucas-C/pre-commit-hooks-safety - rev: v1.3.2 + - id: checkov + - id: checkov_secrets + stages: ["pre-push"] +- repo: local hooks: - - id: python-safety-dependencies-check + - id: trufflehog + name: TruffleHog + description: Detect secrets in your data. + entry: bash -c 'docker run --rm -v "$(pwd):/workdir" -i --rm + trufflesecurity/trufflehog:latest git file:///workdir --since-commit + HEAD --results=verified,unknown --fail' + language: system + stages: ["pre-push"] diff --git a/.travis.yml b/.travis.yml index 5055c66..eae2ca5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,7 @@ language: python python: - - 2.7 - - 3.3 - + - 2.7 + - 3.3 # Setup anaconda before_install: - wget http://repo.continuum.io/miniconda/Miniconda-latest-Linux-x86_64.sh -O miniconda.sh @@ -18,7 +17,6 @@ before_install: install: - conda install --yes python=$TRAVIS_PYTHON_VERSION atlas numpy scipy matplotlib nose dateutil pandas statsmodels conda-env - conda install --yes python=$TRAVIS_PYTHON_VERSION $(python-for-sysadmin/requirements.txt) - # Run test script: - - nosetests + - nosetests diff --git a/ansible-101/deleteme-digitalocean.yml b/ansible-101/deleteme-digitalocean.yml index 86279e6..67c1150 100644 --- a/ansible-101/deleteme-digitalocean.yml +++ b/ansible-101/deleteme-digitalocean.yml @@ -12,15 +12,15 @@ - hosts: localhost gather_facts: false tasks: - - name: Delete machine for the course. - community.digitalocean.digital_ocean_droplet: - state: absent - name: "{{item}}" - unique_name: yes - region: fra1 - image: docker-18-04 - wait_timeout: 500 - register: my_droplet - with_items: - - deleteme-1 - - deleteme-2 + - name: Delete machine for the course. + community.digitalocean.digital_ocean_droplet: + state: absent + name: "{{item}}" + unique_name: yes + region: fra1 + image: docker-18-04 + wait_timeout: 500 + register: my_droplet + with_items: + - deleteme-1 + - deleteme-2 diff --git a/ansible-101/docker-compose.yml b/ansible-101/docker-compose.yml index 4c784e3..14287cf 100644 --- a/ansible-101/docker-compose.yml +++ b/ansible-101/docker-compose.yml @@ -2,66 +2,58 @@ version: "2" services: dev: - build: . - hostname: sysadminpy - environment: + build: . + hostname: sysadminpy + environment: - USE_HTTP=1 - PASSWORD=secret - ports: + ports: - 8888:8888 - volumes: + volumes: - ./notebooks:/notebooks:z - ./notebooks/custom.css:/root/.jupyter/custom/custom.css - .:/code:z - network_mode: bridge - entrypoint: /bin/sh - command: -c "/usr/local/bin/jupyter-notebook --ip 0.0.0.0 --allow-root" - - + network_mode: bridge + entrypoint: /bin/sh + command: -c "/usr/local/bin/jupyter-notebook --ip 0.0.0.0 --allow-root" test: - image: ioggstream/python-course - volumes: + image: ioggstream/python-course + volumes: - ./notebooks:/notebooks:z # entrypoint: tail -f /etc/hosts - - # Official image from docker hub course: - image: ghcr.io/ioggstream/python-course:python27 - user: root - environment: + image: ghcr.io/ioggstream/python-course:python27 + user: root + environment: - USE_HTTP=1 - DOCKER_HOST=172.17.0.1 - SHELL=/bin/bash - volumes: + volumes: - ./notebooks:/notebooks:z - ./notebooks/custom.css:/root/.jupyter/custom/custom.css - .:/code:z - network_mode: bridge - ports: + network_mode: bridge + ports: - 8888:8888 - entrypoint: /bin/sh - command: -c "/usr/local/bin/jupyter-notebook --ip 0.0.0.0 --allow-root" - - + entrypoint: /bin/sh + command: -c "/usr/local/bin/jupyter-notebook --ip 0.0.0.0 --allow-root" # Some ssh-enabled docker containers # for student homework bastion: - build: - context: . - dockerfile: Dockerfile.ssh - volumes: + build: + context: . + dockerfile: Dockerfile.ssh + volumes: - .:/code:z - network_mode: bridge - - + network_mode: bridge # Some ssh-enabled docker containers # for student homework web: - build: - context: . - dockerfile: Dockerfile.ssh - volumes: + build: + context: . + dockerfile: Dockerfile.ssh + volumes: - .:/code:z - # - ./notebooks/exercise-01/id_ansible.pub:/root/.ssh/authorized_keys:z - network_mode: bridge + # - ./notebooks/exercise-01/id_ansible.pub:/root/.ssh/authorized_keys:z + network_mode: bridge diff --git a/ansible-101/notebooks/exercise-00/python-course-test.yml b/ansible-101/notebooks/exercise-00/python-course-test.yml index f61894a..e36d360 100644 --- a/ansible-101/notebooks/exercise-00/python-course-test.yml +++ b/ansible-101/notebooks/exercise-00/python-course-test.yml @@ -6,12 +6,10 @@ tasks: - name: The /notebooks directory should exist file: path="/notebooks" state=directory - - name: jupyter is responding on 8888 uri: url: http://0.0.0.0:8888/notebooks validate_certs: false - status_code: 200 # modify this line to simulate an error and see the outcome! - + status_code: 200 # modify this line to simulate an error and see the outcome! - name: The template.conf is in place file: path="/tmp/template.conf" state=file diff --git a/ansible-101/notebooks/exercise-00/site.yml b/ansible-101/notebooks/exercise-00/site.yml index ed255a9..56956ad 100644 --- a/ansible-101/notebooks/exercise-00/site.yml +++ b/ansible-101/notebooks/exercise-00/site.yml @@ -4,13 +4,11 @@ # - hosts: course tasks: - - name: Create a file from a template template: src=mytemplate.j2 dest=/tmp/template.conf - - name: Ensure needed packages are present and eventually install them apt: name={{item}} state=present with_items: - python - python-dev - ignore_errors: yes # ignore errors during the course (eg. connectivity) + ignore_errors: yes # ignore errors during the course (eg. connectivity) diff --git a/ansible-101/notebooks/exercise-03/conditions.yml b/ansible-101/notebooks/exercise-03/conditions.yml index 5e1bf17..bd66ab9 100644 --- a/ansible-101/notebooks/exercise-03/conditions.yml +++ b/ansible-101/notebooks/exercise-03/conditions.yml @@ -1,4 +1,3 @@ ---- - hosts: localhost tags: when tasks: @@ -6,18 +5,15 @@ when: true - debug: msg="This never does" when: false - - hosts: localhost tags: assert tasks: - debug: msg: "This is Linux!" when: ansible_system == 'Linux' - - fail: msg: "Stop processing now!" when: ansible_architecture == 'x86_64' - - hosts: localhost tags: exercise tasks: diff --git a/ansible-101/notebooks/exercise-03/environment.yml b/ansible-101/notebooks/exercise-03/environment.yml index f0de447..9576f77 100644 --- a/ansible-101/notebooks/exercise-03/environment.yml +++ b/ansible-101/notebooks/exercise-03/environment.yml @@ -1,9 +1,10 @@ ---- - hosts: localhost tasks: - name: Iterate thru environment debug: var: > ansible_env.{{ item }} + with_items: > {{ ansible_env | map('regex_search', '^PATH') | select('string') | list }} + diff --git a/ansible-101/notebooks/exercise-03/fileglob.yml b/ansible-101/notebooks/exercise-03/fileglob.yml index 0721028..2eed12b 100644 --- a/ansible-101/notebooks/exercise-03/fileglob.yml +++ b/ansible-101/notebooks/exercise-03/fileglob.yml @@ -1,12 +1,11 @@ ---- - hosts: web tags: fileglob tasks: - name: You can implement a remote fileglob in 2 steps shell: > ls /etc/host* - register: fileglob_remote + register: fileglob_remote - name: Here we go debug: msg: >- @@ -14,7 +13,6 @@ with_items: > {{ fileglob_remote.stdout_lines }} - - hosts: web, localhost tags: environment environment: @@ -23,6 +21,7 @@ - name: Passing a shell variable to the whole play shell: > echo $WELCOME + register: o - name: EuroPython is here debug: diff --git a/ansible-101/notebooks/exercise-03/get-facts-solution.yml b/ansible-101/notebooks/exercise-03/get-facts-solution.yml index b89fba1..8e8e97d 100644 --- a/ansible-101/notebooks/exercise-03/get-facts-solution.yml +++ b/ansible-101/notebooks/exercise-03/get-facts-solution.yml @@ -1,12 +1,10 @@ ---- # # Use this playbook to dump ansible facts # - hosts: localhost name: > - Use this section to complete the exercise, - and the next section as a reference for - the debug module. + Use this section to complete the exercise, and the next section as a reference for the debug module. + tasks: - name: Dump the requested facts. debug: diff --git a/ansible-101/notebooks/exercise-03/get-facts.yml b/ansible-101/notebooks/exercise-03/get-facts.yml index afb9dd0..d8afdf7 100644 --- a/ansible-101/notebooks/exercise-03/get-facts.yml +++ b/ansible-101/notebooks/exercise-03/get-facts.yml @@ -1,17 +1,14 @@ ---- # # Use this playbook to dump ansible facts # - hosts: localhost name: > - Use this section to complete the exercise, - and the next section as a reference for - the debug module. + Use this section to complete the exercise, and the next section as a reference for the debug module. + tasks: - name: Dump the requested facts. debug: msg: A string - # # Read this for reference # @@ -21,18 +18,16 @@ - name: This is the debug module. debug: msg: A string - - name: The debug module can print variables too debug: var: ansible_hostname - - name: We can iterate too... debug: msg: "{{ item }}" with_items: "{{ ansible_system_capabilities }}" - - name: ..and inspect/format variables debug: msg: The device is {{ item.device }} with_items: > {{ ansible_mounts }} + diff --git a/ansible-101/notebooks/exercise-03/vars-and-facts.yml b/ansible-101/notebooks/exercise-03/vars-and-facts.yml index f35e902..7e9feb0 100644 --- a/ansible-101/notebooks/exercise-03/vars-and-facts.yml +++ b/ansible-101/notebooks/exercise-03/vars-and-facts.yml @@ -1,4 +1,3 @@ ---- # # This playbook has 3 tasklists, each with a different tag. # @@ -11,11 +10,11 @@ - debug: msg: > {{ ansible_hostname }} {{ one }} + - debug: msg: > The output is {{ one + pi }} - - hosts: localhost tags: filters vars: @@ -32,7 +31,7 @@ name: Use this cell for the exercise tasks: - name: > - Show the free percentage of the local disk using - facts and filters + Show the free percentage of the local disk using facts and filters + debug: msg: "Replace me" diff --git a/ansible-101/notebooks/exercise-07/.add_key.yml b/ansible-101/notebooks/exercise-07/.add_key.yml index 16f18f2..3b42870 100644 --- a/ansible-101/notebooks/exercise-07/.add_key.yml +++ b/ansible-101/notebooks/exercise-07/.add_key.yml @@ -1,33 +1,28 @@ - hosts: web tasks: - - name: Create a new keypair - delegate_to: localhost - run_once: yes - user: - name: root - generate_ssh_key: yes - ssh_key_file: /tmp/id_ecdsa_new - ssh_key_type: ecdsa - - - name: Create a new user with associated ssh keys - user: - name: fizz - generate_ssh_key: yes - password: fizz - - - name: Install remotely a local PK - authorized_key: - user: fizz - state: present - key: "{{ lookup('file', '/tmp/id_ecdsa_new.pub') }}" - - - name: Add host as ip - add_host: - ansible_ssh_host: "{{ansible_default_ipv4.address}}" - hostname: "{{ansible_default_ipv4.address}}" - groups: test - - + - name: Create a new keypair + delegate_to: localhost + run_once: yes + user: + name: root + generate_ssh_key: yes + ssh_key_file: /tmp/id_ecdsa_new + ssh_key_type: ecdsa + - name: Create a new user with associated ssh keys + user: + name: fizz + generate_ssh_key: yes + password: fizz + - name: Install remotely a local PK + authorized_key: + user: fizz + state: present + key: "{{ lookup('file', '/tmp/id_ecdsa_new.pub') }}" + - name: Add host as ip + add_host: + ansible_ssh_host: "{{ansible_default_ipv4.address}}" + hostname: "{{ansible_default_ipv4.address}}" + groups: test - hosts: test tags: test vars: @@ -36,5 +31,5 @@ host_key_checking: no ansible_private_key_file: /tmp/id_ecdsa_new tasks: - - name: Just ping - shell: hostname + - name: Just ping + shell: hostname diff --git a/ansible-101/notebooks/exercise-07/changed-when.yml b/ansible-101/notebooks/exercise-07/changed-when.yml index 2182dee..20150f4 100644 --- a/ansible-101/notebooks/exercise-07/changed-when.yml +++ b/ansible-101/notebooks/exercise-07/changed-when.yml @@ -5,10 +5,10 @@ # - hosts: all tasks: - - name: > - Settin changed_when and check_mode after - writing the command may be safer. - shell: | - pgrep -f oracle - check_mode: no - changed_when: no + - name: > + Settin changed_when and check_mode after writing the command may be safer. + + shell: | + pgrep -f oracle + check_mode: no + changed_when: no diff --git a/ansible-101/notebooks/exercise-07/debug.yml b/ansible-101/notebooks/exercise-07/debug.yml index a09b27c..8819e48 100644 --- a/ansible-101/notebooks/exercise-07/debug.yml +++ b/ansible-101/notebooks/exercise-07/debug.yml @@ -2,18 +2,19 @@ tags: gather_facts name: those tasks are run on localhost only tasks: - - name: This is the debug module. - debug: msg="A string" - - name: The debug module can print a variable too... - debug: var=ansible_hostname - + - name: This is the debug module. + debug: msg="A string" + - name: The debug module can print a variable too... + debug: var=ansible_hostname - hosts: web tags: groups name: Those tasks are run on every web host tasks: - - name: Iterating over the host in the "web" group. - debug: - msg: > - Host: {{ item }} - with_items: > - {{ groups['web'] }} + - name: Iterating over the host in the "web" group. + debug: + msg: > + Host: {{ item }} + + with_items: > + {{ groups['web'] }} + diff --git a/ansible-101/notebooks/exercise-07/files-content.yml b/ansible-101/notebooks/exercise-07/files-content.yml index 96739a3..5a973dc 100644 --- a/ansible-101/notebooks/exercise-07/files-content.yml +++ b/ansible-101/notebooks/exercise-07/files-content.yml @@ -1,65 +1,51 @@ - hosts: localhost name: > - A playbook can be made of multiple stanzas. They'll be - pipelined. - tasks: - - name: Delete previous template - file: state=absent dest=/tmp/index.html.template - - - name: | - We're now just showing how to create a file containing a block of lines - blockinfile: - dest: /tmp/index.html.template - create: yes - owner: root - group: root - marker: no - mode: 0644 - block: > - - - System installed by {{ansible_hostname}} on {{ '{{' }} ansible_hostname {{ '}}' }} - - - - - name: Register command output in a variable - shell: cat index.html.template - args: - chdir: /tmp - register: o_cat - - - name: Show output - debug: var=o_cat.stdout - + A playbook can be made of multiple stanzas. They'll be pipelined. + tasks: + - name: Delete previous template + file: state=absent dest=/tmp/index.html.template + - name: | + We're now just showing how to create a file containing a block of lines + blockinfile: + dest: /tmp/index.html.template + create: yes + owner: root + group: root + marker: no + mode: 0644 + block: > + System installed by {{ansible_hostname}} on {{ '{{' }} ansible_hostname {{ '}}' }} + + - name: Register command output in a variable + shell: cat index.html.template + args: + chdir: /tmp + register: o_cat + - name: Show output + debug: var=o_cat.stdout - hosts: web tasks: - - name: Install apache and other packages eventually iterating - apt: name="{{item}}" - with_items: - - apache2 - - curl - - - name: Facts are per-host variables - set_fact: documentroot="{{ '~www-data' | expanduser }}/html" - - - name: Ensure www is there - file: dest="{{documentroot}}" state=directory owner=root group=root - - - name: Upload file as a template - template: - src: /tmp/index.html.template - dest: /var/www/html/index.html - - - name: Start apache2 - service: name=apache2 state=started - - - name: Check page - uri: - url: http://localhost - return_content: yes - register: webpage - - - name: Fail if AWESOME is not in the page content - fail: - when: "'sysadminpy' not in webpage.content" + - name: Install apache and other packages eventually iterating + apt: name="{{item}}" + with_items: + - apache2 + - curl + - name: Facts are per-host variables + set_fact: documentroot="{{ '~www-data' | expanduser }}/html" + - name: Ensure www is there + file: dest="{{documentroot}}" state=directory owner=root group=root + - name: Upload file as a template + template: + src: /tmp/index.html.template + dest: /var/www/html/index.html + - name: Start apache2 + service: name=apache2 state=started + - name: Check page + uri: + url: http://localhost + return_content: yes + register: webpage + - name: Fail if AWESOME is not in the page content + fail: + when: "'sysadminpy' not in webpage.content" diff --git a/ansible-101/notebooks/exercise-07/hostvars.yml b/ansible-101/notebooks/exercise-07/hostvars.yml index 618f5ee..d276918 100644 --- a/ansible-101/notebooks/exercise-07/hostvars.yml +++ b/ansible-101/notebooks/exercise-07/hostvars.yml @@ -10,34 +10,38 @@ tags: hostvars name: Last task runs only on first host tasks: - - name: hostvars is a dictionary - debug: - var: hostvars - - name: Iterating over a dictionary yields the keys - debug: - msg: > - Host: {{ item }} - with_items: > - {{ hostvars }} - - name: >- - Use subscript to access entries. - NB: This task requires iproute2 installed on the remote host. - run_once: true - debug: - msg: > - address: {{ item }} -> {{ hostvars[item]['ansible_default_ipv4']['address'] }} - with_items: > - {{ groups['web'] }} + - name: hostvars is a dictionary + debug: + var: hostvars + - name: Iterating over a dictionary yields the keys + debug: + msg: > + Host: {{ item }} + with_items: > + {{ hostvars }} + + - name: >- + Use subscript to access entries. NB: This task requires iproute2 installed on the remote host. + run_once: true + debug: + msg: > + address: {{ item }} -> {{ hostvars[item]['ansible_default_ipv4']['address'] }} + + with_items: > + {{ groups['web'] }} - hosts: web[0] tags: filters name: Get a list of defined host IPs. tasks: - - name: Using filters - debug: - msg: > - {{ groups['web'] | - map('extract', hostvars, ['ansible_default_ipv4', 'address']) | - reject('undefined') | - list }} + - name: Using filters + debug: + msg: > + {{ groups['web'] | + + + + map('extract', hostvars, ['ansible_default_ipv4', 'address']) | + reject('undefined') | + list }} diff --git a/ansible-101/notebooks/exercise-07/lookup.yml b/ansible-101/notebooks/exercise-07/lookup.yml index 04694c6..1a7da9b 100644 --- a/ansible-101/notebooks/exercise-07/lookup.yml +++ b/ansible-101/notebooks/exercise-07/lookup.yml @@ -2,7 +2,8 @@ # from various sources. - hosts: localhost tasks: - - name: Get file content with the 'file' lookup plugin - debug: - msg: > - {{ lookup('file', '/etc/resolv.conf') }} + - name: Get file content with the 'file' lookup plugin + debug: + msg: > + {{ lookup('file', '/etc/resolv.conf') }} + diff --git a/ansible-101/notebooks/exercise-07/mount-bind.yml b/ansible-101/notebooks/exercise-07/mount-bind.yml index 13db09d..c1a3cee 100644 --- a/ansible-101/notebooks/exercise-07/mount-bind.yml +++ b/ansible-101/notebooks/exercise-07/mount-bind.yml @@ -11,14 +11,13 @@ # - hosts: all tasks: - - name: > - Mount /var under /mnt/bind with a bind mount. - Check the mount module docs to populate all - the options. - mount: - name: - src: - opts: - fstype: - state: - register: fstab + - name: > + Mount /var under /mnt/bind with a bind mount. Check the mount module docs to populate all the options. + + mount: + name: + src: + opts: + fstype: + state: + register: fstab diff --git a/ansible-101/notebooks/exercise-07/shell-output-01.yml b/ansible-101/notebooks/exercise-07/shell-output-01.yml index 91cc241..2df6fa9 100644 --- a/ansible-101/notebooks/exercise-07/shell-output-01.yml +++ b/ansible-101/notebooks/exercise-07/shell-output-01.yml @@ -1,19 +1,18 @@ # - hosts: localhost tasks: - - name: Run multiple commands via /bin/sh (no bashisms) - shell: | - ls -latr /etc/host* - cat /etc/resolv.conf - ignore_errors: yes - register: o + - name: Run multiple commands via /bin/sh (no bashisms) + shell: | + ls -latr /etc/host* + cat /etc/resolv.conf + ignore_errors: yes + register: o + - name: Show output in a single block... + debug: + var: o.stdout + - name: '... or one per line' + debug: + var: item + with_items: > + {{ o.stdout_lines }} - - name: Show output in a single block... - debug: - var: o.stdout - - - name: ... or one per line - debug: - var: item - with_items: > - {{ o.stdout_lines }} diff --git a/ansible-101/notebooks/exercise-07/shell-output-02.yml b/ansible-101/notebooks/exercise-07/shell-output-02.yml index 36b555c..b275483 100644 --- a/ansible-101/notebooks/exercise-07/shell-output-02.yml +++ b/ansible-101/notebooks/exercise-07/shell-output-02.yml @@ -1,39 +1,34 @@ - hosts: localhost tasks: - - name: Clean fetch directory - file: - dest: '/tmp/fetch/' - state: absent - - - name: Create - file: - dest: '/tmp/fetch/' - state: directory - - + - name: Clean fetch directory + file: + dest: '/tmp/fetch/' + state: absent + - name: Create + file: + dest: '/tmp/fetch/' + state: directory - hosts: web vars: - - outfile: "/tmp/outfile_{{ansible_date_time['iso8601']}}.out" + - outfile: "/tmp/outfile_{{ansible_date_time['iso8601']}}.out" tasks: - - name: Run multiple commands via /bin/sh (no bashisms) - shell: | - echo "--- START COMMAND: cat /etc/resolv.conf --" > {{outfile}} 2>&1 - {{item}} > {{outfile}} 2>&1 - echo "--- ENDCOMMAND: cat /etc/resolv.conf --" > {{outfile}} 2>&1 - ignore_errors: yes - with_items: - - "ls /etc/resolv.conf" - - "cat /etc/resolv.conf" - - - name: get file locally - fetch: - src: "{{outfile}}" - dest: /tmp/fetch - + - name: Run multiple commands via /bin/sh (no bashisms) + shell: | + echo "--- START COMMAND: cat /etc/resolv.conf --" > {{outfile}} 2>&1 + {{item}} > {{outfile}} 2>&1 + echo "--- ENDCOMMAND: cat /etc/resolv.conf --" > {{outfile}} 2>&1 + ignore_errors: yes + with_items: + - "ls /etc/resolv.conf" + - "cat /etc/resolv.conf" + - name: get file locally + fetch: + src: "{{outfile}}" + dest: /tmp/fetch - hosts: localhost tasks: - - name: compress directory - archive: - src: /tmp/fetch - dest: /tmp/sosreport.tar.bz2 - format: bz2 + - name: compress directory + archive: + src: /tmp/fetch + dest: /tmp/sosreport.tar.bz2 + format: bz2 diff --git a/ansible-101/notebooks/exercise-08/dumper.yaml b/ansible-101/notebooks/exercise-08/dumper.yaml index f7a7c24..838cbce 100644 --- a/ansible-101/notebooks/exercise-08/dumper.yaml +++ b/ansible-101/notebooks/exercise-08/dumper.yaml @@ -1,7 +1,6 @@ ---- - hosts: localhost tasks: - - name: "Dump processed configs" - debug: var=mongo_nodes_f - - name: "Dump processed configs" - debug: var=mongo_uri_f + - name: "Dump processed configs" + debug: var=mongo_nodes_f + - name: "Dump processed configs" + debug: var=mongo_uri_f diff --git a/ansible-101/notebooks/exercise-09/documentroot.yml b/ansible-101/notebooks/exercise-09/documentroot.yml index a8b0483..7ae68fc 100644 --- a/ansible-101/notebooks/exercise-09/documentroot.yml +++ b/ansible-101/notebooks/exercise-09/documentroot.yml @@ -1,11 +1,8 @@ ---- # I am web-tasklist.yml - - name: Create subfolder file: path: "/var/www/html/{{x}}/" state: directory - - name: lineinfile: path: /var/www/html/{{x}}/index.html diff --git a/ansible-101/notebooks/exercise-09/web-1.yml b/ansible-101/notebooks/exercise-09/web-1.yml index a657d51..b80486d 100644 --- a/ansible-101/notebooks/exercise-09/web-1.yml +++ b/ansible-101/notebooks/exercise-09/web-1.yml @@ -1,10 +1,10 @@ # I am a play including a tasklist - hosts: web tasks: - - include_tasks: documentroot.yml - vars: - x: "{{item}}" - with_items: - - Rimini - - Emilia-Romagna - - Italia + - include_tasks: documentroot.yml + vars: + x: "{{item}}" + with_items: + - Rimini + - Emilia-Romagna + - Italia diff --git a/ansible-101/notebooks/exercise-09/web-2.yml b/ansible-101/notebooks/exercise-09/web-2.yml index b0e7d74..cebb941 100644 --- a/ansible-101/notebooks/exercise-09/web-2.yml +++ b/ansible-101/notebooks/exercise-09/web-2.yml @@ -1,12 +1,9 @@ ---- # This play includes another play # - - hosts: web tasks: - - name: install apache - apt: name=apache2 state=latest - + - name: install apache + apt: name=apache2 state=latest - import_playbook: web-1.yml when: > 'missing' in groups diff --git a/ansible-101/site-digitalocean.yml b/ansible-101/site-digitalocean.yml index 3fbf5bb..25dfca6 100644 --- a/ansible-101/site-digitalocean.yml +++ b/ansible-101/site-digitalocean.yml @@ -28,125 +28,113 @@ - deleteme-4 - deleteme-5 - deleteme-6 - tasks: - - name: Retrieve ssh key id. - community.digitalocean.digital_ocean_sshkey_info: - oauth_token: "{{ oauth_token }}" - register: ssh_keys - check_mode: no - - - name: Set facts based on the gathered information - set_fact: - do_key: "{{ do_key | default([]) + ssh_keys | community.general.json_query(search_query) | default(item) }}" - vars: - search_query: "data[?name=='{{ item }}'].fingerprint" - # search_query: "data[?(@.name.match('{{ ssh_pubkeys | join ('|') }}'))].fingerprint" - # - # This should be the correct query, but Ansible fatals: - # - # fatal: [localhost]: FAILED! => {"msg": "JMESPathError in json_query filter plugin:\nUnknown function: match()"} - loop: "{{ ssh_pubkeys }}" - - - name: Create enough machine for the course. - community.digitalocean.digital_ocean_droplet: - state: present - name: "{{item}}" - unique_name: yes - ssh_keys: "{{ do_key }}" - size: s-2vcpu-4gb - region: fra1 - image: docker-18-04 - wait_timeout: 500 - user_data: "{{ lookup('file', 'cloudinit.txt') }}" # b64encode is not needed in Ansible - register: my_droplet - with_items: "{{ droplet_names }}" - - - name: Dynamically add the new servers to the inventory. - add_host: - hostname: >- - {{ item.data.droplet.networks.v4 | community.general.json_query(jq) | first }} - groups: - - do - ansible_user: root - host_key_checking: no - with_items: "{{my_droplet.results}}" - vars: - jq: "[?(@.type=='public')].ip_address" - - - name: Create a sample inventory file with the server ips. - file: - path: /tmp/inventory.do - state: absent - - lineinfile: - path: /tmp/inventory.do - create: yes - line: "[do]" - - lineinfile: - path: /tmp/inventory.do - line: > - {{ item.data.droplet.networks.v4 | community.general.json_query(jq) | first }} droplet_id={{item.data.droplet.id}} - with_items: "{{my_droplet.results}}" - vars: - jq: "[?(@.type=='public')].ip_address" + - name: Retrieve ssh key id. + community.digitalocean.digital_ocean_sshkey_info: + oauth_token: "{{ oauth_token }}" + register: ssh_keys + check_mode: no + - name: Set facts based on the gathered information + set_fact: + do_key: "{{ do_key | default([]) + ssh_keys | community.general.json_query(search_query) | default(item) }}" + vars: + search_query: "data[?name=='{{ item }}'].fingerprint" + # search_query: "data[?(@.name.match('{{ ssh_pubkeys | join ('|') }}'))].fingerprint" + # + # This should be the correct query, but Ansible fatals: + # + # fatal: [localhost]: FAILED! => {"msg": "JMESPathError in json_query filter plugin:\nUnknown function: match()"} + loop: "{{ ssh_pubkeys }}" + - name: Create enough machine for the course. + community.digitalocean.digital_ocean_droplet: + state: present + name: "{{item}}" + unique_name: yes + ssh_keys: "{{ do_key }}" + size: s-2vcpu-4gb + region: fra1 + image: docker-18-04 + wait_timeout: 500 + user_data: "{{ lookup('file', 'cloudinit.txt') }}" # b64encode is not needed in Ansible + register: my_droplet + with_items: "{{ droplet_names }}" + - name: Dynamically add the new servers to the inventory. + add_host: + hostname: >- + {{ item.data.droplet.networks.v4 | community.general.json_query(jq) | first }} + groups: + - do + ansible_user: root + host_key_checking: no + with_items: "{{my_droplet.results}}" + vars: + jq: "[?(@.type=='public')].ip_address" + - name: Create a sample inventory file with the server ips. + file: + path: /tmp/inventory.do + state: absent + - lineinfile: + path: /tmp/inventory.do + create: yes + line: "[do]" + - lineinfile: + path: /tmp/inventory.do + line: > + {{ item.data.droplet.networks.v4 | community.general.json_query(jq) | first }} droplet_id={{item.data.droplet.id}} + with_items: "{{my_droplet.results}}" + vars: + jq: "[?(@.type=='public')].ip_address" # # Configure the newly created machines # - hosts: do tags: - - setup + - setup vars: - - ansible_python_interpreter: /usr/bin/python3 - - ansible_user: root + - ansible_python_interpreter: /usr/bin/python3 + - ansible_user: root environment: - - ANSIBLE_HOST_KEY_CHECKING: False + - ANSIBLE_HOST_KEY_CHECKING: False tasks: - - ping: - - block: - - name: Automatic shutdown crontab entry - cron: - name: "shutdown" - hour: 2 # timezone is Etc/UTC - minute: 25 - state: present - disabled: false - job: "/sbin/shutdown -r now" - - - name: Docker should listen on localhost. - lineinfile: - path: /etc/systemd/system/multi-user.target.wants/docker.service - regexp: "^ExecStart=.*" - line: "ExecStart=/usr/bin/dockerd -H fd:// -H tcp://172.17.0.1:2375" - register: systemd_updated - - - name: Install make - apt: name=make - - - name: Reload docker with new systemd config - systemd: - state: restarted - name: docker - daemon_reload: yes - - - name: Check socket - shell: | - ss -tlnp | grep 2375 - - - name: Download course - git: - repo: https://github.com/ioggstream/python-course.git - version: main - dest: /root/python-course - ignore_errors: true - - - name: Make it - shell: | - make course - args: - chdir: /root/python-course/ansible-101 - register: output - - - debug: - var: output - when: true # droplet_id|default(0) != 0 + - ping: + - block: + - name: Automatic shutdown crontab entry + cron: + name: "shutdown" + hour: 2 # timezone is Etc/UTC + minute: 25 + state: present + disabled: false + job: "/sbin/shutdown -r now" + - name: Docker should listen on localhost. + lineinfile: + path: /etc/systemd/system/multi-user.target.wants/docker.service + regexp: "^ExecStart=.*" + line: "ExecStart=/usr/bin/dockerd -H fd:// -H tcp://172.17.0.1:2375" + register: systemd_updated + - name: Install make + apt: name=make + - name: Reload docker with new systemd config + systemd: + state: restarted + name: docker + daemon_reload: yes + - name: Check socket + shell: | + ss -tlnp | grep 2375 + - name: Download course + git: + repo: https://github.com/ioggstream/python-course.git + version: main + dest: /root/python-course + ignore_errors: true + - name: Make it + shell: | + make course + args: + chdir: /root/python-course/ansible-101 + register: output + - debug: + var: output + when: true # droplet_id|default(0) != 0 diff --git a/connexion-101/api/logging.yaml b/connexion-101/api/logging.yaml index c00119d..f0c051c 100644 --- a/connexion-101/api/logging.yaml +++ b/connexion-101/api/logging.yaml @@ -20,4 +20,4 @@ handlers: root: level: DEBUG handlers: - - rfc5424 + - rfc5424 diff --git a/connexion-101/api/simple.yaml b/connexion-101/api/simple.yaml index b37bae1..1dd980d 100644 --- a/connexion-101/api/simple.yaml +++ b/connexion-101/api/simple.yaml @@ -1,19 +1,19 @@ openapi: 3.0.1 -info: { version: 0.1.1, title: hi} +info: {version: 0.1.1, title: hi} servers: -- url: 'https://localhost:8443/hello/v1' + - url: 'https://localhost:8443/hello/v1' # description: dev paths: /echo: get: - summary: Just a method - operationId: api.get_hello - responses: - '200': - description: Hi! - content: - api.ication/json: - schema: {} + summary: Just a method + operationId: api.get_hello + responses: + '200': + description: Hi! + content: + api.ication/json: + schema: {} post: summary: Just a method operationId: api.post_hello @@ -25,29 +25,28 @@ paths: $ref: '#/components/schemas/Text' responses: '200': - description: Hi! + description: Hi! content: api.ication/json: schema: $ref: '#/components/schemas/Text' - /basic-auth: get: - summary: Just a method - security: - - basic: [] - operationId: api.get_hello_auth - responses: - '200': - description: Hi! - content: - api.ication/json: - schema: {} + summary: Just a method + security: + - basic: [] + operationId: api.get_hello_auth + responses: + '200': + description: Hi! + content: + api.ication/json: + schema: {} components: schemas: Text: required: - - text + - text properties: text: type: string diff --git a/connexion-101/deleteme-digitalocean.yml b/connexion-101/deleteme-digitalocean.yml index 035e3c8..265f52c 100644 --- a/connexion-101/deleteme-digitalocean.yml +++ b/connexion-101/deleteme-digitalocean.yml @@ -11,27 +11,26 @@ # - hosts: localhost tasks: - - name: Retrieve ssh key id. - digital_ocean: - state: present - command: ssh - name: rpolli - register: do_key - check_mode: no - - - name: Create enough machine for the course. - digital_ocean: - state: absent - command: droplet - name: "{{item}}" - unique_name: yes - ssh_key_ids: >- - {{do_key.ssh_key.id}} - size_id: 2gb - region_id: fra1 - image_id: docker-18-04 - wait_timeout: 500 - register: my_droplet - with_items: - - deleteme-1 - - deleteme-2 + - name: Retrieve ssh key id. + digital_ocean: + state: present + command: ssh + name: rpolli + register: do_key + check_mode: no + - name: Create enough machine for the course. + digital_ocean: + state: absent + command: droplet + name: "{{item}}" + unique_name: yes + ssh_key_ids: >- + {{do_key.ssh_key.id}} + size_id: 2gb + region_id: fra1 + image_id: docker-18-04 + wait_timeout: 500 + register: my_droplet + with_items: + - deleteme-1 + - deleteme-2 diff --git a/connexion-101/notebooks/oas3/ex-01-info-ok.yaml b/connexion-101/notebooks/oas3/ex-01-info-ok.yaml index 10d3245..b1220c3 100644 --- a/connexion-101/notebooks/oas3/ex-01-info-ok.yaml +++ b/connexion-101/notebooks/oas3/ex-01-info-ok.yaml @@ -48,8 +48,6 @@ info: Qui e' possibile introdurre brevi informazioni tecniche ed esempi. Attenzione: la `description` non sostituisce la documentazione di progetto, deve pero' facilitare l'esecuzione delle prime richieste. - - # I termini del servizio contengono un riferimento # a tutte le indicazioni e le note legali per l'utilizzo # del servizio, inclusi gli eventuali riferimenti utili al GDPR. @@ -69,7 +67,6 @@ info: license: name: Apache 2.0 url: 'http://www.apache.org/licenses/LICENSE-2.0.html' - # Per dare indicazioni sul ciclo di vita dell'API # si puo' usare un parametro come: x-lifecycle: diff --git a/connexion-101/notebooks/oas3/ex-02-servers.yaml b/connexion-101/notebooks/oas3/ex-02-servers.yaml index 8524b4e..5aa1589 100644 --- a/connexion-101/notebooks/oas3/ex-02-servers.yaml +++ b/connexion-101/notebooks/oas3/ex-02-servers.yaml @@ -6,7 +6,6 @@ openapi: 3 info: version: 0.1 - # One or more server # You can add production, staging and test environments. # We are using the custom `x-sandbox` to identify @@ -23,6 +22,5 @@ servers: url: https://api.example.com/datetime/v1/status interval: 300 timeout: 15 - paths: {} components: {} diff --git a/connexion-101/notebooks/oas3/ex-03-02-path-ok.yaml b/connexion-101/notebooks/oas3/ex-03-02-path-ok.yaml index d6a151d..62b735f 100644 --- a/connexion-101/notebooks/oas3/ex-03-02-path-ok.yaml +++ b/connexion-101/notebooks/oas3/ex-03-02-path-ok.yaml @@ -7,7 +7,6 @@ openapi: 3.0.0 info: title: Status API version: "0.1" - # One or more server # You can add production, staging and test environments. # We are using the custom `x-sandbox` to identify @@ -24,7 +23,6 @@ servers: url: https://api.example.com/datetime/v1/status interval: 300 timeout: 15 - # # Complete the /status path # @@ -51,8 +49,7 @@ paths: title: OK status: 200 detail: The app is running smoothly. - - 'default': # EXERCIS SOLUTION, REMOVE + 'default': # EXERCIS SOLUTION, REMOVE description: | If none of the above statuses is returned, then this applies: the application is not working properly. @@ -64,8 +61,7 @@ paths: title: Internal Server Errror status: 500 detail: API is not responding correctly - components: schemas: - Problem: # EXERCIS SOLUTION, REMOVE + Problem: # EXERCIS SOLUTION, REMOVE $ref: 'https://teamdigitale.github.io/openapi/0.0.5/definitions.yaml#/schemas/Problem' diff --git a/connexion-101/notebooks/oas3/ex-05-01-bundle-ok.yaml b/connexion-101/notebooks/oas3/ex-05-01-bundle-ok.yaml index ea8543c..11af42b 100644 --- a/connexion-101/notebooks/oas3/ex-05-01-bundle-ok.yaml +++ b/connexion-101/notebooks/oas3/ex-05-01-bundle-ok.yaml @@ -7,7 +7,6 @@ openapi: 3.0.0 info: title: foo version: "0.1" - # One or more server # You can add production, staging and test environments. # We are using the custom `x-sandbox` to identify @@ -24,12 +23,10 @@ servers: url: https://api.example.com/datetime/v1/status interval: 300 timeout: 15 - x-commons: common-responses: &common-responses 503: $ref: "#/components/responses/503ServiceUnavailable" - # # Complete the /status path # @@ -43,7 +40,7 @@ paths: un errore. operationId: api.get_status responses: - <<: *common-responses + !!merge <<: *common-responses '200': description: | Il server ha ritornato lo status. In caso di problemi @@ -56,10 +53,10 @@ paths: title: OK status: 200 detail: The app is running smoothly. - /echo: # TODO implement this + /echo: # TODO implement this get: parameters: - - $ref: '#/components/parameters/tz' + - $ref: '#/components/parameters/tz' summary: Return the current timestamp in RFC3339 description: | Return the current timestamp, in the specified @@ -68,7 +65,7 @@ paths: the given timezone is not in our database. operationId: api.get_echo responses: - <<: *common-responses + !!merge <<: *common-responses '200': description: | The current timestamp. @@ -79,7 +76,7 @@ paths: example: datetime: 20010507T00:00:10Z '400': - $ref: '#/components/responses/400BadRequest' + $ref: '#/components/responses/400BadRequest' components: parameters: tz: @@ -101,7 +98,7 @@ components: example: Europe/Rome Datetime: required: - - timestamp + - timestamp properties: timestamp: type: string diff --git a/connexion-101/notebooks/oas3/ex-05-01-bundle.yaml b/connexion-101/notebooks/oas3/ex-05-01-bundle.yaml index 39ca679..11a2405 100644 --- a/connexion-101/notebooks/oas3/ex-05-01-bundle.yaml +++ b/connexion-101/notebooks/oas3/ex-05-01-bundle.yaml @@ -3,15 +3,15 @@ info: title: foo version: '0.1' servers: -- description: Development server - url: https://localhost:8443/datetime/v1 -- description: Test server - url: https://api.example.com/datetime/v1 - x-healthCheck: - interval: 300 - timeout: 15 - url: https://api.example.com/datetime/v1/status - x-sandbox: true + - description: Development server + url: https://localhost:8443/datetime/v1 + - description: Test server + url: https://api.example.com/datetime/v1 + x-healthCheck: + interval: 300 + timeout: 15 + url: https://api.example.com/datetime/v1/status + x-sandbox: true paths: /echo: get: @@ -22,7 +22,7 @@ paths: the given timezone is not in our database. operationId: api.get_echo parameters: - - $ref: '#/components/parameters/tz' + - $ref: '#/components/parameters/tz' responses: 503: $ref: '#/components/responses/503ServiceUnavailable' @@ -100,7 +100,7 @@ components: format: datetime type: string required: - - timestamp + - timestamp Problem: properties: detail: diff --git a/connexion-101/notebooks/oas3/ex-07-01-throttling-ok.yaml b/connexion-101/notebooks/oas3/ex-07-01-throttling-ok.yaml index 30f9123..0502c9a 100644 --- a/connexion-101/notebooks/oas3/ex-07-01-throttling-ok.yaml +++ b/connexion-101/notebooks/oas3/ex-07-01-throttling-ok.yaml @@ -7,7 +7,6 @@ openapi: 3.0.0 info: title: foo version: "0.1" - # One or more server # You can add production, staging and test environments. # We are using the custom `x-sandbox` to identify @@ -24,7 +23,6 @@ servers: url: https://api.example.com/datetime/v1/status interval: 300 timeout: 15 - x-commons: throttling-headers: &throttling-headers X-RateLimit-Limit: @@ -33,14 +31,11 @@ x-commons: $ref: 'https://teamdigitale.github.io/openapi/0.0.5/definitions.yaml#/headers/X-RateLimit-Remaining' X-RateLimit-Reset: $ref: 'https://teamdigitale.github.io/openapi/0.0.5/definitions.yaml#/headers/X-RateLimit-Reset' - - common-responses: &common-responses 429: $ref: "#/components/responses/429TooManyRequests" 503: $ref: "#/components/responses/503ServiceUnavailable" - # # Complete the /status path # @@ -54,7 +49,7 @@ paths: un errore. operationId: api.get_status responses: - <<: *common-responses + !!merge <<: *common-responses '200': description: | Il server ha ritornato lo status. In caso di problemi @@ -67,12 +62,12 @@ paths: title: OK status: 200 detail: The app is running smoothly. - /echo: # TODO implement this + /echo: # TODO implement this get: security: - - myBasicAuth: [] + - myBasicAuth: [] parameters: - - $ref: '#/components/parameters/tz' + - $ref: '#/components/parameters/tz' summary: Return the current timestamp in RFC3339 description: | Return the current timestamp, in the specified @@ -81,7 +76,7 @@ paths: the given timezone is not in our database. operationId: api.get_echo responses: - <<: *common-responses + !!merge <<: *common-responses '200': description: | The current timestamp. @@ -92,14 +87,13 @@ paths: example: datetime: 20010507T00:00:10Z '400': - $ref: '#/components/responses/400BadRequest' + $ref: '#/components/responses/400BadRequest' components: securitySchemes: myBasicAuth: - type: http - scheme: basic - x-basicInfoFunc: security.my_auth - + type: http + scheme: basic + x-basicInfoFunc: security.my_auth parameters: tz: name: tz @@ -122,7 +116,7 @@ components: example: Europe/Rome Datetime: required: - - timestamp + - timestamp properties: timestamp: type: string diff --git a/connexion-101/notebooks/oas3/ex-08-pagination-ok.yaml b/connexion-101/notebooks/oas3/ex-08-pagination-ok.yaml index 72c3909..3ba6a46 100644 --- a/connexion-101/notebooks/oas3/ex-08-pagination-ok.yaml +++ b/connexion-101/notebooks/oas3/ex-08-pagination-ok.yaml @@ -2,7 +2,6 @@ openapi: 3.0.0 info: title: foo version: "0.1" - # One or more server # You can add production, staging and test environments. # We are using the custom `x-sandbox` to identify @@ -19,7 +18,6 @@ servers: url: https://api.example.com/datetime/v1/status interval: 300 timeout: 15 - x-commons: throttling-headers: &throttling-headers X-RateLimit-Limit: @@ -28,13 +26,11 @@ x-commons: $ref: 'https://teamdigitale.github.io/openapi/0.0.5/definitions.yaml#/headers/X-RateLimit-Remaining' X-RateLimit-Reset: $ref: 'https://teamdigitale.github.io/openapi/0.0.5/definitions.yaml#/headers/X-RateLimit-Reset' - common-responses: &common-responses '429': $ref: "#/components/responses/429TooManyRequests" '503': $ref: "#/components/responses/503ServiceUnavailable" - # # Complete the /status path # @@ -48,7 +44,7 @@ paths: un errore. operationId: api.get_status responses: - <<: *common-responses + !!merge <<: *common-responses '200': description: | Il server ha ritornato lo status. In caso di problemi @@ -61,12 +57,12 @@ paths: title: OK status: 200 detail: The app is running smoothly. - /echo: # TODO implement this + /echo: # TODO implement this get: security: - - myBasicAuth: [] + - myBasicAuth: [] parameters: - - $ref: '#/components/parameters/tz' + - $ref: '#/components/parameters/tz' summary: Return the current timestamp in RFC3339 description: | Return the current timestamp, in the specified @@ -75,12 +71,12 @@ paths: the given timezone is not in our database. operationId: api.get_echo responses: - <<: *common-responses + !!merge <<: *common-responses '200': description: | The current timestamp. headers: - <<: *throttling-headers + !!merge <<: *throttling-headers content: application/problem+json: schema: @@ -88,12 +84,12 @@ paths: example: datetime: 20010507T00:00:10Z '400': - $ref: '#/components/responses/400BadRequest' - /timezones: # TODO implement this + $ref: '#/components/responses/400BadRequest' + /timezones: # TODO implement this get: parameters: - - $ref: "https://teamdigitale.github.io/openapi/0.0.5/definitions.yaml#/parameters/limit" - - $ref: "https://teamdigitale.github.io/openapi/0.0.5/definitions.yaml#/parameters/offset" + - $ref: "https://teamdigitale.github.io/openapi/0.0.5/definitions.yaml#/parameters/limit" + - $ref: "https://teamdigitale.github.io/openapi/0.0.5/definitions.yaml#/parameters/offset" summary: Return the supported timezones description: | Return a paginated list of supported @@ -101,27 +97,27 @@ paths: list of entries is returned. operationId: api.get_timezones responses: - <<: *common-responses + !!merge <<: *common-responses '200': description: | A list of timezones between offset and limit. headers: - <<: *throttling-headers + !!merge <<: *throttling-headers content: application/json: schema: $ref: "#/components/schemas/Timezones" example: - entries: [ "Europe/Rome", "Asia/Calcutta", "UTC" ] + entries: ["Europe/Rome", "Asia/Calcutta", "UTC"] limit: 3 offset: 10 count: 3 - /timezones/{continent}: # TODO implement this + /timezones/{continent}: # TODO implement this get: parameters: - - $ref: "https://teamdigitale.github.io/openapi/0.0.5/definitions.yaml#/parameters/limit" - - $ref: "https://teamdigitale.github.io/openapi/0.0.5/definitions.yaml#/parameters/offset" - - $ref: "#/components/parameters/continent_path" + - $ref: "https://teamdigitale.github.io/openapi/0.0.5/definitions.yaml#/parameters/limit" + - $ref: "https://teamdigitale.github.io/openapi/0.0.5/definitions.yaml#/parameters/offset" + - $ref: "#/components/parameters/continent_path" summary: Return the supported timezones description: | Return a paginated list of supported @@ -129,32 +125,29 @@ paths: out of bound. operationId: api.get_timezones_by_continent responses: - <<: *common-responses + !!merge <<: *common-responses '200': description: | A list of timezones between offset and limit. headers: - <<: *throttling-headers + !!merge <<: *throttling-headers content: application/json: schema: $ref: "#/components/schemas/Timezones" example: - entries: [ "Europe/Amsterdam", "Europe/Andorra", "Europe/Astrakhan" ] + entries: ["Europe/Amsterdam", "Europe/Andorra", "Europe/Astrakhan"] limit: 3 offset: 0 count: 3 '404': - $ref: '#/components/responses/404NotFound' - - + $ref: '#/components/responses/404NotFound' components: securitySchemes: myBasicAuth: - type: http - scheme: basic - x-basicInfoFunc: security.my_auth - + type: http + scheme: basic + x-basicInfoFunc: security.my_auth parameters: continent_path: name: continent @@ -167,7 +160,6 @@ components: in: query schema: $ref: '#/components/schemas/Timezone' - responses: 400BadRequest: $ref: "https://teamdigitale.github.io/openapi/0.0.5/definitions.yaml#/responses/400BadRequest" @@ -177,14 +169,13 @@ components: $ref: "https://teamdigitale.github.io/openapi/0.0.5/definitions.yaml#/responses/429TooManyRequests" 503ServiceUnavailable: $ref: "https://teamdigitale.github.io/openapi/0.0.5/definitions.yaml#/responses/503ServiceUnavailable" - schemas: Timezones: required: - - limit - - count - - offset - - entries + - limit + - count + - offset + - entries properties: limit: type: number @@ -207,7 +198,7 @@ components: example: Europe/Rome Datetime: required: - - timestamp + - timestamp properties: timestamp: type: string diff --git a/connexion-101/notebooks/oas3/store.yaml b/connexion-101/notebooks/oas3/store.yaml index 9caae0b..d72942e 100644 --- a/connexion-101/notebooks/oas3/store.yaml +++ b/connexion-101/notebooks/oas3/store.yaml @@ -21,7 +21,6 @@ x-commons: $ref: 'https://teamdigitale.github.io/openapi/0.0.5/definitions.yaml#/headers/X-RateLimit-Remaining' X-RateLimit-Reset: $ref: 'https://teamdigitale.github.io/openapi/0.0.5/definitions.yaml#/headers/X-RateLimit-Reset' - openapi: 3.0.1 info: title: Flask store API. @@ -95,7 +94,7 @@ paths: get: operationId: openapi.get_status responses: - <<: *common-responses + !!merge <<: *common-responses 200: description: | The API is working properly. @@ -111,7 +110,6 @@ paths: application/problem+json: schema: $ref: '#/components/schemas/Problem' - /stores: get: operationId: openapi.list_files @@ -123,11 +121,11 @@ paths: - $ref: 'https://teamdigitale.github.io/openapi/0.0.5/definitions.yaml#/parameters/fields' - $ref: 'https://teamdigitale.github.io/openapi/0.0.5/definitions.yaml#/parameters/limit' responses: - <<: *common-responses + !!merge <<: *common-responses '200': description: Retrieve a list of stored files. headers: - <<: *throttling-headers + !!merge <<: *throttling-headers content: application/json: schema: @@ -158,15 +156,14 @@ paths: content: multipart/related: schema: {} - # $ref: '#/components/schemas/UploadFiles' - + # $ref: '#/components/schemas/UploadFiles' responses: - <<: *common-responses + !!merge <<: *common-responses '201': description: |- The files are properly indexed and stored. headers: - <<: *throttling-headers + !!merge <<: *throttling-headers content: multipart/related: {} components: @@ -186,7 +183,6 @@ components: items: type: string format: binary - Problem: $ref: 'https://teamdigitale.github.io/openapi/0.0.5/definitions.yaml#/schemas/Problem' Metadata: @@ -200,7 +196,6 @@ components: type: number id: type: string - responses: # Predefined error codes for this API 400BadRequest: diff --git a/connexion-101/site-digitalocean.yml b/connexion-101/site-digitalocean.yml index 91f9d3b..eb50bbf 100644 --- a/connexion-101/site-digitalocean.yml +++ b/connexion-101/site-digitalocean.yml @@ -11,98 +11,89 @@ # - hosts: localhost tasks: - - name: Retrieve ssh key id. - digital_ocean: - state: present - command: ssh - name: rpolli - register: do_key + - name: Retrieve ssh key id. + digital_ocean: + state: present + command: ssh + name: rpolli + register: do_key + - name: Create enough machine for the course. + digital_ocean: + state: present + unique_name: yes + command: droplet + name: "{{item}}" + ssh_key_ids: >- + {{do_key.ssh_key.id}} + size_id: 2gb + region_id: fra1 + image_id: docker-18-04 + wait_timeout: 500 + register: my_droplet + with_items: + - deleteme-1 + - name: Dynamically add the new servers to the inventory. + add_host: + hostname: > + {{ item.droplet.networks.v4[0].ip_address }} - - name: Create enough machine for the course. - digital_ocean: - state: present - unique_name: yes - command: droplet - name: "{{item}}" - ssh_key_ids: >- - {{do_key.ssh_key.id}} - size_id: 2gb - region_id: fra1 - image_id: docker-18-04 - wait_timeout: 500 - register: my_droplet - with_items: - - deleteme-1 - - - name: Dynamically add the new servers to the inventory. - add_host: - hostname: > - {{ item.droplet.networks.v4[0].ip_address }} - groups: do - ansible_user: root - host_key_checking: no - with_items: "{{my_droplet.results}}" - - - - name: Create a sample inventory file with the server ips. - file: - path: /tmp/inventory.do - state: absent - - lineinfile: - path: /tmp/inventory.do - create: yes - line: "[do]" - - lineinfile: - path: /tmp/inventory.do - line: > - {{ item.droplet.networks.v4[0].ip_address }} droplet_id={{item.droplet.id}} - with_items: "{{my_droplet.results}}" + groups: do + ansible_user: root + host_key_checking: no + with_items: "{{my_droplet.results}}" + - name: Create a sample inventory file with the server ips. + file: + path: /tmp/inventory.do + state: absent + - lineinfile: + path: /tmp/inventory.do + create: yes + line: "[do]" + - lineinfile: + path: /tmp/inventory.do + line: > + {{ item.droplet.networks.v4[0].ip_address }} droplet_id={{item.droplet.id}} + with_items: "{{my_droplet.results}}" # # Configure the newly created machines # - hosts: do vars: - - ansible_python_interpreter: /usr/bin/python3 - - ansible_user: root + - ansible_python_interpreter: /usr/bin/python3 + - ansible_user: root environment: - - ANSIBLE_HOST_KEY_CHECKING: False + - ANSIBLE_HOST_KEY_CHECKING: False tasks: - - name: Docker should listen on localhost. - lineinfile: - path: /etc/systemd/system/multi-user.target.wants/docker.service - regexp: "^ExecStart=.*" - line: "ExecStart=/usr/bin/dockerd -H fd:// -H tcp://172.17.0.1:2375" - register: systemd_updated - - - name: Reload docker with new systemd config - systemd: - state: restarted - name: docker - daemon_reload: yes - when: systemd_updated.changed - - - name: Check socket - shell: | - ss -tlnp | grep 2375 - - - name: Download course - git: - repo: https://github.com/ioggstream/python-course.git - dest: /root/python-course - version: master - - - name: install deps - package: - name: - - make - - - name: Make it - shell: | - make course - args: - chdir: /root/python-course/connexion-101 - register: output - - - debug: - var: output + - name: Docker should listen on localhost. + lineinfile: + path: /etc/systemd/system/multi-user.target.wants/docker.service + regexp: "^ExecStart=.*" + line: "ExecStart=/usr/bin/dockerd -H fd:// -H tcp://172.17.0.1:2375" + register: systemd_updated + - name: Reload docker with new systemd config + systemd: + state: restarted + name: docker + daemon_reload: yes + when: systemd_updated.changed + - name: Check socket + shell: | + ss -tlnp | grep 2375 + - name: Download course + git: + repo: https://github.com/ioggstream/python-course.git + dest: /root/python-course + version: master + - name: install deps + package: + name: + - make + - name: Make it + shell: | + make course + args: + chdir: /root/python-course/connexion-101 + register: output + - debug: + var: output diff --git a/mongodb-101/docker-compose.yml b/mongodb-101/docker-compose.yml index dfa7b84..bb690fa 100644 --- a/mongodb-101/docker-compose.yml +++ b/mongodb-101/docker-compose.yml @@ -1,28 +1,25 @@ # Image for developing the course version: "3" services: - test: - image: ioggstream/centos8:jupyter - volumes: + image: ioggstream/centos8:jupyter + volumes: - ./notebooks:/notebooks:z # entrypoint: tail -f /etc/hosts - - # Official image from docker hub course: - image: ioggstream/centos8:jupyter - hostname: course - environment: + image: ioggstream/centos8:jupyter + hostname: course + environment: - USE_HTTP=1 - DOCKER_HOST=172.17.0.1 - volumes: + volumes: - ./notebooks:/notebooks:z - ./notebooks/custom.css:/root/.jupyter/custom/custom.css - ./notebooks/startup:/root/.ipython/profile_default/startup:z - .:/code:z - network_mode: bridge - ports: + network_mode: bridge + ports: - 8888:8888 - entrypoint: /usr/bin/bash - command: -c "/usr/local/bin/jupyter-notebook --ip 0.0.0.0 --allow-root" + entrypoint: /usr/bin/bash + command: -c "/usr/local/bin/jupyter-notebook --ip 0.0.0.0 --allow-root" diff --git a/mongodb-101/site-digitalocean.yml b/mongodb-101/site-digitalocean.yml index 5335ec7..79195b9 100644 --- a/mongodb-101/site-digitalocean.yml +++ b/mongodb-101/site-digitalocean.yml @@ -11,103 +11,94 @@ # - hosts: localhost tasks: - - name: Retrieve ssh key id. - digital_ocean: - state: present - command: ssh - name: rpolli - register: do_key + - name: Retrieve ssh key id. + digital_ocean: + state: present + command: ssh + name: rpolli + register: do_key + - name: Create enough machine for the course. + digital_ocean: + state: present + unique_name: yes + command: droplet + name: "{{item}}" + ssh_key_ids: >- + {{do_key.ssh_key.id}} + size_id: 8gb + region_id: fra1 + image_id: docker-18-04 + wait_timeout: 500 + register: my_droplet + with_items: + - deleteme-1 + - deleteme-2 + - deleteme-3 + - deleteme-4 + - deleteme-5 + - deleteme-6 + - name: Dynamically add the new servers to the inventory. + add_host: + hostname: > + {{ item.droplet.networks.v4[0].ip_address }} - - name: Create enough machine for the course. - digital_ocean: - state: present - unique_name: yes - command: droplet - name: "{{item}}" - ssh_key_ids: >- - {{do_key.ssh_key.id}} - size_id: 8gb - region_id: fra1 - image_id: docker-18-04 - wait_timeout: 500 - register: my_droplet - with_items: - - deleteme-1 - - deleteme-2 - - deleteme-3 - - deleteme-4 - - deleteme-5 - - deleteme-6 - - - name: Dynamically add the new servers to the inventory. - add_host: - hostname: > - {{ item.droplet.networks.v4[0].ip_address }} - groups: do - ansible_user: root - host_key_checking: no - with_items: "{{my_droplet.results}}" - - - - name: Create a sample inventory file with the server ips. - file: - path: /tmp/inventory.do - state: absent - - lineinfile: - path: /tmp/inventory.do - create: yes - line: "[do]" - - lineinfile: - path: /tmp/inventory.do - line: > - {{ item.droplet.networks.v4[0].ip_address }} droplet_id={{item.droplet.id}} - with_items: "{{my_droplet.results}}" + groups: do + ansible_user: root + host_key_checking: no + with_items: "{{my_droplet.results}}" + - name: Create a sample inventory file with the server ips. + file: + path: /tmp/inventory.do + state: absent + - lineinfile: + path: /tmp/inventory.do + create: yes + line: "[do]" + - lineinfile: + path: /tmp/inventory.do + line: > + {{ item.droplet.networks.v4[0].ip_address }} droplet_id={{item.droplet.id}} + with_items: "{{my_droplet.results}}" # # Configure the newly created machines # - hosts: do vars: - - ansible_python_interpreter: /usr/bin/python3 - - ansible_user: root + - ansible_python_interpreter: /usr/bin/python3 + - ansible_user: root environment: - - ANSIBLE_HOST_KEY_CHECKING: False + - ANSIBLE_HOST_KEY_CHECKING: False tasks: - - name: Docker should listen on localhost. - lineinfile: - path: /etc/systemd/system/multi-user.target.wants/docker.service - regexp: "^ExecStart=.*" - line: "ExecStart=/usr/bin/dockerd -H fd:// -H tcp://172.17.0.1:2375" - register: systemd_updated - - - name: Reload docker with new systemd config - systemd: - state: restarted - name: docker - daemon_reload: yes - when: systemd_updated.changed - - - name: Check socket - shell: | - ss -tlnp | grep 2375 - - - name: Download course - git: - repo: https://github.com/ioggstream/python-course.git - dest: /root/python-course - version: master - - - name: install deps - package: - name: - - make - - - name: Make it - shell: | - make course - args: - chdir: /root/python-course/mongodb-101 - register: output - - - debug: - var: output + - name: Docker should listen on localhost. + lineinfile: + path: /etc/systemd/system/multi-user.target.wants/docker.service + regexp: "^ExecStart=.*" + line: "ExecStart=/usr/bin/dockerd -H fd:// -H tcp://172.17.0.1:2375" + register: systemd_updated + - name: Reload docker with new systemd config + systemd: + state: restarted + name: docker + daemon_reload: yes + when: systemd_updated.changed + - name: Check socket + shell: | + ss -tlnp | grep 2375 + - name: Download course + git: + repo: https://github.com/ioggstream/python-course.git + dest: /root/python-course + version: master + - name: install deps + package: + name: + - make + - name: Make it + shell: | + make course + args: + chdir: /root/python-course/mongodb-101 + register: output + - debug: + var: output diff --git a/mysql-101/ansible/initialize-innodbcluster.yml b/mysql-101/ansible/initialize-innodbcluster.yml index 1d154cb..2580b5e 100644 --- a/mysql-101/ansible/initialize-innodbcluster.yml +++ b/mysql-101/ansible/initialize-innodbcluster.yml @@ -7,52 +7,47 @@ register: has_group_replication changed_when: false failed_when: false - - when: has_group_replication.rc == 1 block: - - name: close mysqld - shell: | - pkill -f mysqld - failed_when: false - - name: Create directory - shell: | - rm /var/lib/mysql/* -fr - - name: Add server_id to my.cnf - lineinfile: - dest: /etc/my.cnf - line: | - server_id={{ ansible_default_ipv4_address | ipaddr("int") }} - insertafter: >- - ^[mysqld] - - name: Prepare node for group replication - blockinfile: - dest: /etc/my.cnf - insertafter: >- - ^[mysqld] - block: | - log_bin=1 - gtid_mode=ON - enforce_gtid_consistency=ON - binlog_format=ROW - master_info_repository=TABLE - relay_log_info_repository=TABLE - report_port=3306 - report_host={{ansible_default_ipv4_address}} - log_slave_updates=1 - transaction_write_set_extraction=XXHASH64 - binlog_checksum=NONE - - - - name: Initialize datadir - command: | - mysqld --initialize --user=mysql - + - name: close mysqld + shell: | + pkill -f mysqld + failed_when: false + - name: Create directory + shell: | + rm /var/lib/mysql/* -fr + - name: Add server_id to my.cnf + lineinfile: + dest: /etc/my.cnf + line: | + server_id={{ ansible_default_ipv4_address | ipaddr("int") }} + insertafter: >- + ^[mysqld] + - name: Prepare node for group replication + blockinfile: + dest: /etc/my.cnf + insertafter: >- + ^[mysqld] + block: | + log_bin=1 + gtid_mode=ON + enforce_gtid_consistency=ON + binlog_format=ROW + master_info_repository=TABLE + relay_log_info_repository=TABLE + report_port=3306 + report_host={{ansible_default_ipv4_address}} + log_slave_updates=1 + transaction_write_set_extraction=XXHASH64 + binlog_checksum=NONE + - name: Initialize datadir + command: | + mysqld --initialize --user=mysql - name: Eventually start mysql command: pgrep -fa mysqld.*-- register: mysqld_status changed_when: false failed_when: false - - name: First boot when: >- mysqld_status.rc != 0 @@ -61,21 +56,17 @@ async: 300 poll: 0 register: mysqld_jid - - name: Wait for mysql wait_for: host: 0.0.0.0 port: 3306 delay: 1 timeout: 20 - - name: Prepare instance for clustering command: mysqlsh --js -f /code/ansible/check-cluster.js --log-level=DEBUG4 ignore_errors: true - - name: Take a nap pause: seconds=5 - # - debug: msg="Contacting {{innodb[0]}} for creating cluster." - name: Deploy template files tags: template @@ -83,24 +74,24 @@ src: "{{item}}" dest: /root/ with_items: - - create-cluster.js - - add-node.js - + - create-cluster.js + - add-node.js - name: Create cluster on local node run_once: yes delegate_to: "{{groups['innodb'][0]}}" shell: > mysqlsh --uri icroot@{{ansible_default_ipv4_address}}:3306 + + + --password=Secret%2017 --log-level=DEBUG4 --js -f /root/create-cluster.js - - name: Add instances to cluster delegate_to: "{{groups['innodb'][0]}}" when: >- ansible_hostname in groups['innodb'][1:] shell: > - mysqlsh --uri icroot@localhost:3306 --password=Secret%2017 --log-level=DEBUG4 - --js -f /root/add-node.js + mysqlsh --uri icroot@localhost:3306 --password=Secret%2017 --log-level=DEBUG4 --js -f /root/add-node.js - name: Kill mysql command: pkill -f mysqld diff --git a/mysql-101/ansible/install-mysql.yml b/mysql-101/ansible/install-mysql.yml index 3ee646e..e9d7677 100644 --- a/mysql-101/ansible/install-mysql.yml +++ b/mysql-101/ansible/install-mysql.yml @@ -1,35 +1,30 @@ - hosts: innodb tasks: - - package: - name: https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm - - - package: - name: "{{item}}" - with_items: - - mysql-community-server - - mysql-community-client - - mysql-utilities - - mysql-router - - mysql-shell - - - name: Install sshd - package: - name: openssh - - - name: Start - service: - name: sshd - state: started - enabled: yes - - - name: Distribute keys - copy: - src: "{{item}}" - dest: /root/.ssh/ - mode: 0600 - with_items: - - id_ecdsa_inno - - authorized_keys - - - name: Configure innodb cluster - include: initialize-innodbcluster.yml + - package: + name: https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm + - package: + name: "{{item}}" + with_items: + - mysql-community-server + - mysql-community-client + - mysql-utilities + - mysql-router + - mysql-shell + - name: Install sshd + package: + name: openssh + - name: Start + service: + name: sshd + state: started + enabled: yes + - name: Distribute keys + copy: + src: "{{item}}" + dest: /root/.ssh/ + mode: 0600 + with_items: + - id_ecdsa_inno + - authorized_keys + - name: Configure innodb cluster + include: initialize-innodbcluster.yml diff --git a/python-basic/docker-compose.yml b/python-basic/docker-compose.yml index cad8615..28afdf9 100644 --- a/python-basic/docker-compose.yml +++ b/python-basic/docker-compose.yml @@ -1,19 +1,18 @@ sysadminpy: - build: . - hostname: sysadminpy - environment: - - USE_HTTP=1 - - PASSWORD=secret - - SHELL=/bin/bash - ports: - - 8888:8888 - volumes: - - ./rendered_notebooks:/notebooks - + build: . + hostname: sysadminpy + environment: + - USE_HTTP=1 + - PASSWORD=secret + - SHELL=/bin/bash + ports: + - 8888:8888 + volumes: + - ./rendered_notebooks:/notebooks test: - image: ioggstream/python-course:dev - volumes: - - .:/notebooks - ports: - - 18888:8888 - entrypoint: tail -f /etc/hosts + image: ioggstream/python-course:dev + volumes: + - .:/notebooks + ports: + - 18888:8888 + entrypoint: tail -f /etc/hosts diff --git a/python-for-sysadmin/docker-compose.yml b/python-for-sysadmin/docker-compose.yml index 37f0278..2afd74f 100644 --- a/python-for-sysadmin/docker-compose.yml +++ b/python-for-sysadmin/docker-compose.yml @@ -1,33 +1,29 @@ # Image for developing the course dev: - build: . - hostname: sysadminpy - environment: - - USE_HTTP=1 - - PASSWORD=secret - ports: - - 8888:8888 - volumes: - - ./rendered_notebooks:/notebooks - + build: . + hostname: sysadminpy + environment: + - USE_HTTP=1 + - PASSWORD=secret + ports: + - 8888:8888 + volumes: + - ./rendered_notebooks:/notebooks test: - image: ioggstream/python-course - volumes: - - .:/notebooks:z + image: ioggstream/python-course + volumes: + - .:/notebooks:z # entrypoint: tail -f /etc/hosts - - # Official image from docker hub course: - image: ioggstream/python-course - volumes: - - .:/notebooks:z - ports: - - 8888:8888 - + image: ioggstream/python-course + volumes: + - .:/notebooks:z + ports: + - 8888:8888 # Some ssh-enabled docker containers # for student homework ansible: - image: itscaro/debian-ssh:latest - volumes: - - .:/code:z + image: itscaro/debian-ssh:latest + volumes: + - .:/code:z diff --git a/python-for-sysadmin/notebooks/ansible/python-course-test.yml b/python-for-sysadmin/notebooks/ansible/python-course-test.yml index f61894a..e36d360 100644 --- a/python-for-sysadmin/notebooks/ansible/python-course-test.yml +++ b/python-for-sysadmin/notebooks/ansible/python-course-test.yml @@ -6,12 +6,10 @@ tasks: - name: The /notebooks directory should exist file: path="/notebooks" state=directory - - name: jupyter is responding on 8888 uri: url: http://0.0.0.0:8888/notebooks validate_certs: false - status_code: 200 # modify this line to simulate an error and see the outcome! - + status_code: 200 # modify this line to simulate an error and see the outcome! - name: The template.conf is in place file: path="/tmp/template.conf" state=file diff --git a/python-for-sysadmin/notebooks/logger.yml b/python-for-sysadmin/notebooks/logger.yml index 4b327bc..d6898e2 100644 --- a/python-for-sysadmin/notebooks/logger.yml +++ b/python-for-sysadmin/notebooks/logger.yml @@ -3,7 +3,6 @@ formatters: detailed: class: logging.Formatter format: '%(asctime)s %(name)-15s %(levelname)-8s %(processName)-10s %(message)s' - handlers: console: class: logging.StreamHandler @@ -12,11 +11,9 @@ handlers: class: logging.handlers.SysLogHandler formatter: detailed level: DEBUG - loggers: os: handlers: [syslog] - root: handlers: [console, syslog] level: DEBUG diff --git a/sparql-101/docker-compose.yaml b/sparql-101/docker-compose.yaml index 62b8ffd..21dea21 100644 --- a/sparql-101/docker-compose.yaml +++ b/sparql-101/docker-compose.yaml @@ -2,13 +2,13 @@ services: course: build: . volumes: - - ".:/code:rw" + - ".:/code:rw" working_dir: /code/notebooks user: "1000" environment: - - "HOME=/code/notebooks" + - "HOME=/code/notebooks" ports: - - "8888:8888" + - "8888:8888" command: - - notebook - - --ip=0.0.0.0 + - notebook + - --ip=0.0.0.0 diff --git a/sparql-101/notebooks/guestbook-all-in-one.yaml b/sparql-101/notebooks/guestbook-all-in-one.yaml index a223dab..bd7a770 100644 --- a/sparql-101/notebooks/guestbook-all-in-one.yaml +++ b/sparql-101/notebooks/guestbook-all-in-one.yaml @@ -8,8 +8,8 @@ metadata: role: master spec: ports: - - port: 6379 - targetPort: 6379 + - port: 6379 + targetPort: 6379 selector: app: redis tier: backend @@ -34,14 +34,14 @@ spec: tier: backend spec: containers: - - name: master - image: registry.k8s.io/redis:e2e # or just image: redis - resources: - requests: - cpu: 100m - memory: 100Mi - ports: - - containerPort: 6379 + - name: master + image: registry.k8s.io/redis:e2e # or just image: redis + resources: + requests: + cpu: 100m + memory: 100Mi + ports: + - containerPort: 6379 --- apiVersion: v1 kind: Service @@ -53,7 +53,7 @@ metadata: role: replica spec: ports: - - port: 6379 + - port: 6379 selector: app: redis tier: backend @@ -78,22 +78,22 @@ spec: tier: backend spec: containers: - - name: replica - image: gcr.io/google_samples/gb-redisslave:v1 - resources: - requests: - cpu: 100m - memory: 100Mi - env: - - name: GET_HOSTS_FROM - value: dns - # If your cluster config does not include a dns service, then to - # instead access an environment variable to find the master - # service's host, comment out the 'value: dns' line above, and - # uncomment the line below: - # value: env - ports: - - containerPort: 6379 + - name: replica + image: gcr.io/google_samples/gb-redisslave:v1 + resources: + requests: + cpu: 100m + memory: 100Mi + env: + - name: GET_HOSTS_FROM + value: dns + # If your cluster config does not include a dns service, then to + # instead access an environment variable to find the master + # service's host, comment out the 'value: dns' line above, and + # uncomment the line below: + # value: env + ports: + - containerPort: 6379 --- apiVersion: v1 kind: Service @@ -109,7 +109,7 @@ spec: # an external load-balanced IP for the frontend service. # type: LoadBalancer ports: - - port: 80 + - port: 80 selector: app: guestbook tier: frontend @@ -131,19 +131,19 @@ spec: tier: frontend spec: containers: - - name: php-redis - image: gcr.io/google-samples/gb-frontend:v5 - resources: - requests: - cpu: 100m - memory: 100Mi - env: - - name: GET_HOSTS_FROM - value: dns - # If your cluster config does not include a dns service, then to - # instead access environment variables to find service host - # info, comment out the 'value: dns' line above, and uncomment the - # line below: - # value: env - ports: - - containerPort: 80 + - name: php-redis + image: gcr.io/google-samples/gb-frontend:v5 + resources: + requests: + cpu: 100m + memory: 100Mi + env: + - name: GET_HOSTS_FROM + value: dns + # If your cluster config does not include a dns service, then to + # instead access environment variables to find service host + # info, comment out the 'value: dns' line above, and uncomment the + # line below: + # value: env + ports: + - containerPort: 80