RubyConf AU 2014

Summarized using AI

Using Ruby to Automate Your Life

Seth Vargo • February 19, 2014 • Earth

In his talk at RubyConf AU 2014, Seth Vargo discusses the power of using Ruby, specifically through Chef, to automate common tasks in software development and infrastructure management. He emphasizes how automation can save time, reduce repetitive actions, and create consistency across various environments.

Key points discussed include:
- Common Frustrations: Developers often face repetitive tasks, such as running commands like cap deploy and bundle. This leads to inefficiencies and a feeling of technical debt.
- Chef Introduction: Chef is a configuration management tool that helps automate the setup and maintenance of systems, making it easier to deploy and manage applications across multiple environments.
- Cross-Platform Support: Chef works across multiple platforms, but Vargo focuses on Ubuntu in his demonstration. It’s useful for managing both server and local configurations.

- Benefits of Automation: Chef allows developers to provision laptops accurately to match production environments, helping avoid the common issue of the "it worked on my machine" syndrome. It can quickly create ephemeral staging environments, saving costs and resources.
- Scripting with Chef: An example is shared where Chef is used in place of Capistrano to streamline deployment processes. Chef’s Ruby DSL allows for clearer and more secure code management in deployments.

- Setting Up Developer Environments: Vargo highlights how automation can simplify the setup of new developer laptops, illustrating that with Chef scripts, environments can be established without manual installations.

- Comparison to Shell Scripts: Chef offers more reliability, easy testing with libraries like RSpec, and maintains item potency, which ensures consistent outcomes despite repeat executions.

In conclusion, Vargo encourages developers to leverage Chef to simplify their workflows, enhance productivity, and automate their environments for better efficiency. He invites the audience to learn more about Chef by visiting getchef.org and learnchef.com for tutorials, promoting a more automated approach to development workflows.

Using Ruby to Automate Your Life
Seth Vargo • February 19, 2014 • Earth

RubyConf AU 2014: http://www.rubyconf.org.au

You probably use Ruby everyday, so why not use Ruby to automate some common tasks? What if you could spin up an EC2 instance and have it automatically configure your web server, database, users, and more? What if you could effectively capture and replicate your production environments reliably and consistently? What if you could then give developers production-like environments as Virtual Machines, with no additional work? What if you could set up your new laptop with multiple Ruby versions, your favourite software, and even change the desktop background - from a single command? The good news is - you can!
Chef is a configuration management and automation tool that solves these problems and many more. In this talk, you'll learn common just how easy it is to capture your infrastructure in Chef. Save time and money by using Chef's Ruby DSL to "define" your laptop.
How many times have you bought a new laptop and realise just how much stuff you installed over the years? If you're using Chef, run a single command

RubyConf AU 2014

00:00:16.359 Hello everyone, and welcome to my talk on using Ruby to automate your life. I usually start with a joke, but since we're a little pressed for time, I'll keep it brief.
00:00:21.600 Typically, I share a story with a punchline at the end, but today I'll just jump straight to the joke.
00:00:27.080 So, today's joke is about Windows. How many people know what this is? It's a can, right? A very nice can! I drew it in Keynote, and since I’m not artistic, it took me about six days to finish.
00:00:33.200 This is the repetitive can—something you must do every day.
00:00:38.920 We just heard a talk about continuous delivery and deployment, and today I want to discuss automating not just your deployments, but everything you do.
00:00:45.360 As developers, who wants to type the same command a million times? We all have commands like `cap deploy` if you're using Capistrano, and how many of you have run `bundle` more than a million times in your life?
00:00:50.399 Commands like `vagrant up`, or `arpec`, or `irb`, or `pry`, and the list keeps growing.
00:00:56.640 You start adding your Bash commands for listing files and pinging just because you're pretending to be a sysadmin. Before you know it, you're doing the same thing repeatedly, hitting the up arrow in your command history, and growing frustrated.
00:01:03.640 You add more technologies while trying to ping GitHub and support HTML5 and Windows, which can feel tedious.
00:01:10.200 Your life may feel unimportant because you're spending so much time on the surrounding tasks that you can't get your actual work done.
00:01:15.560 It's like the technical version of meeting fatigue, where you're burdened by so much technical debt—not necessarily in code, but in processes—that you can’t finish your work.
00:01:21.799 So, my question is, what if there was a way to fix this?
00:01:28.680 We can find a solution together. The solution has to be reproducible; for example, the `ls` command will always give you the list of directories and files on a Unix-based system.
00:01:35.920 Similarly, we need a reliable solution. While `ls` works, we know that Ruby can be less reliable sometimes.
00:01:42.000 We also need it to be unattended, or rather—untended. I chose the word untended because 'unattended' didn’t fit on the slide next to my can.
00:01:47.600 I’ll blame it on my spelling and graphic design issues, but really, I want to talk about how we can use Ruby with Chef to automate the daily tasks that bog down our lives.
00:01:53.040 So, who am I? I’m Seth. I used to work at a company called Opscode, which rebranded to Chef. We are the company that develops Chef.
00:02:06.159 Here's my contact information, complete with cool logos. If you have questions, these slides are also posted on Speaker Deck. You can reach me on Twitter or email.
00:02:13.120 So, I have two disclaimers. First, I work for Chef, but this is not a vendor pitch.
00:02:18.680 Everything I’ll show you today is free and open-source, so you can set it up without us even knowing.
00:02:25.920 The second disclaimer is that everything in Chef is cross-platform, including Windows, but I'm focusing on Ubuntu today just because it's easier for people to relate.
00:02:32.480 If you’re using Windows, CentOS, or SmartOS, the principles still apply.
00:02:38.319 I know what you’re thinking: what is Chef? That’s a big question that can’t be answered quickly—but I’ll provide an overview.
00:02:46.720 Chef is for configuration management, ensuring that your servers—and even local computers—have the correct setups to run software.
00:02:53.879 For example, on a Mac, that configuration might tell an application like Sublime where to find its license file.
00:03:00.680 On Ubuntu, it could be the `httpd.conf` file that tells Apache how to run.
00:03:06.319 Chef also handles cloud administration; how many people here use AWS EC2, Digital Ocean, or run their own OpenStack clusters?
00:03:12.599 Chef helps manage many of these responsibilities and reduces repetitive tasks.
00:03:18.000 Lastly, Chef is about continuous delivery. Just heard a fantastic talk about it!
00:03:25.920 What if, instead of pushing code to production with Jenkins, Chef pulled the code from Master every time it runs?
00:03:32.480 So, it’s the same as continuous delivery, but instead of relying on the CI server to push changes, Chef pulls them in.
00:03:41.400 Additionally, Chef is community-driven. Some amazing changes and patches come from contributors outside Chef.
00:03:47.120 We’re open to external contributors, so if you’re a Chef user with great use cases and ideas, we would love to hear from you.
00:03:53.160 We’ve talked about a lot of things so far, but how can Chef actually help you with these issues?
00:04:00.000 Chef can provision our developer laptops to match our production and staging infrastructures.
00:04:07.080 This is crucial because how many times have you heard the phrase, 'It worked on my machine?'
00:04:12.480 If we provision our developer laptops accurately using tools like Vagrant, the probability of issues during production deployment decreases significantly.
00:04:19.720 Chef also helps maintain ephemeral staging environments; how many people know what that means?
00:04:30.800 An ephemeral environment is one that you don’t need to keep running—it can be torn down and recreated.
00:04:37.840 At a previous company, we had a non-ephemeral staging environment that sat idle in EC2, costing us thousands of dollars.
00:04:45.879 With Chef, you can spin up those environments quickly without the need to keep them running.
00:04:52.000 This model saves a lot of money by allowing you to recreate these environments in real time.
00:05:00.000 Chef also enables you to set up new infrastructure rapidly. If your production code is in Chef scripts, you're already set.
00:05:08.240 If a data center goes down, or you face a crisis, Chef helps maintain continuity.
00:05:14.200 Just look at Hurricane Sandy; many companies lost their data simply due to geographical issues.
00:05:22.240 Chef allows you to spin up a new data center effectively in the cloud.
00:05:29.160 I want to share some scenarios to illustrate how Chef can automate common tasks.
00:05:36.120 Let’s first look at Capistrano. How many people have used Capistrano to deploy applications?
00:05:41.400 What I think of Capistrano is that it can be a bit too much at times.
00:05:45.840 When you look at a Capistrano deploy, it creates various directories on the target system.
00:05:52.760 However, this seems outside the scope of what a deployment script should handle.
00:05:58.240 Let's instead rewrite this with Chef. Here's how we can accomplish it using a Chef script.
00:06:05.440 Right away, you notice the `do` and `end` block, so you know it’s Ruby code.
00:06:12.200 Chef treats resources and handles parameters or attributes within this block.
00:06:22.000 Each of the resources in Chef accepts a block of parameters.
00:06:28.560 This implicit action creates directories, ensuring that you specify the ownership and permissions.
00:06:38.720 This basic structure is how you ensure consistent directory creation using Chef.
00:06:46.000 Now that you have an understanding of the structure, let's look at the more complex Capistrano process.
00:06:53.840 Capistrano essentially checks out the latest code from Git or SVN, creates links, and runs migrations, depending on your setup.
00:07:01.640 In Chef, there's a built-in resource called `git` to handle Git commands.
00:07:10.000 Currently, we need to create a timestamp similar to how Capistrano does.
00:07:17.000 The `git` resource includes several parameters that you’ll utilize during deployment.
00:07:24.000 After that, the `link` resource acts as a symbolic link, directing to the linked files.
00:07:30.000 When using Chef, if the current link already exists, it will be overwritten.
00:07:36.760 This approach is straightforward and offers better readability than Capistrano scripts.
00:07:43.680 Chef is natively idempotent, meaning you can run the same actions without changing the system's state.
00:07:50.680 This is critical for security, especially when accessing production instances.
00:07:57.920 With Chef, developers don't need direct SSH access to production, just access to the GitHub project.
00:08:06.160 It's important to manage these keys securely. When a team member leaves, just removing them from GitHub suffices.
00:08:12.919 Also, the Chef client runs as a service.
00:08:19.720 Once you merge code, Chef will take care of the pull when it runs, which may be after a given interval.
00:08:26.960 This offers a resilient infrastructure because the process runs continuously.
00:08:34.000 In practice, that converts a Capistrano deploy into a GitHub push, simplifying the deployment process significantly.
00:08:41.360 This makes for a more enjoyable experience when deploying your code.
00:08:47.640 Now, let’s consider a scenario many developers can relate to: getting a new laptop.
00:08:55.760 How many companies give you just 48 hours to set up your new laptop?
00:09:01.080 You often spend that time configuring stickers, applications, and environment settings.
00:09:08.680 And if your laptop breaks, you have to start all over!
00:09:15.200 So, what’s often a typical scenario for a Ruby developer setting up a new laptop?
00:09:22.360 You're likely installing Vagrant and then VirtualBox, followed by Git and a browser.
00:09:29.680 You probably install Homebrew, PostgreSQL, and maybe MongoDB.
00:09:36.840 Then there’s the ordeal of installing Ruby versions using RVM or rbenv.
00:09:44.960 And don't forget ImageMagick or other dependencies.
00:09:52.560 Then, you go through a manual installation process for each application.
00:09:58.760 This can take time, and every change can feel tiresome.
00:10:07.680 But what if you could script that entire process instead?
00:10:15.680 For example, here’s code that installs Google Chrome without needing any manual clicks.
00:10:22.680 Imagine deploying a local cache on your network for files and packages.
00:10:29.480 This automation would save time and ensure consistency.
00:10:36.240 With Chef, you could install packages, set configurations, and change system preferences all from scripts.
00:10:44.240 Thus, with less than 150 lines of Ruby code, you've set up your new developer environment.
00:10:51.240 Imagine: no more manual installations or error-prone adjustments.
00:10:58.360 Now you only have to track your Chef scripts; everything else is automated.
00:11:05.440 Lastly, how is Chef better than a traditional shell script?
00:11:11.920 It's reliable and reproducible. Shell scripts can vary in outcome, while Chef provides consistent results.
00:11:18.560 Ruby code is easier to test with robust libraries such as RSpec, making Chef's reliability even stronger.
00:11:25.160 Moreover, Chef's item potency allows for running the same command without negative side effects.
00:11:31.600 If you’re on different platforms, Chef can handle that without much hassle.
00:11:39.000 It's cleaner and easier to read and write Ruby compared to shell scripts.
00:11:45.400 Most importantly, it’s actually developed in Ruby, not bash.
00:11:53.160 So, if you’re looking to automate your life, Chef is the way to go!
00:11:59.480 You can start by visiting getchef.org to download Chef.
00:12:06.760 If you're new to Chef, I recommend visiting learnchef.com for tutorials.
00:12:13.680 If you have questions or want to collaborate, here's how you can get in touch with me.
00:12:21.000 Thank you for your time! I'm happy to take any questions you may have.
00:12:29.560 Yes?
00:12:36.480 If you're working on a team and establishing a standard operating environment, is it practical to include personal customizations?
00:12:43.520 Sometimes, it’s easier to tweak system preferences manually rather than using Chef—especially for personal settings.
00:12:50.440 My personal laptop runs Chef for everything from dot files to applications, but it requires an iterative approach.
00:12:57.300 Each time I install a new application, I spend a little time incorporating it into my Chef scripts.
00:13:05.360 So in conclusion, while using a backup tool like Time Machine is a quick fix, automating your setup with Chef will ultimately save you time.
00:13:12.560 Thank you very much for your attention.
00:13:19.840 Seth, thank you!
Explore all talks recorded at RubyConf AU 2014
+17