---

- name: Install openvpn
  yum: name=openvpn state=present
  when: ansible_os_family == "RedHat"
  tags:
    - openvpn
    - packages

- stat: path=/etc/openvpn/ta.key get_md5=no
  register: ta_key

- name: Generate HMAC handshake protection key
  command: openvpn --genkey --secret /etc/openvpn/ta.key
  when: ta_key.stat.exists == False
  tags:
    - openvpn

- stat: path=ca /etc/openvpn/ca.crt get_md5=no
  register: ca_crt

- name: Create ca and server keys
  shell: "source /etc/easy-rsa/vars && /etc/easy-rsa/clean-all && /etc/easy-rsa/build-ca && /etc/easy-rsa/build-key-server {{ server }}"

- name: Move across openvpn server config
  template: src=server.conf.j2 dest=/etc/openvpn/server.conf
  tags:
    - openvpn
    - config_files

- name: Start our openvpn service
  service: name=openvpn@server.service state=started enabled=yes
  when: ansible_os_family == "RedHat"
  tags:
    - openvpn
    - services

---

- name: Install openvpn
  yum: name=openvpn state=present
  when: ansible_os_family == "RedHat"
  tags:
    - openvpn
    - packages

- stat: path=/etc/openvpn/ta.key get_md5=no
  register: ta_key

- name: Generate HMAC handshake protection key
  command: openvpn --genkey --secret /etc/openvpn/ta.key
  when: ta_key.stat.exists == False
  tags:
    - openvpn

- stat: path=ca /etc/openvpn/ca.crt get_md5=no
  register: ca_crt

- name: Create ca and server keys
  shell: "source /etc/easy-rsa/vars && /etc/easy-rsa/clean-all && /etc/easy-rsa/build-ca && /etc/easy-rsa/build-key-server {{ server }}"

- name: Copy across CA cert
  copy: src=../files/ca.crt dest=/etc/openvpn/ca.crt

- name: Copy across server cert
  copy: "src=../files/{{ server }}.crt dest=/etc/openvpn/{{ server }}.crt"

- name: Copy across server key
  copy: "src=../files/{{ server }}.key dest=/etc/openvpn/{{ server }}.key"

- name: Copy across our dh
  copy: src=../files/dh2048.pem dest=/etc/openvpn/dh2048.pem

- name: Move across openvpn server config
  template: src=server.conf.j2 dest=/etc/openvpn/server.conf
  tags:
    - openvpn
    - config_files

- name: Start our openvpn service
  service: name=openvpn@server.service state=started enabled=yes
  when: ansible_os_family == "RedHat"
  tags:
    - openvpn
    - services

Copy across the keys and what not instead of trying to generate them
Copy across the keys and what not instead of trying to generate them
