 So, I hope that you have enjoyed the lunch and now you are in charge to learn some new things about how can you optimize your WordPress day-to-day tasks by automating them. A few words about me. My name is Ivan and I'm working at SiteGround at the moment. I've been with the company for five years and I pretty much went to most of the technical departments there from technical support and doing some DevOps and QA tasks. And right now I'm working as an enterprise solutions engineer where we are building, designing and maintaining infrastructures for our biggest clients. I'm sure that you have heard some of them for example Yoast SEO or WP Forms or most websites. So, yeah and actually in this position I have learned how important is to automate the tasks that we are completing daily in order to have better time management and save time for more significant tasks. And there is a short summary what this talk is going to be about. First of all, I'm saying a few words about automation in general. Then I will introduce you to Ansible and tell you how WordPress can benefit from it. And then I have three videos with practical examples how Ansible is run, how you can write your configs and so on. So let's start with automation and by automation I mean the use software to create repeatable instructions that will reduce the human interactions with tidy systems. And this is good because first of all we are saving a lot of time. Then we are decreasing the errors that we are making by manually executing commands again and again. And from my experience I can say that automation is very very useful when it comes to server provisioning, application deployment, configuration management or even continuous delivery. And now to the point what is Ansible? If I should explain it without going into technical terms, I would say that Ansible is a software that allows us to create tasks and execute them to replace the things that we are doing manually every day. It is really simple but at the same time very powerful software which is agentless and it's only using Cache to connect to the remote machines we are working on. And of course you don't need any specific Cache skills to have. It is just the software using that type of connection to the remote systems and you don't need to create bus scripts or anything like that. And most of the definitions and the configuration files in Ansible are written in YAMU so it's really easy to read and understand even by inexperienced users. So and that's what I like the most because it's practically human readable. And these are the cases which I think are more often the most common cases when we use Ansible. As I mentioned, provisioning, application deployment, configuration management and continuous delivery. And now some theory about Ansible and its parts. I know that we don't like theory but we need to go through this in order to have the practical examples more understandable at the end. So in order to avoid speaking with technical terms only I am trying to compare Ansible with something from the real world and that is a car assembly line. So what we have whenever we are making a car is a specific set of instructions that are executed every time we make each model. So it's the same with Ansible. Ansible Playbook which is the main part of the service is a set of instructions that are executed in a certain way, in a certain order. These instructions whenever when we are in the car factory we have a lot of machines right? So each machine there is doing something and that's exactly modules are in Ansible. There are small programs that are designed to perform small simple tasks and they are based on parameters that we pass in our configuration files. So there are a list of modules on Ansible sites and there are literally hundreds but if by chance there is a service you're using and there is no module for that you can ride your own. And speaking of the machines in the car factory each of them has completely and specifically defined tasks. For example there are machines that are forming the metal parts, machines that are putting stuff under the hood right? So we have the same thing in Ansible. We are defining tasks in YAMU syntax and then these tasks are executed with the help of the modules that I mentioned before that. And all car manufacturers have different models, they have cars with different colors and so on. So in the IT world whenever we have 10 or 20 systems we might want to execute the same set of instructions on each of them but at the same time we want to keep the difference between the systems. We might have some different configuration files or something like that. So that's how Ansible handles the difference between our systems with using variables and templates. Handlers are practically small and very simple tasks that are triggered after the execution of another task. So right here in the example we have defined handware which is restarting Apache service and in the next slide we have a task that is practically replacing the Apache configuration file with the template I'm passing to it. So with that notified line here and then I'm specifying that I want to trigger the handware that I have specified in the previous slide. So what this block of code will do is it will replace the template with the source I have provided and after that the Apache service will be restarted to apply the changes. And at the end we have rows which are pretty much a combination of all the parts I've set so far. Rows are a pretty comfortable way to gather groups of tasks, variables, modules and which are related to one same server services. For example if I want to install and configure Apache all the way from the beginning to the end I would have tasks for downloading the package, installing the package, then I need to adjust the vhosts, then configuration files and so on. And all these tasks might be grouped in one single row which is code with just one line instead of calling each task separately in your playbook. Okay now enough about Ansible only let's see why I think Ansible is great to use with WordPress and I know that there are a lot of one-click installers or applications that allow you to manage your WordPress dashboards of different sites but it's cool to have everything that in one single application or software which actually is installed on your computer and you don't need to log in anywhere to manage your sites right. So I would say that Ansible would be very useful whenever we want to have WordPress deployed somewhere and I'm not talking only about the WordPress core, I'm talking about creating a bundle for example with your favorite plugins or teams which you want to have pre-installed every time you install the WordPress. So as well as environment changes for example if you're running WordPress in subfolder what you usually do I think is that you are installing the WordPress with one-click installer or whatever and then you go and manually adjust the WordPress to work in subfolder which actually can be automated and you can have everything defined in Ansible and execute it automatically without you having to do anything. Another useful example would be managing plugins of a lot of sites. I don't know how much of you here are managing most of five sites or ten sites which are on different servers but it is a good way to have for example to install or update the plugin on all of your applications no matter if they are located on the same or different servers no matter. Also Ansible is a very good option if you want to automate your code deployment because it has Git and subversion modules and of course I think that it's very useful whenever it comes to any task that you are executing via SH I mean not only related to WordPress as an application itself but whenever you need to let's say change permissions of files or update your htaccess file or php.ini file it is basically you can automate everything that you're doing manually in SH. And we reached the practical examples first of all I would like to can you see it well okay first of all I'd like to show my Ansible project folder which is I've created it it's very simple and I've just created for here for this conference to show you what I have in it. First of all I have a playbooks folder where obviously I keep my playbooks that I will show you in the videos after that. Then I have roles that I have written and I will be executed which will be executed in my playbooks later and I have this host file here which is actually a very important part of Ansible and it's called inventory. The inventory file contains the information about your hosts and you can also specify some variables there. I know that security is very important as well as you I'm sure but this is just an example don't mind for example I have plain text passwords here or something like that just ignore it I know you need to keep your safe sites and don't don't do that at home so right here these are group names one group can contain multiple hosts in my case I have one host in each group here then you have the host name which can be pretty much everything you want. Ansible port and Ansible hosts are very important variables because they are used by the software to connect via SSH to the server and then you can add pretty much whatever variables you want in order to suit your roles and your playbooks whatever you need in my case I have database username password WordPress directory where I will install my WordPress and then memcached host and memcached port so the first is the first example is related to it in deploying an application WordPress application and this is my playbook here which will do that for me as you can see I have defined two plays install WordPress core and install initial initial plugins which is a typo but okay so in that first play I'm calling one role which is called install WordPress core and then I'm calling three more tasks separately which are create database and create database users they are pretty straightforward so I'm not gonna open and review them and at the end I have configurable press just a moment to the main dot wide ml file is file that is executed every time you are calling a role I mean it's executed first by default and every time you are calling a role so in my main wide ml file I have two tasks first the feature is ensure WordPress destination is present which is creating my directory where the WordPress will be hosted and the second one is actually WPCI comment where I'm using it to download the files the core files of the application the first task here you can see that this defined using the file module which in Ansible is a module which is create the creates files directories and in that case I am specifying that I want to create the WordPress directory variable here which should be in state directory it might be state file or star state absent which will remove that and the second task is downloading the file which is I'm using the comment module the comment module is pretty flexible thing because it's like you're just executing some message common via bash or on the remote server so what I'm doing here is passing this bash comment to all my remote host that I'm running Ansible on and now let's get to the videos okay there you go stopping for a second just to tell you that Ansible can be used in common line mode not only defining playbooks and writing YAML code in order to have it executed but in this in this example you can see that I'm using the Ansible binary and passing some parameters which will actually execute the comment and specifying in the quotes on all my hosts I have defined in my inventory and the purpose of what I'm showing you now is to show you that before running the playbook there is nothing on servers you can see that I'm trying to access this folder and it is not existing at the moment then I'm going to show that there is no database is created also on the servers and there you go and then I am executing the actual comment that will start our playbook execution which has some important parameters here the I parameter specified the inventory file that I'm using which contains the information of the remote hosts then I'm specifying here the name of the playbook and then I'm passing some extra variables that are needed in order to have my roles executed correctly the first task by default is this thing called gathering facts which is practically going through your Ansible directory checking the files and getting information about the variables and then we start with the tasks one by one executed on each host simultaneously here I'm going to stop for a second just to show you that there is a slight difference between creating database and creating database users so first we have change status and then we have okay status what this means is that Ansible is actually remembering states of the tasks and I have created the database user before running the playbook so Ansible did not took any action it just saw that the user is already created and its reporting task is okay because there is nothing more to do there and then I have configuring and installing WordPress which is actually WPCI comments configuring install and then after that we are going to the second play which would install the plugin we have specified there which are four plugins I have picked randomly and at the end of each play we have that play recap which is actually a summary of what we have done so far after that I'm again using the Ansible comment in order to show you that after the play there is actually some content on the servers and the first the first thing is to show that there is WordPress core files inside the directory we have created then using the MySQL command line in order to show you that there are database created and the WordPress core tables are actually there on each host separately and in the end again running WPCI plugin list comment in order to show you that we don't only have the core installations there but we now have core installations with the plugins we have specified pre-installed there without having to do that manually so this was the first example as a whole of course it's it's very simple but you cannot so much more there if you want and if you have any customizations that you have you need to do on your side the second thing is managing plugins and teams and as I said whenever we are managing 20 sites and I'm not sure but I personally don't know which installation which has any specific plugins so whenever you see that the plugin is outdated and you might want to check if it's need to be updated on your sites Ansible is very good thing to automate that because it can go through all your applications and update the plugin where it is present let me check the next video there you go so again I'm using Ansible binary in order to delete the plugin called booking only on two of my projects so I will have this plugin installed on two work presses and then I will have it deleted from the rest of the two rest of the hosts so waiting for the confirmation message here then quick check with is installed option in order to see and confirm that this plugin is not present on this work presses there you go and now running again the Ansible playbook command which will start executing the next playbook I have which is called plugins.yml again specifying the inventory file and passing some extra bars so that the row can be executed properly getting facts again there we have this message the bug message which is doing nothing just displaying some information I wanted to show you because it is a good way to debug whenever your playbook is failing or getting an error or there is undefined variable the debug message is a good way to see what value does the variable contains and it's just used to display some information then I have checking a plugin function which had something red there so it failed and actually this is the another thing there you go we have failures on two of our hosts and the thing is that whenever there is a playbook for example on four hosts and whenever a task fails on one host it is excluded until the rest of the play so what this playbook does is to first to check all my hosts if the plugin is installed and then if it's installed to update it and since we don't have it on these two hosts they're excluded now from the play and at the end we have we have here the task for update only on the host that actually have the plugin present and here it is the recap again this time we have two failed hosts as we understood it and then just a quick check to see that the booking plugin is actually installed only on two of our hosts there you go we have two hosts which have the plugin installed and then we have two which doesn't have it so moving on to the last example which is actually an example where you are using a git module and what it does is to download in fact it's copy a repo which contains memcache drop-in then deploy it on our four hosts and then checking if then replacing the host and the port inside the object object cache PHP to with the variables we want so again getting faster factory of fast here we we are calling the the repo then we are synchronizing the file to our hosts fixing some permissions and ono ships and at the end I'm using a replace module which you pass a string to and it's it is replacing it replacing it with another string so pretty much the result here can be seen we now have the object cache dot PHP file and we have changed the host and the port inside that file on all my four hosts without having to do anything manually and the last example I don't have any videos because it's very simple and I mean that whenever you need to change htaccess or PHP dot in your WP config file or a lot of applications ansible is very good choice in order to do that automated and do not do it manually so in my opinion combining ansible and WordPress would save you a lot of time and what's even better is that you don't need to have 50 applications in order to use ansible you can start really small with really simple tasks for example a task only for changing permissions and start running on your projects and as your project projects grow your ansible code base will grow gradually with it that was all thank you very much for the attention and if you have any questions your name please and the question yeah I think it should be so I'm just going to ask so you're using the WordPress command line to support the engines that are really inside WordPress right yeah so if I'm running my host setup in the talker and everything is authorized what would be the good way if I don't want to put the WordPress binary command line to my well ansible in my case is just using that binary in order to have the plugins and application installed so I presume that you have installed WPCY already but if you haven't you can do everything pretty much everything as you do it in SH command line so in order you can also use Wget or any Linux command in order to download the package on zip to extract the package and so on so it's just more tasks defining and it's a little bit more work how does this work in the team environment because it looks like it has the playbook and everything lives on your own computer and so how will it work in a team environment? I didn't understand the question can you repeat? okay so it looks like your playbook and they are stored in your local machine but what if I want to share these workflows with other members of my team? well personally in my team we have all of our Ansible configuration in a Git repo so whenever someone wants to use it just cloning the repo and reuses the tasks and the roles and everything so it's pretty much comfortable to have it in a Git repo or on a machine on a control machine whenever everybody can log in and use it Do we have any more questions? Maybe the last one? One, so my question is how would you secure your credentials for the machines that you have written for? Yeah I mentioned that this example was not secure at all but it was created only for the purpose of this conference but for example Ansible has different modules where you can randomly generate a password, record it in a variable and then use this variable without having the password actually displayed anywhere I think that's all we have, thanks for sharing Thank you very much