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

Automatisieren mit Ansible

Automatisieren mit Ansible

Simon Olofsson

November 11, 2014
Tweet

More Decks by Simon Olofsson

Other Decks in Technology

Transcript

  1. Inventory Control Machine Ad-Hoc Commands A SSH B C D

    A B C D Webserver Datenbankserver
  2. apt - Manages apt-packages assemble - Assembles a configuration file

    from fragments azure - create or terminate a virtual machine in azure bigip_pool_member (E) - Manages F5 BIG-IP LTM pool members command - Executes a command on a remote node copy - Copies files to remote locations. docker - manage docker containers ec2 - create, terminate, start or stop an instance in ec2, return instanceid fetch - Fetches a file from remote nodes gce - create or terminate GCE instances git - Deploy software (or files) from git checkouts github_hooks (E) - Manages github service hooks. irc (E) - Send a message to an IRC channel jira (E) - create and modify issues in a JIRA instance mysql_db - Add or remove MySQL databases from a remote host. nagios (E) - Perform common tasks in Nagios related to downtime and notifications. postgresql_db - Add or remove PostgreSQL databases from a remote host. win_msi - Installs and uninstalls Windows MSI files
  3. Inventory Control Machine A SSH B C D Webserver A

    B C D Datenbankserver Webserver Playbook Datenbankserver Playbook
  4. # web.yml --- - hosts: web tasks: - name: Install

    nginx apt: name=nginx state=latest - name: Ensure nginx is started service: name=nginx state=started
  5. # db.yml --- - hosts: db tasks: - name: Install

    PostgreSQL apt: name=postgresql state=latest - name: Ensure PostgreSQL is started service: name=postgresql state=started
  6. # web.yml --- - hosts: web roles: - { role:

    service_provider, service: 'nginx' }
  7. # db.yml --- - hosts: db roles: - { role:

    service_provider, service: 'postgresql' }
  8. # roles/service_provider/tasks/main.yml - name: Install {{ service }} apt: name={{

    service }} state=latest - name: Ensure {{ service }} is started service: name={{ service }} state=started
  9. Vagrant.configure("2") do |config| config.vm.box = "larryli/utopic64" config.vm.define "web" do |web|

    web.vm.network "forwarded_port", guest: 80, host: 8080 web.vm.provision "ansible" do |ansible| ansible.playbook = "../roles/web.yml" ansible.sudo = true end end
  10. config.vm.define "db" do |db| db.vm.network "forwarded_port", guest: 5432, host: 5432

    db.vm.provision "ansible" do |ansible| ansible.playbook = "../roles/db.yml" ansible.sudo = true end end end
  11. % vagrant up Bringing machine 'web' up with ‘virtualbox' provider...

    Bringing machine 'db' up with ‘virtualbox' provider… ==> web: Running provisioner: ansible… web: ok=3 changed=1 ==> db: Running provisioner: ansible… db: ok=3 changed=1
  12. % vagrant provision ==> web: Running provisioner: ansible… web: ok=3

    changed=0 ==> db: Running provisioner: ansible… db: ok=3 changed=0
  13. https://github.com/ansible/ansible-examples pre_tasks: - name: disable nagios alerts for this host

    nagios: action=disable_alerts host={{ inventory_hostname }} services=webserver delegate_to: "{{ item }}" with_items: groups.monitoring - name: disable the server in haproxy shell: echo "disable server myapplb/ {{ inventory_hostname }}" | socat stdio /var/lib/haproxy/stats delegate_to: "{{ item }}" with_items: groups.lbservers
  14. https://github.com/ansible/ansible-examples post_tasks: - name: Wait for webserver to come up

    wait_for: host={{ inventory_hostname }} port=80 state=started timeout=80
  15. https://github.com/ansible/ansible-examples - name: Enable the server in haproxy shell: echo

    "enable server myapplb/ {{ inventory_hostname }}" | socat stdio /var/lib/haproxy/stats delegate_to: "{{ item }}" with_items: groups.lbservers - name: re-enable nagios alerts nagios: action=enable_alerts host={{ inventory_hostname }} services=webserver delegate_to: "{{ item }}" with_items: groups.monitoring
  16. Vielen Dank! Simon Olofsson • Content Management AG @solofs •

    [email protected] Die Logos wurden den Webseiten der jeweiligen Projekte entnommen.