{"id":332,"date":"2017-12-10T19:42:18","date_gmt":"2017-12-10T17:42:18","guid":{"rendered":"https:\/\/www.petersplanet.nl\/?p=332"},"modified":"2017-12-10T19:50:09","modified_gmt":"2017-12-10T17:50:09","slug":"automate-wordpress-updates-with-ansible","status":"publish","type":"post","link":"https:\/\/www.petersplanet.nl\/index.php\/2017\/12\/10\/automate-wordpress-updates-with-ansible\/","title":{"rendered":"Automate WordPress Updates with Ansible"},"content":{"rendered":"<p>I have created an Ansible script to automatically update WordPress on a server. In this case the Ansible script runs locally on that server.<br \/>\n<!--more--><br \/>\nI think the script, that has been provided below, will explain itself.<\/p>\n<pre>- hosts: localhost\r\n  connection: local\r\n  tasks:\r\n    - name: stop httpd\r\n      systemd:\r\n        name: httpd\r\n        state: stopped\r\n      become: true\r\n\r\n    - name: backup html files\r\n      archive:\r\n        path: \/var\/www\/html\r\n        dest: \"\/home\/centos\/backups\/wordpress-bck-{{ansible_date_time.iso8601_basic_short}}.tgz\"\r\n        format: gz\r\n      become: true\r\n\r\n    - name: backup wordpress database\r\n      command: \/etc\/backup-wpdb.sh\r\n      become: true\r\n\r\n    - name: get latest wordpress\r\n      unarchive:\r\n        src:  https:\/\/wordpress.org\/latest.zip\r\n        dest: \/tmp\/\r\n        remote_src: yes\r\n      become: true\r\n\r\n    - name: Wait until wordpress has been downloaded\r\n      wait_for:\r\n        path: \/tmp\/wordpress\/index.php\r\n        state: present\r\n\r\n    - name: copy wordpress to website\r\n      shell: \/bin\/cp -rf \/tmp\/wordpress\/* \/var\/www\/html\/\r\n      become: true\r\n\r\n    - name: delete tmp wordpress\r\n      file:\r\n        path: \/tmp\/wordpress\r\n        state: absent\r\n      become: true\r\n\r\n    - name: start httpd\r\n      systemd: \r\n        name: httpd\r\n        state: started\r\n        daemon_reload: yes\r\n      become: true\r\n\r\n    - name: simple check website\r\n      uri:\r\n        url: https:\/\/www.petersplanet.nl\r\n<\/pre>\n<p>The command to run the script is:<\/p>\n<pre>sudo ansible-playbook -v update-wordpress.yml\r\n<\/pre>\n<p>The version of Ansible is: 2.4.1.0<\/p>\n<p>References:<br \/>\n<a href=\"https:\/\/docs.ansible.com\">https:\/\/docs.ansible.com<\/a><br \/>\n<a href=\"https:\/\/www.wordpress.org\">https:\/\/www.wordpress.org<\/a><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I have created an Ansible script to automatically update WordPress on a server. In this case the Ansible script runs locally on that server.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,9],"tags":[],"class_list":["post-332","post","type-post","status-publish","format-standard","hentry","category-linux","category-programming"],"_links":{"self":[{"href":"https:\/\/www.petersplanet.nl\/index.php\/wp-json\/wp\/v2\/posts\/332","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.petersplanet.nl\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.petersplanet.nl\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.petersplanet.nl\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.petersplanet.nl\/index.php\/wp-json\/wp\/v2\/comments?post=332"}],"version-history":[{"count":10,"href":"https:\/\/www.petersplanet.nl\/index.php\/wp-json\/wp\/v2\/posts\/332\/revisions"}],"predecessor-version":[{"id":342,"href":"https:\/\/www.petersplanet.nl\/index.php\/wp-json\/wp\/v2\/posts\/332\/revisions\/342"}],"wp:attachment":[{"href":"https:\/\/www.petersplanet.nl\/index.php\/wp-json\/wp\/v2\/media?parent=332"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.petersplanet.nl\/index.php\/wp-json\/wp\/v2\/categories?post=332"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.petersplanet.nl\/index.php\/wp-json\/wp\/v2\/tags?post=332"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}