إن كتب Ansible هي رمز: نحن نفحص ونختبر وندمج باستمرار. إيفان بونوماريف

أقترح أن تقرأ نص تقرير إيفان بونوماريف "كتابات Ansible هي رمز: نحن نتحقق ونختبر وندمج باستمرار."


يمكن أن تكون إعادة هيكلة الكود ممتعة ، خاصة إذا كانت كود البنية التحتية الخاصة بك. بالإضافة إلى ذلك ، تميل الأدوار Ansible لسبب ما إلى زيادة التعقيد بسرعة. وهذا يضيف لمسة إلى مهمتك. سيخبرك إيفان بكيفية التغلب على تعقيد كود Ansible من خلال الاختبار. في حاويات دوكر.
مع نمو قاعدة التعليمات البرمجية ، تأتي Ansible بمشاكل مألوفة: تعقيد الحفاظ على التعليمات البرمجية والأخطاء والخوف من التغيير. المشاكل المألوفة لها حل مألوف: الاختبار الآلي و CI. في التقرير ، سيوضح إيفان كيفية استخدام الأدوات لحل مشاكل "هشاشة" التعليمات البرمجية Ansible وإجراء تحليل ثابت واختبار البرامج النصية Ansible وتكوين أنظمة CI لنشر الأدوار في Ansible Galaxy.



. , . , , - .



. . . . — «», - , . , , — DigitalOcean. : Terraform + Ansible. Terraform, Ansible .



Ansible , best practices. - — , , , , . .



, . best practices, . , -, - .



, . :


  1. .
    • , .
    • . : , ? ?
  2. , , .
  3. . playbook, , .


CI. ? , unit-tests , Java Python. configuration is code. ?



, , , , .


— well-formedness: . , . YAMLLint, Ansible-lint Syntax check playbook. .



YAMLLint.


  • YAML. YAML , . , .
  • .
  • UNIX-style.
  • , YAML, , .

, Ansible, , . , Windows, Windows-style , . YAMLLint .



YAMLLint. : , - , -. YAMLLint YAML- , Ansible playbooks , - , .



Ansible-lint — , good practices.


:


  • command module, — shell module? . Ansible-lint .
  • command module, , Ansible. Ansible-lint , Ansible.
  • idempotence () command shell. idempotence - . , Ansible, best practices .
  • , , Python - , , .


. «». - , . , CI-. .



.



— Syntax check, Ansible. . «», , — CI, . Syntax check Syntax check, , . - , .



CI-. Jenkins, . pipeline. , . , Ansible-.



, , . -, , . ?



. Jeff Geerling — , Ansible-. , «Ansible for DevOps». , Travis , .



, docker-. .



Molecule. , - . . Ansible-.



OpenSource-, .



Python environment. ansible, molecule , Docker, — docker-py.



, . Ansible , . , . instances (, ), . , .


, playbook. Playbook — , , instances.


.



-, . molecule, . , readme-, , Ansible-. Molecule Default. , Default , .



molecule , . Default-. , . , Molecule, . .



, : molecule test. , Molecule . , . . , .



--debug, , docker-py. , docker-py . --debug : .



Test matrix. , Molecule . , . , syntax, converge, idempotence, instances, .



, , — , , Molecule , instances, ? — molecule.yml. Platforms instances, . , . Ansible converge , Ansible .


docker, image. , image . , systemd. - , systemd, , , docker , . , , systemd.



docker .


-, instances , , Ansible.


-, . .


Vagrant, .


Molecule, . docker — , .



: , . , .


requirements.yml, best practices Ansible. : . , dependency, .



, : YAMLLint, Ansible-lint, Syntax check.



converge instances playbook.yml. , . , - . converge playbook.yml. , - , .



- : converge , , , , — destroy=never ( « instances») docker, interactive- , .



converge. , , instances , . Molecule . , diff Ansible, Jeff Geerling : , . , , . , .



--diff. , , , , failed idempotence.



Molecule — . , , . , , . Molecule .


:


  • Testinfra (Python, default).
  • Serverspec (Ruby).
  • Goss (written in Go, tests in YAML).

, - , Serverspec, Molecule.


, Testinfra, Python, Molecule Ansible, .



Testinfra Molecule. .



, , ? , , - , ? shell, - , .


. , host, host «run» return code stdout stderr .



assert, , , rc=0. - , assert , : , .



molecule test, — Ansible- instances. instances, destroy=never molecule verify. instances.



, . 2000 JUnit, Unit-, : «keep the bar green to keep your code clean». everything is code, .



? , . curl — - , curl.



Testinfra . , . Host.process , host. - , - , , : , root , - .



. , .



. , - , , - , . -, exists , , contains , - , , OK.



- TDD, , , Ansible, Ansible.


Ansible- , Java Python, .


, , - — Testinfra, — Ansible assert. , — Ansible-. Jython — Python JVM. , jython version, , - .



. , , Molecule, Molecule , . ? Ansible-lint. Ansible-lint , Molecule .


assert Ansible.



, . , , , , , , .


. - production - , , Ansible playbooks .



, -. , , , Testinfra, . , Ansible- .



. . — Galaxy. GitHub, OpenSource, GitHub , , GitHub- CI . , Master, . - , - Master, .



? Molecule CI-. Jenkins, «». Jenkins Multibranch, checkout MyRole, , Ansible , : MyRole, . : symlink , .



Molecule .



, Jenkins. - - , , . , . , , , molecule test.



, , OpenSource, , — Travis. . services docker, , Ansible Molecule docker-py. , — , , , .


— molecule test, , , GitHub-.



, webhook, Ansible Galaxy , : build passing build failing.


Galaxy . , GitHub, Ansible Galaxy. , Travis webhook. CI , , , — . Travis.



, ? — - , - , copy-paste-modify .



. , , Galaxy, . , Molecule, , .


, , linting. — YAMLLint, Ansible-lint Syntax Check. , .



: - ? , Ansible Galaxy Molecule, , Molecule . , , , , . , , YAML well format, .



- ? ? , Molecule — . , , Molecule .


, , , , .



, , .


— Heisenbug. , .



- . , ?


  • . , , - , , , URL, URL.
  • , .
  • . , , , , Ansible .
  • . , , , instances - , , failsafe. , , instances?

: , framework, pytest. , , . , .



, ? , pytest, , — , , — . asserts : , . . : Python, values- , .



, , ? . , , , ‘port$’. «var_values», , -, Ansible playbooks, var_values , «port», , , , , .


var_values? Python . YAML-. , YAML Ansible, , .



, , , , , .


? . port_var_values, , , .



, : «keep the bar green to keep the configuration clean». , .


: , . , . , . , . , . , , .



— , «» . -, - , .


: «password», «pass», «pwd». -, , placeholder, -, - , Vault. , .



. pull request. . : k=’myskq_root_password’, v=’12345’. , password «12345», , GitHub . , pull request .


.



— Ansible.


  • -, : YAMLLint + Ansible-lint + Syntax check — . - Ansible-, - , , , , . , . Ansible-lint , , best practices .
  • Molecule.
  • . playbook failed fast. , , - , .
  • .


  • - — Molecule. : pip install molecule, molecule init, molecule test.
  • ? converge idempotence.
  • converge idempotence? .


, : , , . — ? , Git, , pipeline, quality gates, .



, , — GitHub + Travis + Galaxy. OpenSource. , OpenSource. Jenkins Multibranch .



, , , .




: ! . : , , , ? , Ansible? Ansible , Python, Testinfra, Molecule. , Python, , .


: ? , Java. pull request — : . , — - , . , - , , , . . playbooks . , . - , ? . , - , . - shell, shell - . , .


: Ansible Windows? Ansible playbook Windows. ? , ?


: , Ansible - Windows Testinfra. Windows, Ansible cygwin . Linux- , . , . .


: , . — . , ? . changed_when, ?


: , -, - , , ?


: , , , . , .


: , asserts, . . . command shell, , . , , . — , — , . , . Ansible . , , , . .


: . , Ansible gathering facts study, , …


: .


: , , JUnit , — , , gathering tasks, , , ?


: . , . -, -. -, ? , -. , , , , , - . - . , : , , ? .


: , , GitHub , . , version. , .


: . . Molecule , .


: . , ? , - , - , , , .


: . , service is running. , «»?


: , — , . , , …


: , , , -, - . , «200» , - . . selenium- . , Ansible : « ». , , «200» , , , pipeline.


: production Ansible Galaxy ? .


: , . , nginx, PostgreSQL. . Oracle Java Ansible Galaxy. . . , , . , Ansible build pipeline. Molecule, Travis . , , Jeff Geerling.


: playbook Ansible Galaxy?


: , , . . , , , . , 150000 , , 150 . 150000 , , , - production.


: Jinja. , Jinja , hosts. ?


: , Molecule , Molecule , . inventory. Molecule , , . - … Molecule? Molecule - , playbook.yml. playbook.yml, , , playbook. - Jinja, — . , . Molecule .


All Articles