Commit 17d0469f by Arbab Nazar Committed by GitHub

Merge pull request #3222 from edx/arbab/certs-rewrite

proper YAML syntax for rewriting ansible tasks
parents 5e4d036d 55b5ee74
--- ---
- name: Create certificate application config and auth file
- name: create certificate application config template:
template: > src: "{{ item.src }}"
src=certs.env.json.j2 dest: "{{ certs_app_dir }}/{{ item.dest }}"
dest={{ certs_app_dir }}/env.json with_items:
become_user: "{{ certs_user }}" - { src: 'certs.env.json.j2', dest: 'env.json' }
- { src: 'certs.auth.json.j2', dest: 'auth.json' }
- name: create certificate auth file
template: >
src=certs.auth.json.j2
dest={{ certs_app_dir }}/auth.json
become_user: "{{ certs_user }}" become_user: "{{ certs_user }}"
- name: writing supervisor script for certificates - name: Writing supervisor script for certificates
template: > template:
src=certs.conf.j2 dest={{ supervisor_available_dir }}/certs.conf src: certs.conf.j2
owner={{ supervisor_user }} mode=0644 dest: "{{ supervisor_available_dir }}/certs.conf"
owner: "{{ supervisor_user }}"
mode: "0644"
- name: enable supervisor script for certificates - name: Enable supervisor script for certificates
file: > file:
src={{ supervisor_available_dir }}/certs.conf src: "{{ supervisor_available_dir }}/certs.conf"
dest={{ supervisor_cfg_dir }}/certs.conf dest: "{{ supervisor_cfg_dir }}/certs.conf"
owner={{ supervisor_user }} owner: "{{ supervisor_user }}"
state=link state: link
force=yes force: yes
mode=0644 mode: "0644"
when: not disable_edx_services when: not disable_edx_services
- name: create ssh script for git - name: Create ssh script for git
template: > template:
src={{ certs_git_ssh|basename }}.j2 dest={{ certs_git_ssh }} src: "{{ certs_git_ssh | basename }}.j2"
owner={{ certs_user }} mode=750 dest: "{{ certs_git_ssh }}"
owner: "{{ certs_user }}"
mode: "0750"
# This key is only needed if you are pulling down a private # This key is only needed if you are pulling down a private
# certificates repo # certificates repo
- name: install read-only ssh key for the certs repo - name: Install read-only ssh key for the certs repo
copy: > copy:
content="{{ CERTS_GIT_IDENTITY }}" dest={{ certs_git_identity }} content: "{{ CERTS_GIT_IDENTITY }}"
force=yes owner={{ certs_user }} mode=0600 dest: "{{ certs_git_identity }}"
force: yes
owner: "{{ certs_user }}"
mode: "0600"
when: CERTS_GIT_IDENTITY != "none" when: CERTS_GIT_IDENTITY != "none"
- name: checkout certificates repo into {{ certs_code_dir }} - name: "Checkout certificates repo into {{ certs_code_dir }}"
git_2_0_1: > git_2_0_1:
dest={{ certs_code_dir }} repo={{ CERTS_REPO }} version={{ certs_version }} dest: "{{ certs_code_dir }}"
accept_hostkey=yes repo: "{{ CERTS_REPO }}"
version: "{{ certs_version }}"
accept_hostkey: yes
become_user: "{{ certs_user }}" become_user: "{{ certs_user }}"
environment: environment:
GIT_SSH: "{{ certs_git_ssh }}" GIT_SSH: "{{ certs_git_ssh }}"
register: certs_checkout register: certs_checkout
when: CERTS_GIT_IDENTITY != "none" when: CERTS_GIT_IDENTITY != "none"
- name: checkout certificates repo into {{ certs_code_dir }} - name: Checkout certificates repo into {{ certs_code_dir }}
git_2_0_1: > git_2_0_1:
dest={{ certs_code_dir }} repo={{ CERTS_REPO }} version={{ certs_version }} dest: "{{ certs_code_dir }}"
accept_hostkey=yes repo: "{{ CERTS_REPO }}"
version: "{{ certs_version }}"
accept_hostkey: yes
become_user: "{{ certs_user }}" become_user: "{{ certs_user }}"
register: certs_checkout register: certs_checkout
when: CERTS_GIT_IDENTITY == "none" when: CERTS_GIT_IDENTITY == "none"
- name: remove read-only ssh key for the certs repo - name: Remove read-only ssh key for the certs repo
file: path={{ certs_git_identity }} state=absent file:
path: "{{ certs_git_identity }}"
state: absent
when: CERTS_GIT_IDENTITY != "none" when: CERTS_GIT_IDENTITY != "none"
- name : install python requirements - name: Install python requirements
pip: > pip:
requirements="{{ certs_requirements_file }}" virtualenv="{{ certs_venv_dir }}" state=present requirements: "{{ certs_requirements_file }}"
extra_args="-i {{ COMMON_PYPI_MIRROR_URL }}" virtualenv: "{{ certs_venv_dir }}"
state: present
extra_args: "-i {{ COMMON_PYPI_MIRROR_URL }}"
become_user: "{{ certs_user }}" become_user: "{{ certs_user }}"
# call supervisorctl update. this reloads # call supervisorctl update. this reloads
...@@ -73,38 +84,40 @@ ...@@ -73,38 +84,40 @@
# the services if any of the configurations # the services if any of the configurations
# have changed. # have changed.
# #
- name: update supervisor configuration - name: Update supervisor configuration
shell: "{{ supervisor_ctl }} -c {{ supervisor_cfg }} update" shell: "{{ supervisor_ctl }} -c {{ supervisor_cfg }} update"
register: supervisor_update register: supervisor_update
become_user: "{{ supervisor_service_user }}" become_user: "{{ supervisor_service_user }}"
changed_when: supervisor_update.stdout is defined and supervisor_update.stdout != "" changed_when: supervisor_update.stdout is defined and supervisor_update.stdout != ""
when: not disable_edx_services when: not disable_edx_services
- name: ensure certs has started - name: Ensure certs has started
supervisorctl: > supervisorctl:
name=certs name: certs
supervisorctl_path={{ supervisor_ctl }} supervisorctl_path: "{{ supervisor_ctl }}"
config={{ supervisor_cfg }} config: "{{ supervisor_cfg }}"
state=started state: started
become_user: "{{ supervisor_service_user }}" become_user: "{{ supervisor_service_user }}"
when: not disable_edx_services when: not disable_edx_services
- name: create a symlink for venv python - name: Create a symlink for venv python
file: > file:
src="{{ certs_venv_bin }}/{{ item }}" src: "{{ certs_venv_bin }}/{{ item }}"
dest={{ COMMON_BIN_DIR }}/{{ item }}.certs dest: "{{ COMMON_BIN_DIR }}/{{ item }}.certs"
state=link state: link
with_items: with_items:
- python - python
- pip - pip
- include: tag_ec2.yml tags=deploy - include: tag_ec2.yml
when: COMMON_TAG_EC2_INSTANCE when: COMMON_TAG_EC2_INSTANCE
tags:
- deploy
- name: restart certs - name: Restart certs
supervisorctl: > supervisorctl:
name=certs name: certs
supervisorctl_path={{ supervisor_ctl }} supervisorctl_path: "{{ supervisor_ctl }}"
config={{ supervisor_cfg }} config: "{{ supervisor_cfg }}"
state=restarted state: restarted
when: not disable_edx_services when: not disable_edx_services
...@@ -31,19 +31,19 @@ ...@@ -31,19 +31,19 @@
# - supervisor # - supervisor
# - certs # - certs
# #
- name: create application user - name: Create application user
user: > user:
name="{{ certs_user }}" name: "{{ certs_user }}"
home="{{ certs_app_dir }}" home: "{{ certs_app_dir }}"
createhome=no createhome: no
shell=/bin/false shell: /bin/false
- name: create certs app dirs - name: Create certs app dirs
file: > file:
path="{{ item }}" path: "{{ item }}"
state=directory state: directory
owner="{{ certs_user }}" owner: "{{ certs_user }}"
group="{{ common_web_group }}" group: "{{ common_web_group }}"
with_items: with_items:
- "{{ certs_app_dir }}" - "{{ certs_app_dir }}"
# needed for the ansible 1.5 git module # needed for the ansible 1.5 git module
...@@ -54,42 +54,46 @@ ...@@ -54,42 +54,46 @@
# The certs web root must be owned # The certs web root must be owned
# by the web user so the certs service # by the web user so the certs service
# can write files there. # can write files there.
- name: create certs web root - name: Create certs web root
file: > file:
path="{{ CERTS_WEB_ROOT }}" path: "{{ CERTS_WEB_ROOT }}"
state=directory state: directory
owner="{{ common_web_group }}" owner: "{{ common_web_group }}"
group="{{ certs_user }}" group: "{{ certs_user }}"
- name: create certs gpg dir - name: Create certs gpg dir
file: > file:
path="{{ certs_gpg_dir }}" state=directory path: "{{ certs_gpg_dir }}"
owner="{{ common_web_user }}" state: directory
mode=0700 owner: "{{ common_web_user }}"
mode: "0700"
- name: copy the private gpg signing key - name: Copy the private gpg signing key
copy: > copy:
src={{ CERTS_LOCAL_PRIVATE_KEY }} src: "{{ CERTS_LOCAL_PRIVATE_KEY }}"
dest={{ certs_app_dir }}/{{ CERTS_LOCAL_PRIVATE_KEY|basename }} dest: "{{ certs_app_dir }}/{{ CERTS_LOCAL_PRIVATE_KEY | basename }}"
owner={{ common_web_user }} mode=0600 owner: "{{ common_web_user }}"
mode: "0600"
register: certs_gpg_key register: certs_gpg_key
no_log: True
- name: copy the pgp trust export - name: Copy the pgp trust export
copy: > copy:
content="{{ CERTS_OWNER_TRUST }}" content: "{{ CERTS_OWNER_TRUST }}"
dest={{ certs_app_dir }}/trust.export dest: "{{ certs_app_dir }}/trust.export"
owner={{ common_web_user }} mode=0600 owner: "{{ common_web_user }}"
mode: "0600"
- name: load the gpg key - name: Load the gpg key
shell: > shell: "/usr/bin/gpg --homedir {{ certs_gpg_dir }} --import {{ certs_app_dir }}/{{ CERTS_LOCAL_PRIVATE_KEY | basename }}"
/usr/bin/gpg --homedir {{ certs_gpg_dir }} --import {{ certs_app_dir }}/{{ CERTS_LOCAL_PRIVATE_KEY|basename }} become_user: "{{ common_web_user }}"
sudo_user: "{{ common_web_user }}"
when: certs_gpg_key.changed when: certs_gpg_key.changed
- name: import the trust export - name: Import the trust export
shell: > shell: "/usr/bin/gpg --homedir {{ certs_gpg_dir }} --import-ownertrust {{ certs_app_dir }}/trust.export"
/usr/bin/gpg --homedir {{ certs_gpg_dir }} --import-ownertrust {{ certs_app_dir }}/trust.export become_user: "{{ common_web_user }}"
sudo_user: "{{ common_web_user }}"
when: certs_gpg_key.changed when: certs_gpg_key.changed
- include: deploy.yml tags=deploy - include: deploy.yml
tags:
- deploy
--- ---
- name: get instance information - name: Get instance information
action: ec2_facts action: ec2_facts
- name: tag instance - name: Tag instance
ec2_tag: resource={{ ansible_ec2_instance_id }} region={{ ansible_ec2_placement_region }} ec2_tag:
args: resource: "{{ ansible_ec2_instance_id }}"
region: "{{ ansible_ec2_placement_region }}"
tags: tags:
"version:certs" : "{{ CERT_REPO }} {{ certs_checkout.after|truncate(7,True,'') }}" "version:certs" : "{{ CERT_REPO }} {{ certs_checkout.after|truncate(7,True,'') }}"
when: certs_checkout.after is defined when: certs_checkout.after is defined
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment