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

Development Environments with Vagrant and Ansible

Development Environments with Vagrant and Ansible

Talk from PHP Brighton

Adam Strawson

February 13, 2016
Tweet

More Decks by Adam Strawson

Other Decks in Programming

Transcript

  1. Vagrant.configure("2") do |config| config.vm.provider :virtualbox do |v| v.name = "phpbrighton"

    end config.vm.box = "ubuntu/trusty64" config.vm.network :private_network, ip: "192.168.20.101" config.ssh.forward_agent = true config.vm.provision "ansible" do |ansible| ansible.playbook = "ansible/playbook.yml" ansible.inventory_path = "ansible/inventories/dev" ansible.limit = 'all' end config.vm.synced_folder "./data", "/vagrant", type: "nfs" end Vagrantfile
  2. config.vm.network "forwarded_port", guest: 80, host: 8080 Networking Port Forwarding Public

    Networks (Bridging) Static IP config.vm.network "public_network", ip: “10.2.6.45” config.vm.network “public_network"
  3. config.vm.define "web" do |web| web.vm.box = "apache" end config.vm.define "db"

    do |db| db.vm.box = "mysql" end Multi-machine $ vagrant ssh web vagrant@web:~$
  4. Provisioning File Shell Ansible Ansible Local Chef Solo CFEngine Chef

    Zero Chef Client Chef Apply Docker Puppet Apply Puppet Agent Salt
  5. $ vagrant ? Usage: vagrant [options] <command> [<args>] Common commands:

    box manages boxes: installation, removal, etc. destroy stops and deletes all traces of the vagrant machine halt stops the vagrant machine init initializes a new Vagrant environment by creating a Vagrantfileas package packages a running vagrant environment into a box provision provisions the vagrant machine reload restarts vagrant machine, loads new Vagrantfile configuration resume resume a suspended vagrant machine ssh connects to machine via SSH status outputs status of the vagrant machine suspend suspends the machine up starts and provisions the vagrant environment ...
  6. Simple Uses YAML Human Readable No specific language Tasks executed

    in order Wide OS Support Colo and Cloud Small Footprint Uses OpenSSH No extra code More Secure More Scalable Agentless Support
  7. a10_server (E) - Manage A10 Networks AX/SoftAX/Thunder/vThunder devices a10_service_group (E)

    - Manage A10 Networks devices’ service groups a10_virtual_server (E) - Manage A10 Networks devices’ virtual servers accelerate - Enable accelerated mode on remote node acl - Sets and retrieves file ACL information. add_host - add a host (and alternatively a group) to the ansible-playbook in- memory inventory airbrake_deployment (E) - Notify airbrake about app deployments alternatives (E) - Manages alternative programs for common commands apache2_module - enables/disables a module of the Apache2 webserver apk (E) - Manages apk packages apt - Manages apt-packages apt_key - Add or remove an apt key apt_repository - Add and remove APT repositories apt_rpm - apt_rpm package manager assemble - Assembles a configuration file from fragments assert - Fail with custom message async_status - Obtain status of asynchronous task at (E) - Schedule the execution of a command or script file via the at command. authorized_key - Adds or removes an SSH authorized key azure - create or terminate a virtual machine in azure bigip_facts (E) - Collect facts from F5 BIG-IP devices bigip_gtm_wide_ip (E) - Manages F5 BIG-IP GTM wide ip bigip_monitor_http (E) - Manages F5 BIG-IP LTM http monitors bigip_monitor_tcp (E) - Manages F5 BIG-IP LTM tcp monitors bigip_node (E) - Manages F5 BIG-IP LTM nodes bigip_pool (E) - Manages F5 BIG-IP LTM pools bigip_pool_member (E) - Manages F5 BIG-IP LTM pool members bigip_virtual_server (E) - Manages F5 BIG-IP LTM virtual servers bigpanda (E) - Notify BigPanda about deployments blockinfile (E) - Insert/update/remove a text block surrounded by marker lines. boundary_meter (E) - Manage boundary meters bower (E) - Manage bower packages with bower bundler (E) - Manage Ruby Gem dependencies with Bundler bzr (E) - Deploy software (or files) from bzr branches campfire (E) - Send a message to Campfire capabilities (E) - Manage Linux capabilities circonus_annotation (E) - create an annotation in circonus clc_aa_policy (E) - Create or Delete Anti Affinity Policies at CenturyLink Cloud. debug - Print statements during execution deploy_helper (E) - Manages some of the steps common in deploying projects. digital_ocean - Create/delete a droplet/SSH_key in DigitalOcean digital_ocean_domain - Create/delete a DNS record in DigitalOcean digital_ocean_sshkey - Create/delete an SSH key in DigitalOcean django_manage - Manages a Django application. dnf (E) - Manages packages with the *dnf* package manager dnsimple (E) - Interface with dnsimple.com (a DNS hosting service). dnsmadeeasy (E) - Interface with dnsmadeeasy.com (a DNS hosting service). docker - manage docker containers docker_image - manage docker images docker_login (E) - Manage Docker registry logins dpkg_selections (E) - Dpkg package selection selections dynamodb_table (E) - Create, update or delete AWS Dynamo DB tables. easy_install - Installs Python libraries ec2 - create, terminate, start or stop an instance in ec2 ec2_ami - create or destroy an image in ec2 ec2_ami_copy (E) - copies AMI between AWS regions, return new image id ec2_ami_find - Searches for AMIs to obtain the AMI ID and other information ec2_ami_search (D) - Retrieve AWS AMI information for a given operating system. ec2_asg - Create or delete AWS Autoscaling Groups ec2_eip - associate an EC2 elastic IP with an instance. ec2_elb - De-registers or registers instances from EC2 ELBs ec2_elb_facts (E) - Gather facts about EC2 Elastic Load Balancers in AWS ec2_elb_lb - Creates or destroys Amazon ELB. ec2_eni (E) - Create and optionally attach an Elastic Network Interface (ENI) to an instance ec2_eni_facts (E) - Gather facts about ec2 ENI interfaces in AWS ec2_facts - Gathers facts about remote hosts within ec2 (aws) ec2_group - maintain an ec2 VPC security group. ec2_key - maintain an ec2 key pair. ec2_lc - Create or delete AWS Autoscaling Launch Configurations ec2_metric_alarm - Create/update or delete AWS Cloudwatch ‘metric alarms’ ec2_remote_facts (E) - Gather facts about ec2 instances in AWS ec2_scaling_policy - Create or delete AWS scaling policies for Autoscaling groups ec2_snapshot - creates a snapshot from an existing volume ec2_tag - create and remove tag(s) to ec2 resources. ec2_vol - create and attach a volume, return volume id and device map vmware_target_canonical_facts (E) - Return canonical (NAA) from an ESXi host vmware_vm_facts (E) - Return basic facts pertaining to a vSphere virtual machine guest vmware_vm_shell (E) - Execute a process in VM vmware_vm_vss_dvs_migrate (E) - Migrates a virtual machine from a standard vswitch to distributed vmware_vmkernel (E) - Create a VMware VMkernel Interface vmware_vmkernel_ip_config (E) - Configure the VMkernel IP Address vmware_vsan_cluster (E) - Configure VSAN clustering on an ESXi host vmware_vswitch (E) - Add a VMware Standard Switch to an ESXi host vsphere_copy (E) - Copy a file to a vCenter datastore vsphere_guest - Create/delete/manage a guest VM through VMware vSphere. wait_for - Waits for a condition before continuing. webfaction_app (E) - Add or remove applications on a Webfaction host webfaction_db (E) - Add or remove a database on Webfaction webfaction_domain (E) - Add or remove domains and subdomains on Webfaction webfaction_mailbox (E) - Add or remove mailboxes on Webfaction webfaction_site (E) - Add or remove a website on a Webfaction host win_acl (E) - Set file/directory permissions for a system user or group. win_chocolatey (E) - Installs packages using chocolatey win_copy - Copies files to remote locations on windows hosts. win_dotnet_ngen (E) - Runs ngen to recompile DLLs after .NET updates win_environment (E) - Modifies environment variables on windows hosts. win_feature - Installs and uninstalls Windows Features win_file - Creates, touches or removes files or directories. win_firewall_rule (E) - Windows firewall automation win_get_url - Fetches a file from a given URL win_group - Add and remove local groups win_iis_virtualdirectory (E) - Configures a virtual directory in IIS. win_iis_webapplication (E) - Configures a IIS Web application. win_iis_webapppool (E) - Configures a IIS Web Application Pool. win_iis_webbinding (E) - Configures a IIS Web site. win_iis_website (E) - Configures a IIS Web site. win_lineinfile - Ensure a particular line is in a file, or replace an existing line using a back-referenced regular expression. win_msi - Installs and uninstalls Windows MSI files win_nssm (E) - NSSM - the Non-Sucking Service Manager win_package (E) - Installs/Uninstalls a installable package, either from local file system or url win_ping - A windows version of the classic ping module. Modules 468
  8. hosts vars/ vars1 vars2 site.yml webservers.yml dbservers.yml roles/ common/ tasks/

    main.yml handlers/ main.yml templates/ ntp.conf.j2 files/ bar.txt foo.sh vars/ main.yml meta/ main.yml Structure
  9. --- - hosts: all sudo: true vars_files: - vars/all.yml roles:

    - common - apache - mysql - php - composer - app Playbook site.yml
  10. --- - name: Install Apache sudo: yes apt: pkg=apache2 state=latest

    - name: Install Apache Modules apache2_module: state=present name={{ item }} notify: restart apache with_items: - rewrite - vhost_alias - headers - expires - filter - shell: apache2 -v register: apache_version - name: Change default apache2.4 site sudo: yes template: src=vhost24.conf.tpl dest=/etc/apache2/sites-available/000-default.conf notify: restart apache when: apache_version.stdout.find('Apache/2.4.') != -1 - name: Change default apache2.2 site sudo: yes template: src=vhost22.conf.tpl dest=/etc/apache2/sites-available/default notify: restart apache when: apache_version.stdout.find('Apache/2.2.') != -1 Apache Role tasks/main.yml
  11. --- - name: restart apache service: name=apache2 enabled=yes state=restarted Apache

    Role handler/main.yml notify: restart apache In the task..
  12. # Default Apache virtualhost template <VirtualHost *:80> ServerAdmin webmaster@localhost DocumentRoot

    {{ apache.docroot }} ServerName {{ apache.servername }} <Directory {{ apache.docroot }}> AllowOverride All Options -Indexes +FollowSymLinks Require all granted </Directory> </VirtualHost> Apache Role template/vhost24.conf.tpl
  13. --- server: install: '1' timezone: Europe/London locale: en_US.UTF-8 apache: install:

    '1' docroot: /vagrant servername: phpbrighton.dev mysql: install: '1' root_password: password123 database: phpbrighton_db user: phpbrighton_user password: secretpassword dump: '' php: install: '1' ppa: php5-5.6 packages: [php5-cli, php5-intl, php5-mcrypt, php5-mysql] composer: install: '1' Variables vars/all.yml
  14. [phpbrighton-app] 192.168.20.101 Hosts --- - hosts: all sudo: true vars_files:

    --- - hosts: phpbrighton-npp sudo: true vars_files: