title: Using Ansible to install Docker
body: <p>Some time ago I asked a question regarding Ansible and Docker and received <a href="https://stackoverflow.com/a/32105086/4009451">this excellent answer</a>. I am now trying to understand that answer a bit better. Essentially, I have a bunch of Ubuntu 14.04 VMs and I want Ansible to install/maintain Docker on all of them.</p>
  
  <p>My Ansible project:</p>
  
  <pre><code>myansible01.example.com:/opt/ansible/
      site.yml
      allservers.yml
      roles/
          common/
              tasks/
                  main.yml
  </code></pre>
  
  <p>Where <code>site.yml</code> is:</p>
  
  <pre><code>---
  # file: site.yml
  - include: allservers.yml
  </code></pre>
  
  <p>Where <code>allservers.yml</code> is:</p>
  
  <pre><code>---
  # file: allservers.yml
  - hosts: all
    user: {{ privileged_user }}
    gather_facts: false
    roles:
    - common
  </code></pre>
  
  <p>And where <code>roles/common/tasks/main.yml</code> is:</p>
  
  <pre><code>---
  # file: roles/common/tasks/main.yml
  - name: Add docker apt keys
    apt_key: keyserver=keyserver.ubuntu.com id=36A1D7869245C8950F966E92D8576A8BA88D21E9
  - name: Update apt
    apt_repository: repo='deb https://get.docker.com docker main' state=present
  - name: Install Docker
    apt: pkg=lxc-docker update_cache=yes
  </code></pre>
  
  <p>Finally, my <code>/etc/ansible/hosts</code>:</p>
  
  <pre><code>[allservers]
  server01.example.com
  server02.example.com
  server03.example.com
  ...etc.
  server49.example.com
  server50.example.com
  </code></pre>
  
  <p>Several concerns here:</p>
  
  <ul>
  <li>How do I actually run this so that Ansible installs Docker on all 50 servers? Something like (from the project root) <code>ansible-playbook site.yml -f 10</code>?</li>
  <li>How do I "inject" the <code>privileged_user</code> into the above command?</li>
  <li>Why is the first task "<em>Add docker apt keys</em>" necessary? According to the <a href="http://docs.ansible.com/ansible/apt_key_module.html" rel="nofollow noreferrer"><code>apt_key</code> docs</a>, we are fetching an <code>apt_key</code> from the Ubuntu repos, but where does that long key come from? What role does this play in installing Docker (I ask because if you go to the <a href="https://docs.docker.com/installation/ubuntulinux/#installation" rel="nofollow noreferrer">Docker Ubuntu installation page</a> it doesn't mention these <code>apt_keys</code> at all)?</li>
  <li>Anything else I need to do for a proper Docker install?</li>
  </ul>