Book Image

DevOps Automation Cookbook

By : Michael Duffy
Book Image

DevOps Automation Cookbook

By: Michael Duffy

Overview of this book

<p>There has been a recent explosion in tools that allow you to redefine the delivery of infrastructure and applications, using a combination of automation and testing to deliver continuous deployment. DevOps has garnered interest from every quarter, and is rapidly being recognized as a radical shift, as large as the Agile movement for the delivery of software.</p> <p>This book takes a collection of some of the coolest software available today and shows you how to use it to create impressive changes to the way you deliver applications and software. It tackles the plethora of tools that are now available to enable organizations to take advantage of the automation, monitoring, and configuration management techniques that define a DevOps-driven infrastructure.</p> <p>Starting off with the fundamental command-line tools that every DevOps enthusiast must know, this book will guide you through the implementation of the Ansible tool to help you facilitate automation and perform diverse tasks. You will explore how to build hosts automatically with the creation of Apt mirrors and interactive pre-seeds, which are of the utmost importance for Ubuntu automation. You will also delve into the concept of virtualization and creating and manipulating guests with ESXi. Following this, you will venture into the application of Docker; learn how to install, run, network, and restore Docker containers; and also learn how to build containers in Jenkins and deploy apps using a combination of Ansible, Docker, and Jenkins. You will also discover how to filter data with Grafana and the usage of InfluxDB along with unconventional log management. Finally, you will get acquainted with cloud infrastructure, employing the Heroku and Amazon AWS platforms.</p> <p>By tackling real-world issues, this book will guide you through a huge variety of tools, giving new users the ability to get up and running and offering advanced users some interesting recipes that may help with existing issues.</p>
Table of Contents (19 chapters)
DevOps Automation Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Controlling network interfaces


Networking is one of the core elements of server management, and can be one of the more complex to manage. This recipe will show you how to use the IP tool to discover the details of, and make changes to, the networking setup of your server.

Although these are ephemeral changes, the ability to apply them at the command line is very powerful; for instance, it allows you to script the addition and removal of IP addresses. When looking at command-line tools, it's a good idea to think of not only how they can help you now, but also how they could be used for automation in future.

Getting ready

The IP tools come preinstalled on the major Linux distributions (RHEL and Debian based), so additional configuration is no longer required.

How to do it…

Let's configure the network interface as follows:

  1. Sometimes you just want to know the IP address of the server you are working on; this can be found using the following command:

    $ ip addr show
    

    This should give you an output similar to to the following screenshot:

    This output gives you the details of each interface, including the IP address, state, MAC address, and interface options.

  2. To narrow this down to a single interface, you can use the following command:

    $ ip addr show <interface>
    

    Where <interface> is the name of the network interface you wish to see the details for. So, for example, to see the details of eth0 you can use the following command:

    $ ip addr show eth0
    
  3. To add a new IP4 address, you can use the ip addr add command. Note that you also need to supply a netmask in Classless Inter-Domain Routing (CIDR) format. The command looks like this:

    $ ip addr add  <IP address>/<CIDR> dev <device>
    

    For example, to add a new RFC1918-compliant address to the interface named eth1, you will use the following command:

    $ ip addr add 10.132.1.1/24 dev eth1
    
  4. You can confirm that the new address is available on the interface using the ip addr show command:

    $ ip addr show eth1
    
  5. Removing an IP address is a straightforward reversal of adding it. The command is the same as the command used to add addresses, but with the delete option:

    $ ip addr del <IP address>/<CIDR> dev <device>
    
  6. So, to remove the address that we just added, we can use the following command:

    $ ip addr del 10.132.1.1/24 dev eth1
    

    The IP command can be used to control the physical interfaces; thus, allowing you to bring them up and down from the command line.

    Tip

    It goes without saying that you need to be careful when using this command. Removing the only available interface on a remote server is both possible, and if you don't have access to a remote console, extremely inconvenient.

  7. To bring an interface down, you can use the ip link set command, followed by the interface name, and then the desired state. For example, you can use the following command to enable the eth2 interface:

    $ ip link set eth2 down
    

    Conversely, to bring it back up, you can use the following command:

    $ ip link set eth2 up
    
  8. You can check the state of the interface using the ip command:

    $ ip addr eth2
    

See also

You can find further details on the ip command within its man pages. You can access these using the following command:

$ man 8 ip