introduction
play

Introduction digitalocean.com What does DO do? Simple, - PowerPoint PPT Presentation

Introduction digitalocean.com What does DO do? Simple, Developer-focused Cloud Hosting digitalocean.com What are we using Ansible for? digitalocean.com Example Deployment digitalocean.com Example Project Layout digitalocean.com Project


  1. Introduction digitalocean.com

  2. What does DO do? Simple, Developer-focused Cloud Hosting digitalocean.com

  3. What are we using Ansible for? digitalocean.com

  4. Example Deployment digitalocean.com

  5. Example Project Layout digitalocean.com

  6. Project Layout ● Inventories Local Module Library ● ● Group Variables / Host Variables Roles ● ○ Component roles Project Specific Roles ○ ● Playbooks Server Templates ○ ○ Cluster Configuration Actions ○ ● Makefiles digitalocean.com

  7. Inventories ● List hosts (by environment) Define groups ● ● Guardrails ansible-playbook -i inventories/development ... digitalocean.com

  8. Inventories ● List hosts (by environment) all: children: Define groups ● mysql: children: ● Guardrails mysql_managed: hosts: test-mysql-0[1:3].atlantic.com: test-mysql-0[1:6].pacific.com: mysql_unmanaged: digitalocean.com

  9. Inventories ● List hosts (by environment) Define groups ● ● Guardrails ansible-playbook ... --extra-vars="target_env=development” ... Playbook: --- - hosts: mysql:!mysql_unmanaged:&{{ target_env }} ... digitalocean.com

  10. Inventories: Constructed Groups plugin: constructed strict: false groups: dev: inventory_hostname.startswith('dev-') digitalocean.com

  11. Inventories: Constructed Groups plugin: constructed strict: false groups: dev_mysql: (group_names|intersect(['mysql', 'dev']))|length >= 2 digitalocean.com

  12. Inventories: Ordering inventories - development - 10_mysql.yml - 90_environment.yml - 99_dev_mysql.yml - production - staging digitalocean.com

  13. Variable Order of Precedence 1. command values (eg “-u user”) 12. play vars 2. role defaults 13. play vars_prompt 3. inventory file or script group vars 14. play vars_files 4. inventory group_vars/all 15. role vars (defined in role/vars/main.yml) 5. playbook group_vars/all 16. block vars (only for tasks in block) 6. inventory group_vars/* 17. task vars (only for the task) 7. playbook group_vars/* 18. include_vars 8. inventory file or script host vars 19. set_facts / registered vars 9. inventory host_vars/* 20. role (and include_role) params 10. playbook host_vars/* 21. include params 11. host facts / cached set_facts 22. extra vars (always win precedence) digitalocean.com

  14. Variable Management ● Role defaults interface with the role ● Define project level generic variables applicable to all environments playbook group_vars/all ○ ○ playbook group_vars/* ● Host specific overrides ○ inventory host_vars/* Variables we construct ● ○ role vars / include_vars / set_facts ● Functional role variables ○ role (and include_role) params Guardrails ● ○ extra vars (always win precedence) digitalocean.com

  15. Variable Management Example - Defaults --- ### proxysql install proxysql_create_image: "{{ global_create_image | default(false) }}" proxysql_download_src: https://github.com/sysown/proxysql/releases/download proxysql_version: 1.4.10 proxysql_mysql_client_version: 5.7 proxysql_user: proxysql proxysql_group: proxysql proxysql_datadir: /var/lib/proxysql proxysql_restart_missing_heartbeats: 10 ... # autocommit proxysql_mysql_autocommit_false_is_transaction: false proxysql_mysql_autocommit_false_not_reusable: false proxysql_mysql_enforce_autocommit_on_reads: false proxysql_mysql_forward_autocommit: false ... digitalocean.com

  16. Variable Management Example - Vars --- ... ### percona required packages proxysql_release: "{{ proxysql_download_src }}/v{{ proxysql_version }}/proxysql_{{ proxysql_version }}-ubuntu18_amd64.deb" ... proxysql_mysql_variables: autocommit_false_is_transaction: variable: "autocommit_false_is_transaction" variable_value: "{{ proxysql_mysql_autocommit_false_is_transaction | to_json }}" autocommit_false_not_reusable: variable: "autocommit_false_not_reusable" variable_value: "{{ proxysql_mysql_autocommit_false_not_reusable | to_json }}" client_found_rows: variable: "client_found_rows" variable_value: "{{ proxysql_mysql_client_found_rows | to_json }}" ... digitalocean.com

  17. Variable Management Example - Config #jinja2: lstrip_blocks: "true" datadir="{{ proxysql_datadir }}" restart_on_missing_heartbeats={{ proxysql_restart_missing_heartbeats }} admin_variables= { {% for config_item in proxysql_admin_variables|dictsort %} {% if config_item.1.variable_value is not none %} {{ config_item.1.variable }}={{ config_item.1.variable_value | to_json }} {% endif %} {% endfor %} } mysql_variables= { {% for config_item in proxysql_mysql_variables|dictsort %} {% if config_item.1.variable_value is not none %} {{ config_item.1.variable }}={{ config_item.1.variable_value | to_json }} {% endif %} {% endfor %} } digitalocean.com

  18. Anatomy of a Role digitalocean.com

  19. Anatomy of a Role ● A role should be map to a single unit of functionality that utilise a common set of variables. Roles should be intuitive , and wherever possible mimic a common structure. ● ● Role Variable Management Where possible, a [component] role should be generic , and any variables should map ○ to sensible defaults . The interface into role customisation should be via scalar role defaults. ○ ○ Role variables should be used for variables that shouldn't be overridden in normal circumstance, or as syntactic sugar to construct variables internal to the role. ● A role should have repeatable logic and should avoid logical branching that might be non-repeatable . digitalocean.com

  20. Component Roles digitalocean.com

  21. Role Versioning - name: role_mysql_proxysql src: git+ssh://git@github.pacific.com/ansible/role_mysql_proxysql.git version: 1.1.1 digitalocean.com

  22. Example ProxySQL Deployment digitalocean.com

  23. Testing Roles digitalocean.com

  24. Molecule ● pip install --user molecule pip install --user molecule[ec2] ○ ○ pip install --user molecule[docker] digitalocean.com

  25. Molecule Commands ● create / destroy / list / cleanup prepare ● ● dependency ● login digitalocean.com

  26. Anatomy of a Role digitalocean.com

  27. Molecule Commands ● lint syntax ● ● idempotence ● verify ● check digitalocean.com

  28. Molecule Commands ● converge test ● ● side-effects digitalocean.com

  29. Role Development with Molecule digitalocean.com

  30. Testing ProxySQL Example digitalocean.com

  31. Molecule Configuration dependency: name: galaxy driver: name: docker lint: name: yamllint platforms: - name: host1 image: "geerlingguy/docker-${MOLECULE_DISTRO:-ubuntu1804}-ansible:latest" command: ${MOLECULE_DOCKER_COMMAND:-""} volumes: - /sys/fs/cgroup:/sys/fs/cgroup:ro privileged: true pre_build_image: true provisioner: name: ansible lint: name: ansible-lint digitalocean.com

  32. Molecule Configuration scenario: name: default converge_sequence: # - dependency - create # - prepare - converge test_sequence: - lint - destroy # - dependency - syntax - create # - prepare - converge - idempotence # - side_effect - verify - destroy digitalocean.com

  33. Molecule Configuration verifier: name: testinfra env: PYTHONWARNINGS: "ignore:.*U.*mode is deprecated:DeprecationWarning" options: v: 1 lint: name: flake8 digitalocean.com

  34. Functional Testing with TestInfra proxysql_file_attributes = ("proxysql_file," "proxysql_file_user," "proxysql_file_group," "proxysql_file_mode") @pytest.mark.parametrize(proxysql_file_attributes, [ ("/root/.my.cnf", None, None, 0o600), ("/etc/proxysql.cnf", "proxysql", "proxysql", 0o644), ]) def test_proxysql_files(host, proxysql_file, proxysql_file_user, proxysql_file_group, proxysql_file_mode): f = host.file(proxysql_file) assert f.exists assert f.is_file if proxysql_file_user: assert f.user == proxysql_file_user if proxysql_file_group: assert f.group == proxysql_file_group if proxysql_file_mode: assert f.mode == proxysql_file_mode digitalocean.com

  35. Functional Testing with TestInfra ● Host fixture host.file ○ ○ host.package ○ host.service ○ host.run digitalocean.com

  36. Continuous Integration Pipeline digitalocean.com

  37. User Management digitalocean.com

  38. User Management Story ● Deployment and maintenance of individual and Service users ● Maintain user (dynamic) privileges ● Manage secrets (securely) ● Manage across both MySQL and ProxySQL digitalocean.com

  39. Manual Worst Case Scenario sammy@10.21.% sammy@10.22.% sammy@10.23.% sammy sammy@10.24.% sammy@10.25.% digitalocean.com

  40. User Management Requirements ● Deploy user control manifest to Ansible Project Role ● Generate & Encrypt secrets in Ansible Vault ● Consistent Delivery across technologies / tenancies / environments ● Scalable solution digitalocean.com

  41. New User Deploy Chain Request > New UMC > Gen Secret > commit/PR > Peer Review > Dry Run > Deploy >> >> >> + digitalocean.com

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend