Advertisement
Guest User

Untitled

a guest
May 3rd, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.83 KB | None | 0 0
  1. --
  2. - hosts: all
  3. gather_facts: True
  4. vars:
  5. wp_mysql_db: MyWP
  6. wp_mysql_user: wpUser
  7. wp_mysql_password: wpP4ss
  8. mysql_root_user: root
  9. mysql_root_password: Solinea
  10.  
  11. - hosts: db
  12. remote_user: ubuntu
  13. become: yes
  14. become_method: sudo
  15. # Multi-Tier WP install
  16.  
  17. ## Setup dependencies
  18. tasks:
  19. - name: Add repo file
  20. template: src=mariadb.list.j2 dest=/etc/apt/sources.list.d/mariadb.list owner=root group=root mode=0644
  21. register: mariadb_list
  22.  
  23. - name: Add repo key
  24. apt_key: id=1BB943DB url=http://keyserver.ubuntu.com/pks/lookup?op=get&search=0xCBCB082A1BB943DB state=present
  25. register: mariadb_key
  26.  
  27. # - name: Update all packages
  28. # apt: upgrade=dist update_cache=yes
  29.  
  30. - name: Unattended package installation
  31. shell: export DEBIAN_FRONTEND=noninteractive
  32. changed_when: false
  33.  
  34. - name: Install needed packages
  35. apt: name={{ item }} state=present update_cache=yes
  36. with_items:
  37. - vim-nox
  38. - apache2
  39. - mariadb-server
  40. - mariadb-client
  41. - php5
  42. - php5-mysql
  43. - python-mysqldb
  44.  
  45. - name: Enable remote MySQL access
  46. lineinfile: dest=/etc/mysql/my.cnf regexp="^bind-address" line="bind-address = 0.0.0.0"
  47.  
  48. - name: Set root password
  49. mysql_user: name="{{ mysql_root_user }}" password="{{ mysql_root_password }}" host="{{ item }}" priv=*.*:ALL,GRANT state=present
  50. with_items:
  51. - "{{ ansible_hostname }}"
  52. - "{{ hostvars['web01']['ansible_eth0']['ipv4']['address'] }}"
  53. - 127.0.0.1
  54. - ::1
  55. - localhost
  56. ignore_errors: true
  57.  
  58. - name: Copy ~/.my.cnf to nodes
  59. template: src=my.cnf.j2 dest=/root/.my.cnf
  60.  
  61. - name: Create MariaDB database
  62. mysql_db: name={{ wp_mysql_db }} state=present
  63.  
  64. - name: Create MariaDB username and password
  65. mysql_user:
  66. login_user={{ mysql_root_user }}
  67. login_password={{ mysql_root_password }}
  68. name={{ wp_mysql_user }}
  69. host={{ hostvars['web01']['ansible_eth0']['ipv4']['address'] }}
  70. password={{ wp_mysql_password }}
  71. priv=*.*:ALL
  72.  
  73. - name: Ensure MariaDB is running (and enable it at boot)
  74. service: name=mysql state=restarted enabled=yes
  75.  
  76. - hosts: web
  77. remote_user: ubuntu
  78. become: yes
  79. become_method: sudo
  80.  
  81. tasks:
  82. # - name: Update all packages
  83. # apt: upgrade=dist update_cache=yes
  84.  
  85. - name: Unattended package installation
  86. shell: export DEBIAN_FRONTEND=noninteractive
  87. changed_when: false
  88.  
  89. - name: Install needed packages
  90. apt: name={{ item }} state=present update_cache=yes
  91. with_items:
  92. - vim-nox
  93. - apache2
  94. - mysql-client
  95. - php5
  96. - php5-mysql
  97. - python-mysqldb
  98.  
  99. - name: Is WP-CLI downloaded?
  100. stat: path="/usr/local/bin/wp"
  101. register: wpcli_is_downloaded
  102.  
  103. - name: Download WP-CLI
  104. get_url:
  105. url: https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
  106. dest: /usr/local/bin/wp
  107. mode: 0655
  108. when: wpcli_is_downloaded.stat.exists == False
  109.  
  110. - name: Make WP-CLI executable
  111. file:
  112. path: /usr/local/bin/wp
  113. mode: u=rwx,g=rx,o=rx
  114. when: wpcli_is_downloaded.stat.exists == False
  115.  
  116. - name: Is WordPress downloaded?
  117. stat: path=/var/www/html/index.php
  118. register: wordpress_is_downloaded
  119.  
  120. - name: Download WordPress
  121. shell: /usr/local/bin/wp core download --allow-root
  122. args:
  123. chdir: /var/www/html
  124.  
  125. when: wordpress_is_downloaded.stat.exists == False
  126.  
  127. - name: Configure WordPress
  128. shell: /usr/local/bin/wp core config --allow-root
  129. --path=/var/www/html
  130. --dbhost="{{ hostvars['db01']['ansible_eth0']['ipv4']['address'] }}"
  131. --dbname="{{ wp_mysql_db }}"
  132. --dbuser="{{ wp_mysql_user }}"
  133. --dbpass="{{ wp_mysql_password }}"
  134. when: wordpress_is_downloaded.stat.exists == False
  135.  
  136. - name: Is WordPress installed?
  137. shell: /usr/local/bin/wp core is-installed --allow-root
  138. args:
  139. chdir: /var/www/html/
  140. register: wordpress_is_installed
  141. ignore_errors: True
  142.  
  143. - name: Install WordPress tables
  144. become: yes
  145. become_method: sudo
  146. shell: /usr/local/bin/wp core install --allow-root
  147. --path=/var/www/html
  148. --url="http://{{ hostvars['web01']['ansible_eth0']['ipv4']['address'] }}"
  149. --title="Solinea Ansible"
  150. --admin_user="admin"
  151. --admin_password="Solinea"
  152. --admin_email="jason@solinea.com"
  153. when: wordpress_is_installed|failed
  154.  
  155. #Remove index.html so WP loads at default URL
  156. - file: path=/var/www/html/index.html state=absent
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement