Advertisement
freephile

Deploy a Quality Box to Digital Ocean

Aug 22nd, 2016
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 2.22 KB | None | 0 0
  1. - hosts: localhost
  2.   connection: local
  3.   vars_files:
  4.    - vars.yml
  5.   vars_prompt:
  6.     - name: do_name
  7.       prompt: "Name of server"
  8.       private: no
  9.     - name: do_dns
  10.       prompt: "DNS name to bind (press return for none)"
  11.       private: no
  12.   tasks:
  13.     - name: Register SSH key
  14.       digital_ocean: >
  15.        state=present
  16.         command=ssh
  17.         name="{{ do_ssh_name }}"
  18.         ssh_pub_key="{{ do_ssh_pub_key }}"
  19.         api_token={{ do_api_token }}
  20.       register: do_droplet
  21.  
  22.     - name: Register Droplet
  23.       digital_ocean: >
  24.        state=active
  25.         command=droplet
  26.         name={{ do_name }}
  27.         region_id={{ do_region }}
  28.         size_id={{ do_size }}
  29.         image_id={{ do_image }}
  30.         ssh_key_ids={{ do_droplet.ssh_key.id }}
  31.         unique_name=yes
  32.         api_token={{ do_api_token }}
  33.         wait_timeout=600
  34.       register: do_droplet
  35.  
  36.     - name: Register DNS
  37.       digital_ocean_domain: >
  38.        state=present
  39.         name="{{ do_dns }}"
  40.         id="{{ do_droplet.droplet.id }}"
  41.         api_token={{ do_api_token }}
  42.       when: do_dns|length > 0
  43.  
  44.     - debug: msg="IP is {{ do_droplet.droplet.ip_address }}"
  45.  
  46.     - name: Add new droplet to inventory
  47.       add_host: >
  48.        name="{{ do_name }}"
  49.         groups=dohosts
  50.         ansible_ssh_host="{{ do_droplet.droplet.ip_address }}"
  51.         ansible_ssh_user=root
  52.         ssh_private_key_file="{{ do_ssh_private_key }}"
  53. ### need these for xenial  
  54. #    - name: apt-get update
  55. #      raw: apt-get update -qq
  56. #    - name: Install python 2.7
  57. #      raw: apt-get install -qq python2.7
  58.  
  59. - hosts: dohosts
  60.  
  61.   gather_facts: no
  62.  
  63.   vars_files:
  64.    - defaults/main.yml
  65.     - vars.yml
  66.  
  67.   # by using pre_tasks, we can get all this preliminary stuff (especially the 'wait') scheduled before
  68.   # the actual role executes
  69.   pre_tasks:
  70.     - name: Wait for new host to come up
  71.       local_action: wait_for host={{ ansible_ssh_host }} port=22 state=started delay=10
  72.     - setup:
  73.     - include: tasks/swap.yml
  74.     - include: tasks/software.yml
  75.     - include: tasks/security.yml
  76.     - include: tasks/users.yml
  77.  
  78.   handlers:
  79.     - include: handlers/site.yml  
  80.  
  81.   # install all the goodness
  82.   roles:
  83.    - qualitybox
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement