main.yml 2.31 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
---

- name: Install Pip
  tags: swagger
  yum: name=python-pip state=present

- name: Install PyYAML
  tags: swagger
  pip: name=pyYAML state=latest

- name: Install Apache
  tags: swagger
13 14 15 16
  yum: name={{ item }} state=present
  with_items:
    - httpd
    - mod_ssl
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31

- name: Config Apache Up and Running
  tags: swagger
  service: name=httpd enabled=yes state=started

- name: Create /tmp/swagger folder
  tags: swagger
  file: path=/tmp/swagger state=directory

- name: Get swagger-ui distro tar
  tags: swagger
  shell: >
    curl -L https://api.github.com/repos/swagger-api/swagger-ui/tarball
    | tar xz -C /tmp/swagger --strip-components 1

32
- name: Create swagger directories
33
  tags: swagger
34 35
  file: path=/var/www/html/{{ item.name }} state=directory owner=root group=root mode=0755
  with_items: swagger_docs
36 37 38

- name: Transfer dist files to each dedicated dir at /var/www/html/
  tags: swagger
39 40
  shell: cp -R /tmp/swagger/dist/* /var/www/html/{{ item.name }}
  with_items: swagger_docs
41

42
- name: Get latest swagger.yaml definition files
43
  tags: swagger
44 45 46 47 48
  get_url: url=https://raw.githubusercontent.com/{{ item.github_org }}/{{ item.name }}/{{ item.branch }}/{{ item.path_to_yaml }}
           dest=/tmp/swagger/{{ item.name }}_swagger.yaml force=yes
           owner=root group=root mode=0644
  with_items: swagger_docs
  notify: restart apache
49

50
- name: Convert swagger.yaml to swagger.json
51 52 53 54
  tags: swagger
  shell: >
    python -c 'import sys, yaml, json;
    json.dump(yaml.load(sys.stdin), sys.stdout, indent=4)'
55 56
    < /tmp/swagger/{{ item.name }}_swagger.yaml > /var/www/html/{{ item.name }}/swagger.json
  with_items: swagger_docs
57

58
- name: Make swagger.json point to corresponding api endpoint
59
  tags: swagger
60 61 62 63 64 65 66
  lineinfile: >
              dest=/var/www/html/{{ item.name }}/swagger.json
              regexp='( +)\"host\":\ \"(.+)\"\,'
              line='    \"host\": \"{{ item.api_host }}\",'
              state=present backup=yes
  with_items: swagger_docs
  notify: restart apache
67

68
- name: Point swagger-ui to corresponding swagger definitions on host
69
  tags: swagger
70 71 72 73 74
  replace: dest=/var/www/html/{{ item.name }}/index.html
           regexp='url = "http:\/\/petstore\.swagger\.io\/v2\/swagger\.json";'
           replace='url = "https://{{ inventory_hostname }}/{{ item.name }}/swagger.json";'
           backup=yes
  with_items: swagger_docs
75 76