Matt Makai | @mattmakai | makaimc on GitHub | Twilio Developer Evangelist
$ ansible webservers -m user -a \ "name=sanfran state=present \ uid=1040 group=meetup" -u deployer
- name: ensure user "sanfran" exists user: name=sanfran state=present uid=1040 group=meetup
deploy |---- deploy.yml |---- hosts |---- group_vars/ |---- all |---- dbservers |---- webservers |---- roles/ |---- all |---- db |---- handlers |---- tasks |---- templates |---- web
- name: install latest version of Apache yum: name=httpd state=latest - name: check if apache conf.d dir exists stat: path=/etc/httpd/conf.d/ register: apache_dir - debug: msg="conf.d exists and is dir" when: apache_dir.stat.isdir is defined and apache_dir.stat.isdir
- name: check if virtualenv already exists stat: path={{virtualenv_dir}} register: venv_dir - name: create virtualenv for Django web app shell: virtualenv {{virtualenv_dir}} when: venv_dir.stat.isdir is not defined - name: install web application dependencies pip: requirements={{app_dir}}/reqs.txt virtualenv={{virtualenv_dir}}
- name: install known_hosts file for GitHub copy: src={{ ssh_dir }}/known_hosts dest=/home/{{ deploy_user }}/.ssh - name: checkout latest web app code git: repo={{code_repo}} dest={{app_dir}}
- name: Django syncdb django_manage: command=syncdb app_path={{app_code_dir}} virtualenv={{venv_dir}} environment: django_env_vars - name: Django migrate django_manage: command=migrate app_path={{app_code_dir}} virtualenv={{venv_dir}} environment: django_env_vars when: django_use_south
# playbook - name: Django collectstatic django_manage: command=collectstatic app_path={{app_code_dir}} virtualenv={{venv_dir}} environment: django_env_vars # command line $ ansible-playbook django-stack.yml --step \ --start-at-task="Django collectstatic" \ -u deployer -K