Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Ansible 介紹

Ansible 介紹

如何使用 Ansible 管理大量機器

williamwu

April 18, 2014
Tweet

Other Decks in Technology

Transcript

  1. 半⾃自動安裝版 <安裝apache2> 1. <寫好script> 2. scp your_scripts.sh <your_name>@<remote_host> 3. ssh

    <your_name>@<remote_host> 4. sudo ./your_script.sh 5. <wait and see> 6. exit
  2. your_script.sh sudo aptitude update if [ ! $? -eq 0

    ]; then echo "Update error" exit 1 fi sudo aptitude install apache2 -y if [ ! $? -eq 0 ]; then echo "Install Apache2 error" exit 2 fi echo "Install completed."
  3. Ansible版<安裝apache2> install_apache2.yml --- - hosts: all sudo: yes tasks: -

    name: install apache2 apt: pkg=apache2 update_cache=yes
  4. 安裝Ansible The Hard Way • aptitude update • aptitude install

    python-dev python-virtualenv python-pip -y • virtualenv myvenv • source myvenv/bin/activate • pip install ansible
  5. 使⽤用 ansible執⾏行簡單指令 ansible all —ask-pass —sudo -m shell -a “aptitude

    update” ansible webservers —ask-pass —sudo -m shell -a “aptitude install apache2 -y” ansible dnsservers —sudo -m shell -a “reboot”
  6. playbook 範例 —- - hosts: all tasks: - name: run

    my own script script: runmyscript.sh - name: reboot the system shell: reboot