main.yml 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. - include_vars: passwords.yml
  2. ## MariaDB ##
  3. - name: Unattended package installation
  4. shell: export DEBIAN_FRONTEND=noninteractive
  5. changed_when: false
  6. - name: Install MariaDB
  7. apt:
  8. pkg: "{{ item }}"
  9. update_cache: no
  10. state: installed
  11. with_items:
  12. - mariadb-server
  13. - mariadb-client
  14. - python-mysqldb
  15. - name: Start and enable mysql
  16. service: name=mysql state=started enabled=yes
  17. - name: Set root Password
  18. mysql_user: name=root host={{ item }} password={{ mysql_root_password }} state=present
  19. with_items:
  20. - localhost
  21. - 127.0.0.1
  22. - ::1
  23. - name: Reload privilege tables
  24. command: 'mysql -ne "{{ item }}"'
  25. with_items:
  26. - FLUSH PRIVILEGES
  27. changed_when: False
  28. - name: Add .my.cnf
  29. template: src=my.cnf.j2 dest=/root/.my.cnf owner=root group=root mode=0600
  30. - name: Remove anonymous users
  31. command: 'mysql -ne "{{ item }}"'
  32. with_items:
  33. - DELETE FROM mysql.user WHERE User=''
  34. changed_when: False
  35. - name: Disallow root login remotely
  36. command: 'mysql -ne "{{ item }}"'
  37. with_items:
  38. - DELETE FROM mysql.user WHERE User='root' AND Host NOT IN ('localhost', '127.0.0.1', '::1')
  39. changed_when: False
  40. - name: Remove test database and access to it
  41. command: 'mysql -ne "{{ item }}"'
  42. with_items:
  43. - DROP DATABASE IF EXISTS test
  44. - DELETE FROM mysql.db WHERE Db='test' OR Db='test\\_%'
  45. changed_when: False
  46. - name: Reload privilege tables
  47. command: 'mysql -ne "{{ item }}"'
  48. with_items:
  49. - FLUSH PRIVILEGES
  50. changed_when: False
  51. ## Apache ##
  52. - name: PHP | Install Ondrej PHP PPA
  53. apt_repository:
  54. repo: 'ppa:ondrej/php'
  55. update_cache: yes
  56. - name: Install Apache and PHP
  57. apt:
  58. pkg: "{{ item }}"
  59. update_cache: no
  60. state: installed
  61. with_items:
  62. - apache2
  63. - php5.6
  64. - php5.6-cli
  65. - php5.6-mysql
  66. - php-gettext
  67. - php5.6-mbstring
  68. - libapache2-mod-php5.6
  69. - php5.6-gd
  70. - php5.6-imap
  71. - php5.6-xml
  72. - php5.6-intl
  73. - php5.6-apcu
  74. notify:
  75. - "restart apache"
  76. - name: purge php7.1
  77. apt:
  78. pkg: php7.1-common
  79. update_cache: no
  80. state: absent
  81. purge: yes
  82. notify:
  83. - "restart apache"
  84. - name: activate cgi.fix_pathinfo in php.ini
  85. lineinfile: dest=/etc/php/5.6/apache2/php.ini regexp=^[;]?cgi.fix_pathinfo line="cgi.fix_pathinfo=1"
  86. notify:
  87. - "restart apache"
  88. - name: set timezone in php.ini
  89. lineinfile: dest=/etc/php/5.6/apache2/php.ini regexp=^[;]?date.timezone line="date.timezone = Europe/Berlin"
  90. notify:
  91. - "restart apache"
  92. - name: Check existence of root directory for virthost
  93. stat:
  94. path: /var/www/{{inventory_hostname_short}}.{{freifunk.domain}}
  95. register: virthostroot
  96. - name: create root directory for virthost
  97. file: name=/var/www/{{inventory_hostname_short}}.{{freifunk.domain}} state=directory
  98. when: virthostroot.stat.islnk is not defined
  99. - name: Deploy virthost config
  100. template:
  101. src: templates/virthost.conf.j2
  102. dest: /etc/apache2/sites-available/{{inventory_hostname_short}}.{{freifunk.domain}}.conf
  103. notify:
  104. - "restart apache"
  105. - name: Enable virthost site with a2ensite
  106. shell: a2ensite -q {{inventory_hostname_short}}.{{freifunk.domain}}.conf
  107. args:
  108. creates: /etc/apache2/sites-enabled/{{inventory_hostname_short}}.{{freifunk.domain}}.conf
  109. notify:
  110. - "restart apache"
  111. - name: Enable mod_rewrite
  112. shell: a2enmod rewrite
  113. - name: install letsencrypt
  114. apt:
  115. pkg: python-letsencrypt-apache
  116. update_cache: no
  117. state: installed
  118. - name: Create certificate
  119. shell: letsencrypt --non-interactive --agree-tos --email {{freifunk.email}} --apache --domains {{inventory_hostname_short}}.{{freifunk.domain}}
  120. args:
  121. creates: /etc/letsencrypt/live/{{inventory_hostname_short}}.{{freifunk.domain}}/cert.pem
  122. - name: Install renewal cron
  123. cron:
  124. name: "Let's Encrypt Renewal"
  125. weekday: "1"
  126. hour: "2"
  127. minute: "30"
  128. job: "/usr/bin/letsencrypt renew >> /var/log/le-renew.log"