Advertisement
Guest User

Untitled

a guest
Jun 25th, 2018
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 24.02 KB | None | 0 0
  1. #
  2. # The following playbook automates the migration of an existing Magento store into another environment/server
  3. # Currently supports the following:
  4. #
  5. # - magento 1 and magento 2
  6. #
  7. # - Transferring the files including git repos across
  8. # - Transferring the database and setting up credentials as per the store config (local.xml/env.php)
  9. # - Transferring the ssh identities so that git/deploybot setups continue to work
  10. # - Transferring nginx configuration
  11. # - Transferring and setting up varnish configuration
  12. #
  13. # ansible-playbook playbooks/migrations/magento.yml --extra-vars "host=original.cfstack.com destination=new.cfstack.com"
  14. #
  15. ---
  16. - name: "CF Migration Utility : Magento 1/2 / Shopware"
  17.  
  18. vars_files:
  19. - "../../data/variables/general.yml"
  20. - "../../data/variables/secret.yml"
  21.  
  22. # This allows us to use the playbook as both a role and a utility cli task
  23. hosts: "{{ host | default('all') }}"
  24. any_errors_fatal: false
  25.  
  26. vars:
  27.  
  28. enable_maintenance: "false"
  29. ssh_port_original: 3333
  30. ssh_port_destination: 22
  31.  
  32. platform: "magento1"
  33. php_version: "7.0"
  34. dump_and_restore_db: "false"
  35. transfer_files: "true"
  36. generate_ssl: "false"
  37. transfer_certificates: "true"
  38.  
  39. n981url: "https://files.magerun.net/n98-magerun.phar"
  40. n981filename: "n98-magerun.phar"
  41. n982url: "https://files.magerun.net/n98-magerun2.phar"
  42. n982filename: "n98-magerun2.phar"
  43. old_url: "aspinline.co.uk"
  44.  
  45. tasks:
  46.  
  47.  
  48. - name: "install python 2 on new host"
  49. raw: test -e /usr/bin/python || (apt -y update && apt install -y python-minimal)
  50. delegate_to: "{{ destination }}"
  51.  
  52. - name: "Get Public IP Address of destination host ({{ destination }})"
  53. ipify_facts:
  54. delegate_to: "{{ destination }}"
  55.  
  56. - name: "Update CFUtilityScripts"
  57. git:
  58. repo: https://github.com/CoreFinity/CFUtilityScripts.git
  59. dest: /usr/bin/CFScripts/
  60. version: master
  61. accept_hostkey: yes
  62.  
  63. - name: "Get Nginx VHOSTs Paths by parsing nginx config (used to detect magento version)"
  64. shell: >
  65. '/usr/bin/CFScripts/ansible/getNginxVhostPath.sh'
  66. register: vhost_path_result
  67. - set_fact: vhost_path={{ vhost_path_result.stdout }}
  68.  
  69. - debug:
  70. msg: "Found NGINX Path by parsing the config directory, path is {{ vhost_path }} {{ ansible_all_ipv4_addresses }}"
  71.  
  72. - name: "Get Magento version"
  73. command: "/usr/bin/CFScripts/ansible/getMagentoVersion.sh {{ vhost_path }}"
  74. register: magento_version_result
  75. - set_fact: magento_version={{ magento_version_result.stdout }}
  76.  
  77. - debug:
  78. msg: "Magento version appears to be {{ magento_version }}"
  79.  
  80. - name: "Create the same vhost path on the destination server"
  81. file:
  82. path: "{{ vhost_path }}"
  83. state: directory
  84. delegate_to: "{{ destination }}"
  85.  
  86. - name: "Generating RSA key for root on original server"
  87. user: name=root generate_ssh_key=yes
  88.  
  89. - name: "Downloading pub key of original server into tmp"
  90. fetch: src=/root/.ssh/id_rsa.pub dest=/tmp/id_rsa.tmp flat=yes
  91.  
  92. - name: "Copying local key to destination sever"
  93. local_action: "shell cat /tmp/id_rsa.tmp | ssh root@{{ destination }} 'cat >> /root/.ssh/authorized_keys'"
  94.  
  95. - name: "Deleting temporal files"
  96. local_action: file path=/tmp/id_rsa.tmp state=absent
  97.  
  98. - name: "Put the original site on maintenance if enabled (m1)"
  99. command: "touch {{ vhost_path }}/maintenance.flag"
  100. when: enable_maintenance == "true" and platform == "magento1"
  101.  
  102. - name: "Put the original site on maintenance if enabled (m2)"
  103. command: "touch {{ vhost_path }}/maintenance.flag"
  104. when: enable_maintenance == "true" and platform == "magento1"
  105.  
  106. - name: "Backup the database"
  107. command: "sh /usr/bin/CFScripts/backups/backupMagentoDb.sh {{ vhost_path }} >/dev/null 2>&1"
  108. when: dump_and_restore_db == "true"
  109.  
  110. - name: "Transfer site files from host ({{ inventory_hostname }}) to host ({{ destination }})"
  111. command: "rsync -aHAXxv --numeric-ids --delete --progress -e 'ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -T -c aes128-gcm@openssh.com -o Compression=no -x' {{ vhost_path }} root@{{ destination }}:{{ vhost_path }}"
  112. when: transfer_files == "true"
  113. ignore_errors: yes
  114.  
  115. - name: "Fix problems with packages"
  116. shell: dpkg --configure --pending
  117. delegate_to: "{{ destination }}"
  118.  
  119. - name: "Download CFUtilityScripts into destination host"
  120. git:
  121. repo: https://github.com/CoreFinity/CFUtilityScripts.git
  122. dest: /usr/bin/CFScripts/
  123. version: master
  124. accept_hostkey: yes
  125. delegate_to: "{{ destination }}"
  126.  
  127. - name: "Installing base stack packages"
  128. apt: pkg={{ item }} state=present
  129. with_items:
  130. - software-properties-common
  131. - nano
  132. - vim
  133. - pv
  134. - iotop
  135. - gawk
  136. - logrotate
  137. - git
  138. - docker
  139. - docker-compose
  140. - unzip
  141. - letsencrypt
  142. - python-pycurl
  143. - python-mysqldb
  144. - apt-transport-https
  145. async: 120
  146. poll: 2
  147. delegate_to: "{{ destination }}"
  148.  
  149. - name: "Set up root authosied keys"
  150. authorized_key: user=root key="{{ lookup('file', item) }}" state=present
  151. with_fileglob:
  152. - ../../data/public_keys/*.pub
  153. delegate_to: "{{ destination }}"
  154.  
  155. - name: "Add to Zabbix server for CF monitoring suite"
  156. local_action:
  157. module: zabbix_host
  158. server_url: http://monitor.corefinity.com
  159. login_user: ansible
  160. login_password: Kjl5Mab47nS1
  161. host_name: "{{ destination }}"
  162. visible_name: "{{ destination }}"
  163. host_groups:
  164. - Linux servers
  165. - Virtual machines
  166. - vortex
  167. link_templates:
  168. - Template App HTTP Service
  169. - Template App SSH Service
  170. - Template DB MySQL
  171. - Template OS Linux
  172. status: enabled
  173. state: present
  174. interfaces:
  175. - type: 1
  176. main: 1
  177. useip: 1
  178. ip: "{{ ipify_public_ip }}"
  179. dns: "{{ destination }}"
  180. port: 10050
  181.  
  182. - name: "Setup Percona repo"
  183. command: bash -lc "{{ item }}"
  184. with_items:
  185. - "wget https://repo.percona.com/apt/percona-release_0.1-5.$(lsb_release -sc)_all.deb -O /tmp/percona-release_0.1-5.$(lsb_release -sc)_all.deb"
  186. - "dpkg -i /tmp/percona-release_0.1-5.$(lsb_release -sc)_all.deb"
  187. - "dpkg -i /tmp/percona-*.deb"
  188. delegate_to: "{{ destination }}"
  189.  
  190. - name: Update apt
  191. become: yes
  192. become_user: root
  193. apt: update_cache=yes
  194. delegate_to: "{{ destination }}"
  195.  
  196. - name: Install Percona MySQL Server
  197. action: apt pkg={{ item }} state=present
  198. with_items:
  199. - percona-server-server-5.7
  200. - percona-server-client-5.7
  201. - python-mysqldb
  202. environment:
  203. DEBIAN_FRONTEND: noninteractive
  204. delegate_to: "{{ destination }}"
  205.  
  206. # Start to secure MySQL
  207. - mysql_user:
  208. name: ''
  209. host_all: yes
  210. state: absent
  211. delegate_to: "{{ destination }}"
  212.  
  213. - name: "create a mysql user with a random password"
  214. mysql_user:
  215. name: "{{ platform }}"
  216. password: "{{ lookup('password', '../../credentials/' + destination + '/' + platform + '_mysql_password chars=ascii_letters,digits') }}"
  217. priv: "*.*:ALL"
  218. state: present
  219. register: mysql_password
  220. delegate_to: "{{ destination }}"
  221.  
  222. - debug:
  223. msg: "Successfully created MYSQL user {{ platform }} with password {{ mysql_password }}"
  224. delegate_to: "{{ destination }}"
  225.  
  226. - name: "Update mysql root password for all root accounts"
  227. mysql_user: name=root host={{ item }} password={{ lookup('password', '../../credentials/' + destination + '/root_mysql_password chars=ascii_letters,digits') }}
  228. with_items:
  229. - "{{ inventory_hostname }}"
  230. - 127.0.0.1
  231. - ::1
  232. - localhost
  233. delegate_to: "{{ destination }}"
  234.  
  235. - set_fact:
  236. mysql_root_password: "{{ lookup('file', '../../credentials/' + destination + '/' + 'root_mysql_password') }}"
  237. mysql_platform_username: "{{ platform }}"
  238. mysql_platform_password: "{{ lookup('file', '../../credentials/' + destination + '/' + platform + '_mysql_password') }}"
  239. url: "https://{{ inventory_hostname }} /"
  240. platform_admin_password: "{{ lookup('password', '../../credentials/' + destination + '/' + platform + '_admin_password chars=ascii_letters,digits') }}"
  241. domain: "{{ inventory_hostname }}"
  242. ip: "{{ ipify_public_ip }}"
  243.  
  244. - name: "Copy .my.cnf file with root password credentials"
  245. template: src=../../templates/mysql/root.my.cnf.j2 dest=~/.my.cnf mode=0600
  246. delegate_to: "{{ destination }}"
  247.  
  248. - name: "check if DB exists"
  249. shell: mysql --host=127.0.0.1 --user=root --password={{ mysql_root_password }} -e 'SHOW DATABASES;' | grep -c {{ platform }}
  250. register: dbstatus
  251. failed_when: dbstatus.rc == 2
  252. delegate_to: "{{ destination }}"
  253.  
  254. - name: "Create database"
  255. mysql_db: name={{ platform }} collation=utf8mb4_unicode_ci state=present login_host=127.0.0.1 login_user=root login_password={{ mysql_root_password }}
  256. when: dbstatus.stdout == "0" and dump_and_restore_db == "true"
  257. delegate_to: "{{ destination }}"
  258.  
  259. - name: "Extract db"
  260. command: "gunzip {{ vhost_path }}/var/latest.sql.gz"
  261. when: dump_and_restore_db == "true"
  262. delegate_to: "{{ destination }}"
  263.  
  264. - name: "Import db into {{ platform }} from {{ vhost_path }}/var/latest.sql"
  265. mysql_db:
  266. state: import
  267. login_user: "{{ mysql_platform_username }}"
  268. login_password: "{{ mysql_platform_password }}"
  269. name: "{{ platform }}"
  270. target: "{{ vhost_path }}/var/latest.sql"
  271. async: 12000
  272. poll: 5
  273. when: dump_and_restore_db == "true"
  274. delegate_to: "{{ destination }}"
  275.  
  276. - name: "Ensure group web exists"
  277. group:
  278. name: web
  279. state: present
  280. delegate_to: "{{ destination }}"
  281.  
  282. - name: "Add the user 'web' a primary group of 'web'"
  283. user:
  284. name: web
  285. group: web
  286. delegate_to: "{{ destination }}"
  287.  
  288. - name: "Configure varnish"
  289. copy:
  290. src: ../../templates/ubuntu/varnish/varnish.gpg
  291. dest: /tmp/varnish.gpg
  292. when: platform == "magento2"
  293. delegate_to: "{{ destination }}"
  294.  
  295. - name: "Configure repo for varnish 5"
  296. apt_key:
  297. file: /tmp/varnish.gpg
  298. state: present
  299. when: platform == "magento2"
  300. delegate_to: "{{ destination }}"
  301.  
  302. - name: "Configure varnish"
  303. copy:
  304. src: ../../templates/ubuntu/varnish/varnish-5-xenial.list
  305. dest: /etc/apt/sources.list.d/varnishcache_varnish5.list
  306. when: platform == "magento2"
  307. delegate_to: "{{ destination }}"
  308.  
  309. - name: "Run the equivalent of apt-get update"
  310. apt:
  311. update_cache: yes
  312. when: platform == "magento2"
  313. delegate_to: "{{ destination }}"
  314.  
  315. - name: "Install varnish 5.x"
  316. apt: pkg={{ item }} state=installed
  317. with_items:
  318. - ['varnish']
  319. when: platform == "magento2"
  320. delegate_to: "{{ destination }}"
  321.  
  322. - name: "Install nginx"
  323. apt: pkg={{ item }} state=present
  324. with_items:
  325. - ['nginx']
  326. delegate_to: "{{ destination }}"
  327.  
  328. - name: "Add ondrej/php ppp"
  329. command: add-apt-repository ppa:ondrej/php
  330. delegate_to: "{{ destination }}"
  331.  
  332. - name: "Run the equivalent of apt-get update"
  333. apt:
  334. update_cache: yes
  335. delegate_to: "{{ destination }}"
  336.  
  337. - name: "Install PHP 7.1 for Magento 2 / Shopware"
  338. apt: pkg={{ item }} state=present
  339. with_items:
  340. - ['php7.1','php7.1-fpm','php7.1-mysql','php7.1-soap','php7.1-opcache','php7.1-zip','php7.1-curl','php7.1-mcrypt','php7.1-mbstring','php7.1-zip', 'php7.1-dom','php7.1-gd','php7.1-intl', 'php7.1-redis']
  341. when: platform == "magento2" or platform == "shopware"
  342. delegate_to: "{{ destination }}"
  343.  
  344. - name: "Install PHP 7.0 for Magento 1"
  345. apt: pkg={{ item }} state=present
  346. with_items:
  347. - ['php7.0','php7.0-fpm','php7.0-mysql','php7.0-soap','php7.0-opcache','php7.0-zip','php7.0-curl','php7.0-mcrypt','php7.0-mbstring','php7.0-zip', 'php7.0-dom','php7.0-gd','php7.0-intl', 'php7.0-redis']
  348. when: platform == "magento1" and php_version == "7.0"
  349. delegate_to: "{{ destination }}"
  350.  
  351. - name: "Install PHP 5.6 for Magento 1"
  352. apt: pkg={{ item }} state=present
  353. with_items:
  354. - ['php5.6','php5.6-fpm','php5.6-mysql','php5.6-soap','php5.6-opcache','php5.6-zip','php5.6-curl','php5.6-mcrypt','php5.6-mbstring','php5.6-zip', 'php5.6-dom', 'php5.6-redis', 'php5.6-gd']
  355. when: platform == "magento1" and php_version == "5.6"
  356. delegate_to: "{{ destination }}"
  357.  
  358. - name: "Install Redis"
  359. apt: pkg={{ item }} state=installed
  360. with_items:
  361. - ['redis-server']
  362. delegate_to: "{{ destination }}"
  363.  
  364. - name: "get current db password from local.xml if m1 so we can search and replace it with the auto generated one"
  365. shell: "php {{ vhost_path }}/n98-magerun.phar --root-dir={{ vhost_path }} --skip-root-check db:info password"
  366. register: old_db_password_result
  367. when: platform == "magento1"
  368. delegate_to: "{{ destination }}"
  369. - set_fact: old_db_password={{ old_db_password_result.stdout }}
  370. when: platform == "magento1"
  371.  
  372. - name: "Update local.xml (m1) with new auto generated mysql password"
  373. replace:
  374. path: "{{ vhost_path }}/app/etc/local.xml"
  375. regexp: "{{ old_db_password }}"
  376. replace: "{{ mysql_platform_password }}"
  377. backup: no
  378. when: platform == "magento1"
  379. delegate_to: "{{ destination }}"
  380.  
  381. - name: "debug current db pass"
  382. debug: msg="current db pass is {{old_db_password}}"
  383. when: platform == "magento1"
  384.  
  385. - name: "get current db username from local.xml if m1 so we can search and replace it with the auto generated one"
  386. shell: "php {{ vhost_path }}/n98-magerun.phar --root-dir={{ vhost_path }} --skip-root-check db:info username"
  387. register: old_db_username_result
  388. when: platform == "magento1"
  389. delegate_to: "{{ destination }}"
  390. - set_fact: old_db_username={{ old_db_username_result.stdout }}
  391. when: platform == "magento1"
  392.  
  393. - name: "Update local.xml (m1) with new auto generated mysql username"
  394. replace:
  395. path: "{{ vhost_path }}/app/etc/local.xml"
  396. regexp: "{{ old_db_username }}"
  397. replace: "{{ platform }}_mysql_username "
  398. backup: no
  399. delegate_to: "{{ destination }}"
  400. when: platform == "magento1"
  401.  
  402. - name: "debug current db username"
  403. debug: msg="current db pass is {{old_db_username}}"
  404. when: platform == "magento1"
  405.  
  406. - name: "get current dbname from local.xml if m1 so we can search and replace it with the auto generated one"
  407. shell: "php {{ vhost_path }}/n98-magerun.phar --root-dir={{ vhost_path }} --skip-root-check db:info dbname"
  408. register: old_db_dbname_result
  409. delegate_to: "{{ destination }}"
  410. when: platform == "magento1"
  411. - set_fact: old_db_dbname={{ old_db_dbname_result.stdout }}
  412. when: platform == "magento1"
  413.  
  414. - name: "Update local.xml (m1) with new auto generated mysql dbname"
  415. replace:
  416. path: "{{ vhost_path }}/app/etc/local.xml"
  417. regexp: "{{ old_db_dbname }}"
  418. replace: "{{ platform }}"
  419. backup: no
  420. delegate_to: "{{ destination }}"
  421. when: platform == "magento1"
  422.  
  423. - name: "debug current db dbname"
  424. debug: msg="current db pass is {{old_db_dbname}}"
  425. when: platform == "magento1"
  426.  
  427. - name: "Change PHP-FPM user (7.1)"
  428. replace:
  429. path: /etc/php/7.1/fpm/pool.d/www.conf
  430. regexp: 'www-data'
  431. replace: 'web'
  432. backup: yes
  433. when: platform == "magento2" or platform == "shopware"
  434. delegate_to: "{{ destination }}"
  435.  
  436. - name: "Change PHP-FPM user (5.6)"
  437. replace:
  438. path: /etc/php/5.6/fpm/pool.d/www.conf
  439. regexp: 'www-data'
  440. replace: 'web'
  441. backup: yes
  442. when: platform == "magento1" and php_version == "5.6"
  443. delegate_to: "{{ destination }}"
  444.  
  445. - name: "Change PHP-FPM user (7.0)"
  446. replace:
  447. path: /etc/php/7.0/fpm/pool.d/www.conf
  448. regexp: 'www-data'
  449. replace: 'web'
  450. backup: yes
  451. when: platform == "magento1" and php_version == "7.0"
  452. delegate_to: "{{ destination }}"
  453.  
  454. - name: "chown the current run files for php"
  455. command: bash -lc "{{ item }}"
  456. with_items:
  457. - "chown -R web:web /run/php/*"
  458. delegate_to: "{{ destination }}"
  459.  
  460. - name: restart php7.1-fpm
  461. service: name=php7.1-fpm state=restarted
  462. when: platform == "magento2" or platform == "shopware"
  463. delegate_to: "{{ destination }}"
  464.  
  465. - name: restart php7.0-fpm
  466. service: name=php7.0-fpm state=restarted
  467. when: platform == "magento1" and php_version == "7.0"
  468. delegate_to: "{{ destination }}"
  469.  
  470. - name: restart php5.6-fpm
  471. service: name=php5.6-fpm state=restarted
  472. when: platform == "magento1" and php_version == "5.6"
  473. delegate_to: "{{ destination }}"
  474.  
  475. - name: "Change nginx user to web"
  476. replace:
  477. path: /etc/nginx/nginx.conf
  478. regexp: 'www-data'
  479. replace: 'web'
  480. backup: yes
  481. delegate_to: "{{ destination }}"
  482.  
  483.  
  484.  
  485. - debug:
  486. msg: "Creating DNS A Record: {{ destination }} => {{ ipify_public_ip }}"
  487.  
  488. - cloudflare_dns:
  489. zone: corefinity.com
  490. record: "{{ destination }}"
  491. type: A
  492. value: "{{ ipify_public_ip }}"
  493. account_email: "{{ cloudflare_email }}"
  494. account_api_token: "{{ cloudflare_token }}"
  495.  
  496. - name: "Install latest version of composer"
  497. command: bash -lc "{{ item }}"
  498. with_items:
  499. - "curl -sS https://getcomposer.org/installer -o composer-setup.php"
  500. - "sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer"
  501. delegate_to: "{{ destination }}"
  502.  
  503. - name: "Setting up the composer config directory"
  504. file: path="/root/.config/composer/" state=directory
  505. delegate_to: "{{ destination }}"
  506.  
  507. - name: "Copy composer auth file"
  508. copy:
  509. src: ../../templates/platforms/shared/composer/auth.json
  510. dest: /root/.composer/auth.json
  511. owner: web
  512. group: web
  513. when: platform == "magento2"
  514. delegate_to: "{{ destination }}"
  515.  
  516. - name: "Setting up the htdocs root"
  517. file: path="{{ vhost_path }}/var/composer_home/" state=directory
  518. when: platform == "magento2"
  519. delegate_to: "{{ destination }}"
  520.  
  521. - name: stop nginx
  522. service: name=nginx state=stopped
  523. delegate_to: "{{ destination }}"
  524.  
  525. - name: "Ensure log directory for nginx exists"
  526. file: path="/var/log/nginx/{{ destination }}/" state=directory
  527. delegate_to: "{{ destination }}"
  528.  
  529. - name: "Get SSL certificate using certbot"
  530. command: bash -lc "{{ item }}"
  531. with_items:
  532. - "rm -rf /etc/letsencrypt/archive/{{ destination }}"
  533. - "rm -rf /etc/letsencrypt/live/{{ destination }}"
  534. - "rm -rf /etc/letsencrypt/renewal/{{ destination }}.conf"
  535. - "rm -rf /etc/letsencrypt/archive/{{ inventory_hostname }}"
  536. - "rm -rf /etc/letsencrypt/live/{{ inventory_hostname }}"
  537. - "rm -rf /etc/letsencrypt/renewal/{{ inventory_hostname }}.conf"
  538. - "openssl dhparam -out /etc/nginx/dhparam.pem 2048"
  539. - "letsencrypt certonly --standalone -d {{ destination }} --email support@corefinity.com --agree-tos"
  540. - "letsencrypt certonly --standalone -d {{ inventory_hostname }} --email support@corefinity.com --agree-tos"
  541. when: generate_ssl == "true"
  542. delegate_to: "{{ destination }}"
  543.  
  544.  
  545.  
  546. - name: "Delete default nginx vhost"
  547. file:
  548. state: absent
  549. path: "/etc/nginx/sites-enabled/default"
  550. delegate_to: "{{ destination }}"
  551.  
  552. - name: "Setting up the htdocs generated folder (m2)"
  553. file: path="{{ vhost_path }}/generated" state=directory
  554. delegate_to: "{{ destination }}"
  555. when: platform == "magento2"
  556.  
  557. - name: "Set permissions on the vhost/var folder folder"
  558. command: bash -lc "{{ item }}"
  559. delegate_to: "{{ destination }}"
  560. with_items:
  561. - "chmod -R 777 {{ vhost_path }}/var/"
  562.  
  563. - name: "Copy nginx config from original server ({{ inventory_hostname}}) to destination host ({{ destination }})"
  564. command: "rsync -aHAXxv --numeric-ids --delete --progress -e 'ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -T -c aes128-gcm@openssh.com -o Compression=no -x' /etc/nginx/ root@{{ destination }}:/etc/nginx/"
  565.  
  566. - name: "Remove any instances of real_ip_header from nginx config files"
  567. command: bash -lc "sed -ir '/real_ip_header/d' /etc/nginx/conf.d/*.conf"
  568. delegate_to: "{{ destination }}"
  569.  
  570. - name: "Update the ip address from ({{ ansible_all_ipv4_addresses }}) to ({{ ipify_public_ip }})"
  571. replace:
  572. path: "{{ item }}"
  573. regexp: "{{ ansible_all_ipv4_addresses }}"
  574. replace: "{{ ipify_public_ip }}"
  575. backup: no
  576. with_fileglob:
  577. - "/etc/nginx/conf.d/*.conf"
  578. delegate_to: "{{ destination }}"
  579.  
  580. - name: "Transfer letsencrypt certificates from original server ({{ inventory_hostname}}) to destination host ({{ destination }})"
  581. command: "rsync -aHAXxv --numeric-ids --delete --progress -e 'ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -T -c aes128-gcm@openssh.com -o Compression=no -x' /etc/letsencrypt/ root@{{ destination }}:/etc/letsencrypt/"
  582. when: transfer_certificates == "true"
  583.  
  584. - name: "Remove more_set_headers in nginx config"
  585. command: bash -lc "sed -ir '/more_set_headers/d' /etc/nginx/nginx.conf"
  586. delegate_to: "{{ destination }}"
  587.  
  588. - name: "Create directory for to stop nginx failing"
  589. file: path=/var/log/nginx/aspinline.co.uk/ state=directory
  590. delegate_to: "{{ destination }}"
  591.  
  592. - name: "remove old IP in nginx config"
  593. command: bash -lc "sed -i -e 's/"{{ ansible_all_ipv4_addresses[0] }}"/"{{ ipify_public_ip }}"/g' /etc/nginx/conf.d/aspinline.co.uk.conf"
  594. delegate_to: "{{ destination }}"
  595.  
  596.  
  597. - name: "rm contents of var/cache"
  598. command: bash -lc "/bin/rm -rf /var/www/vhosts/aspinline.co.uk/htdocs/var/cache/*"
  599. delegate_to: "{{ destination }}"
  600.  
  601. - name: "update url in DB"
  602. shell: /usr/bin/mysql -u magento1 -p{{ mysql_platform_password }} magento1 -e 'update core_config_data set value = "https://{{ destination }}/" where config_id = 6 or config_id = 7'
  603. delegate_to: "{{ destination }}"
  604.  
  605. - name: "Flush cache "
  606. command: "/var/www/vhosts/aspinline.co.uk/htdocs/n98-magerun.phar --root-dir={{vhost_path}} cache:flush"
  607. delegate_to: "{{ destination }}"
  608.  
  609. - name: "Update old url with new hostname"
  610. command: bash -lc "sed -i -e 's/{{old_url}}/{{ destination }}/g' /etc/nginx/conf.d/*.conf"
  611. delegate_to: "{{ destination }}"
  612.  
  613. - name: "Move ssl.includes file from old to new"
  614. command: bash -lc "mv /etc/nginx/conf.d/aspinline.co.uk.ssl.includes /etc/nginx/conf.d/m1.aspinline.co.uk.cfstack.com.ssl.includes"
  615. delegate_to: "{{ destination }}"
  616.  
  617. - name: "Move htdocs root to new location"
  618. command: bash -lc "{{ item }}"
  619. with_items:
  620. - "rm -rf /var/www/vhosts/m1.aspinline.co.uk.cfstack.com/htdocs"
  621. - "mkdir -p /var/www/vhosts/m1.aspinline.co.uk.cfstack.com/htdocs"
  622. - "mv /var/www/vhosts/aspinline.co.uk/htdocs /var/www/vhosts/m1.aspinline.co.uk.cfstack.com/"
  623. delegate_to: "{{ destination }}"
  624.  
  625. - name: "restart nginx"
  626. delegate_to: "{{ destination }}"
  627. service: name=nginx state=restarted
  628.  
  629. - command: bash -lc "{{ item }}"
  630. delegate_to: "{{ destination }}"
  631. with_items:
  632. - "chown -R web:web /var/www/vhosts "
  633. - "systemctl daemon-reload"
  634.  
  635. - name: "Configure varnish"
  636. copy:
  637. src: ../../templates/platforms/magento2/varnish/default.vcl
  638. dest: /etc/varnish/default.vcl
  639. delegate_to: "{{ destination }}"
  640. when: platform == "magento2"
  641.  
  642. - name: "Change the varnish ports"
  643. replace:
  644. path: /lib/systemd/system/varnish.service
  645. regexp: '6081'
  646. replace: '80'
  647. backup: no
  648. delegate_to: "{{ destination }}"
  649. when: platform == "magento2"
  650.  
  651. - command: bash -lc "{{ item }}"
  652. with_items:
  653. - "systemctl daemon-reload"
  654. delegate_to: "{{ destination }}"
  655.  
  656. - name: restart varnish
  657. service: name=varnish state=restarted
  658. delegate_to: "{{ destination }}"
  659. when: platform == "magento2"
  660.  
  661. - name: "Update all packages to the latest version"
  662. apt:
  663. update_cache: yes
  664. upgrade: dist
  665. delegate_to: "{{ destination }}"
  666.  
  667. - debug:
  668. msg: "Successfully installed {{ platform }}"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement