main.yml 3.98 KB
Newer Older
1 2 3 4 5
---
#
# edX Configuration
#
# github:     https://github.com/edx/configuration
6 7
# wiki:       https://openedx.atlassian.net/wiki/display/OpenOPS
# code style: https://openedx.atlassian.net/wiki/display/OpenOPS/Ansible+Code+Conventions
8 9 10 11 12
# license:    https://github.com/edx/configuration/blob/master/LICENSE.TXT
#
#
#
# Tasks for role edx_service
John Jarvis committed
13
#
14 15
# Overview:
#
e0d committed
16 17
# This role performs the repetive tasks that most edX roles
# require in our default configuration.
18 19 20
#
# Example play:
#
e0d committed
21
# Rather than being included in the play, this role
Max Rothman committed
22
# is included as a dependency by other roles in the meta/main.yml
e0d committed
23 24 25 26
# file.  The including role should add the following
# depency definition.
#
# dependencies:
Max Rothman committed
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
#   - role: edx_service
#     edx_service_name: "hotg"
#     edx_service_config: "{{ structure_to_be_written_to_config_file_in_/edx/etc }}"
#     edx_service_repos:
#       - PROTOCOL: [https/ssh]
#         DOMAIN: github.com
#         PATH: edx
#         REPO: hotg
#         VERSION: master
#         DESTINATION: "/edx/app/hotg/hotg"
#         SSH_KEY: <required if PROTOCOL==ssh>
#       - PROTOCOL
#         ...
#     edx_service_user: hotg_system_user
#     edx_service_home: "/edx/app/hotg"
Max Rothman committed
42 43 44
#     edx_service_packages:
#       debian: [ pkg1, pkg2, pkg3 ]      
#       redhat: [ pkg4, pkg5 ]
45
#
Edward Zarecor committed
46
# Assumes that the home directory has been created above.
47 48
# In some cases(vagrant boxes) the home directory gets created
# but does not have the corrent owner and group. In vagrant for
49
# example we were seeing it defaulting to `root` for both.
50 51
# The item that is a blank string("") ensures the ownership
# of the home directory is always correct before proceeding.
52 53 54 55 56 57
- name: Create edx_service app, venv, data, and staticfiles dirs
  file:
    path: "{{ edx_service_home }}/{{ item }}"
    state: directory
    owner: "{{ edx_service_name }}"
    group: "{{ common_web_group }}"
58
  with_items:
59
    - ""
60 61 62
    - "venvs"
    - "data"
    - "staticfiles"
63 64 65
  tags:
    - install
    - install:base
John Jarvis committed
66

67 68 69 70 71 72 73
- name: Create /edx/var and /edx/etc dirs
  file:
    path: "{{ item }}/{{ edx_service_name }}"
    state: directory
    owner: "{{ edx_service_user }}"
    group: "{{ common_web_group }}"
    mode: "0755"
74
  with_items:
75 76
    - "/edx/var"
    - "/edx/etc"
77 78 79
  tags:
    - install
    - install:base
80

81 82 83 84 85 86
- name: Create edx_service log dir
  file:
    path: "{{ item }}"
    state: directory
    owner: "syslog"
    group: "syslog"
John Jarvis committed
87
  with_items:
e0d committed
88
    - "{{ COMMON_LOG_DIR }}/{{ edx_service_name }}"
89 90 91
  tags:
    - install
    - install:base
John Jarvis committed
92

93 94 95 96 97
- name: Write out app config file
  template:
    src: "config.yml.j2"
    dest: "{{ COMMON_CFG_DIR  }}/{{ edx_service_name }}.yml"
    mode: "0644"
Edward Zarecor committed
98
  when: edx_service_config is defined
99 100 101
  tags:
    - install
    - install:configuration
102
    - install:app-configuration
103
  
104
- name: Install a bunch of system packages on which edx_service relies
105
  apt:
106
    name: "{{ item }}"
107 108
    state: present
    update_cache: true
109
    cache_valid_time: 3600
110
  with_items: "{{ edx_service_packages.debian }}"
111
  when: ansible_distribution in common_debian_variants
112 113 114
  tags:
    - install
    - install:system-requirements
115

116 117 118 119 120
- name: Install a bunch of system packages on which edx_service relies
  yum:
    name: "{{ item }}"
    state: present
  with_items: "{{ edx_service_packages.redhat }}"
John Jarvis committed
121
  when: ansible_distribution in common_redhat_variants
122 123 124
  tags:
    - install
    - install:system-requirements
125

126
- name: Get instance information
127
  action: ec2_facts
Edward Zarecor committed
128 129
  tags:
    - to-remove
130

131
- name: Tag instance
Feanil Patel committed
132
  ec2_tag_local:
133
  args:
Feanil Patel committed
134 135
    resource: "{{ ansible_ec2_instance_id }}"
    region: "{{ ansible_ec2_placement_region }}"
136
    tags:
Feanil Patel committed
137
      - Name: "version:{{ edx_service_name }}"
138
        Value: "{{ item.0.DOMAIN }}/{{ item.0.PATH }}/{{ item.0.REPO }} {{ item.1.after |truncate(7,True,'') }}"
139
  when: item.1.after is defined and COMMON_TAG_EC2_INSTANCE and edx_service_repos is defined
140
  with_together: 
141 142
    - "{{ edx_service_repos }}"
    - "{{ code_checkout.results }}"
143 144
  tags:
    - to-remove
145

Max Rothman committed
146
#TODO: restart supervisor- depends on supervisor being refactored into this role