Ua kom Ansible nrog Mitogen

Ua tau zoo tau los ua ib qho nrov tshaj plaws System Configuration Management. Tom qab tau yuav los ntawm Red Hat hauv 2015 tus lej cov neeg koom nrog qhov project Tshaj ntau txhiab thiab Ansible tau dhau los ua qhov feem ntau siv kev xa tawm thiab kev ua haujlwm. Nws ntau yam ntawm daim ntawv thov yog impressive heev.

Ansible ua haujlwm dhau SSH kev sib txuas rau cov chaw taws teeb tswj. Nws qhib qhov kev sib tham SSH, nkag rau hauv, theej Python code hla lub network thiab sau nws mus rau ib ntus cais. Tom qab ntawd, nws khiav cov ntaub ntawv no ntawm lub tshuab tej thaj chaw deb. Qhov kev ua haujlwm tag nrho no yog qhov ntev thiab tedious, yog li muaj ntau txoj hauv kev los txhim kho nws.

Ib txoj hauv kev no yog SSH cov kav dej uas tso cai rau koj siv ib qho kev sib tham SSH los ua cov lus qhia, tsis yog qhib kev sib tham tshiab txhua lub sijhawm, uas tuaj yeem txuag peb lub sijhawm ntau. (Nco ntsoov tig tawm requiretty teeb tsa sudo hauv koj /etc/sudoers cov ntaub ntawv ntawm lub tshuab tej thaj chaw deb)

Ib txoj hauv kev tshiab rau overclock Ansible yog lub tsev qiv ntawv python hu ua Mitogen. Yog tias leej twg tsis tau hnov ​​​​txog nws, Kuv yuav piav qhia luv luv txog nws txoj haujlwm. Nws tso cai rau kev ua tiav nrawm ntawm python code ntawm lub tshuab tej thaj chaw deb, thiab Ansible tsuas yog ib qho piv txwv ntawm kev siv. Mitogen siv UNIX yeeb nkab rau ntawm lub tshuab tej thaj chaw deb thiab hloov cov python code compressed nrog zlib thiab serialized nrog pickle. Qhov no pab ua kom tiav nws sai dua thiab txuag tsheb khiav. Yog tias koj txaus siab rau cov lus piav qhia ntxaws ntxiv, nws yog qhov zoo tshaj los nyeem txog nws ntawm nplooj ntawv "Nws ua haujlwm li cas". Tab sis hnub no peb yuav tsom mus rau qhov yuav ua li cas lub tsev qiv ntawv ua haujlwm nrog Ansible.

Mitogen nyob rau qee qhov xwm txheej tuaj yeem ua kom koj qhov Ansible code ntau zaus thiab txo qis kev siv tsheb. Cia peb tshawb xyuas cov neeg siv nrov tshaj plaws thiab saib seb nws pab peb li cas.

Kuv siv Ansible feem ntau rau: tsim cov ntaub ntawv teeb tsa ntawm lub tshuab chaw taws teeb, txhim kho pob khoom, luam cov ntaub ntawv mus rau thiab los ntawm lub tshuab chaw taws teeb. Tej zaum koj muaj lwm yam piv txwv - sau rau hauv cov lus.

Cia peb mus!

Mitogen configuration rau Ansible yog yooj yim heev:
Nruab lub tsev qiv ntawv Mitogen:

pip install mitogen

Tam sim no muaj ob txoj hauv kev sib npaug - ob qho tib si teeb tsa cov kev xaiv hauv ansible.cfg cov ntaub ntawv teeb tsa, lossis teeb tsa qhov tsim nyog ib puag ncig hloov pauv.

Cia peb xav tias txoj hauv kev mus rau nruab Mitogen yuav yog /usr/lib/python2.7/site-packages/ansible_mitogen/plugins/strategy. Tom qab ntawd:

export ANSIBLE_STRATEGY_PLUGINS=/usr/lib/python2.7/site-packages/ansible_mitogen/plugins/strategy
export ANSIBLE_STRATEGY=mitogen_linear

los yog

[defaults]
strategy = mitogen_linear
strategy_plugins = /usr/lib/python2.7/site-packages/ansible_mitogen/plugins/strategy

Cia peb nruab Ansible hauv virtualenv, nrog thiab tsis muaj Mitogen:

virtualenv mitogen_ansible
./mitogen_ansible/bin/pip install ansible==2.7.10 mitogen
virtualenv pure_ansible
./pure_ansible/bin/pip install ansible==2.7.10

Thov nco ntsoov tias Mitogen 0.2.7 tsis ua haujlwm nrog Ansible 2.8 (raws li lub Tsib Hlis 2019)

Ua aliases:

alias pure-ansible-playbook='$(pwd)/pure_ansible/bin/ansible-playbook'
alias mitogen-ansible-playbook='ANSIBLE_STRATEGY_PLUGINS=$(pwd)/mitogen_ansible/lib/python3.7/site-packages/ansible_mitogen/plugins/strategy ANSIBLE_STRATEGY=mitogen_linear $(pwd)/mitogen_ansible/bin/ansible-playbook'

Tam sim no cia peb sim khiav ib phau ntawv ua si uas tsim cov ntaub ntawv ntawm lub tshuab tej thaj chaw deb:

---
- hosts: all
  gather_facts: false
  tasks:
    - name: Create files with copy content module
      copy:
        content: |
          test file {{ item }}
        dest: ~/file_{{ item }}
      with_sequence: start=1 end={{ n }}

Thiab cia peb khiav nws nrog thiab tsis muaj Mitogen los tsim 10 cov ntaub ntawv:

time mitogen-ansible-playbook file_creation.yml -i hosts -e n=10 &>/dev/null

real    0m2.603s
user    0m1.152s
sys     0m0.096s

time pure-ansible-playbook file_creation.yml -i hosts -e n=10 &>/dev/null

real    0m5.908s
user    0m1.745s
sys     0m0.643s

Peb pom kev txhim kho 2 npaug. Cia peb kuaj rau 20, 30, ..., 100 cov ntaub ntawv:

time pure-ansible-playbook file_creation.yml -i hosts -e n=100 &>/dev/null

real    0m51.775s
user    0m8.039s
sys     0m6.305s

time mitogen-ansible-playbook file_creation.yml -i hosts -e n=100 &>/dev/null

real    0m4.331s
user    0m1.903s
sys     0m0.197s

Raws li qhov tshwm sim, peb nrawm ua tiav ntau dua 10 zaug!
Tam sim no cia peb sim cov xwm txheej sib txawv thiab saib seb txhua yam ua haujlwm sai npaum li cas rau peb:

  • Tsab ntawv rau luam cov ntaub ntawv mus rau ib lub chaw nyob deb ntawm ib lub zos (nrog rau lub module copy):
    Ua kom Ansible nrog Mitogen

  • Script tsim cov ntaub ntawv ntawm lub chaw taws teeb tswj nrog copy module:
    Ua kom Ansible nrog Mitogen

  • Scenario nrog rub tawm cov ntaub ntawv los ntawm cov chaw taws teeb tswj mus rau ib lub zos:
    Ua kom Ansible nrog Mitogen

Wb sim ib tug scenario nrog ob peb (3) tej thaj chaw deb tshuab, piv txwv li ib scenario nrog luam cov ntaub ntawv mus rau ib tug tej thaj chaw deb host:
Ua kom Ansible nrog Mitogen

Raws li koj tuaj yeem pom, Mitogen txuag peb lub sijhawm thiab kev tsheb khiav hauv cov xwm txheej no. Tab sis yog hais tias lub bottleneck tsis nyob rau hauv Ansible, tab sis piv txwv li nyob rau hauv lub I / O ntawm ib tug disk los yog network, los yog lwm qhov chaw, nws yog ib qhov nyuaj rau xav tias Mitogen yuav pab tau peb.

Wb sim ib tsab ntawv nrog kev txhim kho pob khoom nrog yum / dnf thiab python modules siv pip. Cov pob khoom raug kaw kom tsis txhob nyob ntawm lub network glitches:

---
- hosts: all
  gather_facts: false
  tasks:
    - name: Install packages
      become: true
      package:
        name:
          - samba
          - httpd
          - nano
          - ruby
        state: present

    - name: Install pip modules
      become: true
      pip:
        name:
          - pytest-split-tests
          - bottle
          - pep8
          - flask
        state: present

Nrog Mitogen nws siv 12 vib nas this, tib yam li tsis muaj nws.
Ntawm nplooj ntawv Mitogen rau Ansible nplooj koj tuaj yeem saib lwm cov qauv ntsuas thiab ntsuas. Raws li nplooj ntawv hais tias:

Mitogen tsis tuaj yeem ceev lub module thaum nws khiav. Nws tsuas tuaj yeem ua kom tiav ntawm qhov module no sai li sai tau.

Yog li ntawd, nws yog ib qho tseem ceeb kom nrhiav tau koj cov fwj hauv koj qhov kev xa tawm thiab yog tias lawv yog vim Ansible, ces Mitogen yuav pab koj daws lawv thiab ua kom nrawm rau kev ua tiav ntawm koj phau ntawv ua si.

Tau qhov twg los: www.hab.com

Ntxiv ib saib