ТЕМА: Pompano Beach : powerapps azure devops - Эдуард Кабринский

Pompano Beach : powerapps azure devops - Эдуард Кабринский 2 років 10 місяців тому #30046

Кабринский Эдуард - Ansible deployment automation - Эдуард Кабринский


<h1>Ansible deployment automation</h1>
<p>[youtube]</p>
Ansible deployment automation <a href="remmont.com">Today's news headlines in english</a> Ansible deployment automation
<h1>How to automate your system administration tasks with Ansible</h1>
<h2>Sharpen your sysadmin and Linux skills and learn how to set up tooling to simplify administering multiple machines.</h2>
<p style="clear: both"><img src="opensource.com/sites/default/files/style...NESS_google_wave.png" /></p>
<h2>Subscribe now</h2>
<p>Get the highlights in your inbox every week.</p>
<p>Do you want to sharpen your system administration or Linux skills? Perhaps you have some stuff running on your local LAN and you want to make your life easier—where do you begin? In this article, I'll explain how to set up tooling to simplify administering multiple machines.</p>
<p>When it comes to remote administration tools, SaltStack, Puppet, Chef, and Ansible are a few popular options. Throughout this article, I'll focus on Ansible and explain how it can be helpful whether you have 5 virtual machines or a 1,000.</p>
<p>Our journey begins with the basic administration of multiple machines, whether they are virtual or physical. I will assume you have an idea of what you want to achieve, and basic Linux administration skills (or at least the ability to look up the steps required to perform each task). I will show you how to use the tools, and it is up to you to decide what to do with them.</p>
<h2>What is Ansible?</h2>
<p>The Ansible website explains the project as "a radically simple IT automation engine that automates cloud provisioning, configuration management, application deployment, intra-service orchestration, and many other IT needs." Ansible can be used to perform the same tasks across a defined set of servers from a centralized location.</p>
<p>If you are familiar with Bash for-loops, you'll find that Ansible operates in a similar fashion. The difference, however, is that Ansible is <i>idempotent</i>. In layman's terms this means that generally Ansible only performs the requested action if a change will occur as a result. For example, if you were to perform a Bash for-loop to create a user across all of your machines, it may look something like this:</p>
<p>This would create <b>myuser</b> on <b>serverA</b>, <b>serverB</b>, and <b>serverC</b>; however, it would run the <b>user add</b> command every single time the for-loop was run, whether or not the user existed. An idempotent system will first check whether the user exists, and if it does not, the tool will create it. This is a simplified example, of course, but the benefits of an idempotent tool will become more clear over time.</p>
<h3>How does Ansible work?</h3>
<p>Ansible translates <i>Ansible playbooks</i> into commands that are run over SSH, which has several benefits when it comes to managing Unix-like environments:</p>
<p><ol>
<li>Most, if not all of the Unix-like machines you are administering will have SSH running by default.</li>
<li>Relying on SSH means that no agent is required on the remote host.</li>
<li>In most cases no additional software needs to be installed as Ansible requires Python 2.6 in order to operate. Most, if not all distributions of Linux have this version (or greater) installed by default.</li>
<li>Ansible does not require a <i>master</i> node. It can be run from any host that has the Ansible package installed and sufficient SSH access.</li>
<li>Although running Ansible in a cron job is possible, by default Ansible only runs when you tell it to.</li>
</ol>
</p>
<h3>Setting up SSH key authentication</h3>
<p>A common method for using Ansible is to set up passwordless SSH keys to facilitate ease of management. (Using Ansible Vault for passwords and other sensitive information is possible, but is outside the scope of this article.) For now, simply generate an SSH key with the following command as shown in Example 1.</p>
<h4>Example 1: Generating An SSH Key</h4>
<p>In Example 1, the <i>Enter</i> key is used to accept the defaults. An SSH key can be generated by any unprivileged user and installed in any user's SSH <b>authorized_keys</b> file on the remote system. After the key has been generated, it will need to be copied to a remote host. To do so, run the following command:</p>
<p><i>Note: Ansible does not require root access; however, if you choose to use a non-root user, you</i> must <i>configure the appropriate <b>sudo</b> permissions for the tasks you want to accomplish.</i></p>
<p>You will be prompted for the root password for <b>servera</b>, which will allow your SSH key to be installed on the remote host. After the initial installation of the SSH key, you will no longer be prompted for the root password on the remote host when logging in over SSH.</p>
<h2>Installing Ansible</h2>
<p>The installation of the Ansible package is only required on the host that generated the SSH key in Example 1. If you are running Fedora, you can issue the following command:</p>
<p>If you run CentOS, you need to configure Extra Packages for Enterprise Linux (EPEL) repositories:</p>
<p>Then you can install Ansible with yum:</p>
<p>For Ubuntu-based systems, you can install Ansible from the PPA:</p>
<p>If you are using macOS, the recommended installation is done via Python PIP:</p>
<h2>Working with Ansible Inventory</h2>
<p>Ansible uses an INI-style file called an <i>Inventory</i> to track which servers it may manage. By default this file is located in <b>/etc/ansible/hosts</b>. In this article, I will use the Ansible Inventory shown in Example 2 to perform actions against the desired hosts (which has been paired down for brevity):</p>
<h4>Example 2: Ansible hosts file</h4>
<p>Each group, which is denoted via square brackets and a group name (such as <b>[group1]</b>), is an arbitrary group name that can be applied to a set of servers. A server can exist in multiple groups without issue. In this case, I have groups for operating systems (<i>arch</i>, <i>ubuntu</i>, <i>centos</i>, <i>fedora</i>), as well as server function (<i>ocp</i>, <i>satellite</i>). The Ansible host file can handle significantly more advanced functionality than what I am using. For more information, see the Inventory documentation.</p>
<h2>Running ad hoc commands</h2>
<p>After you have copied your SSH keys to all the servers in your inventory, you are ready to start using Ansible. A basic Ansible function is the ability to run ad hoc commands. The syntax is:</p>
<p>For example, if you want to update all of the CentOS servers, you might run:</p>
<p><i>Note: Having group names based on the operating system of the server is not necessary. As I will discuss, Ansible Facts can be used to gather this information; however, issuing ad hoc commands becomes more complex when trying to use Facts, and so for convenience I recommend creating a few groups based on operating system if you manage a heterogeneous environment.</i></p>
<p>This will loop over each of the servers in the group <b>centos</b> and install all of the updates. A more useful ad hoc command would be the Ansible <b>ping</b> module, which is used to verify that a server is ready to receive commands:</p>
<p>This will result in Ansible attempting to log in via SSH to all of the servers in your inventory. Truncated output for the <b>ping</b> command can be seen in Example 3.</p>
<h4>Example 3: Ansible ping command output</h4>
<p>The ability to run ad hoc commands is useful for quick tasks, but what if you want to be able to run the same tasks later, in a repeatable fashion? For that Ansible implements playbooks.</p>
<h2>Ansible playbooks for complex tasks</h2>
<p>An Ansible playbook is a YAML file that contains all the instructions that Ansible should complete during a run. For the purposes of this exercise, I will not get into more advanced topics such as Roles and Templates. If you are interested in learning more, the documentation is a great place to start.</p>
<p>In the previous section, I encouraged you to use the <b>ssh-copy-id</b> command to propagate your SSH keys; however, this article is focused on how to accomplish tasks in a consistent, repeatable manner. Example 4 demonstrates one method for ensuring, in an idempotent fashion, that an SSH key exists on the target hosts.</p>
<h4>Example 4: Ansible playbook "push_ssh_keys.yaml"</h4>
<p>In the playbook from Example 4, all of the critical sections are highlighted.</p>
<p>The <b>- hosts:</b> line indicates which host groups the playbook should evaluate. In this particular case, it is going to examine all of the hosts from our <i>Inventory</i>.</p>
<p>The <b>gather_facts:</b> line instructs Ansible to attempt to find out detailed information about each host. I will examine this in more detail later. For now, <b>gather_facts</b> is set to <b>false</b> to save time.</p>
<p>The <b>vars:</b> section, as one might imagine, is used to define variables that can be used throughout the playbook. In such a short playbook as the one in Example 4, it is more a convenience rather than a necessity.</p>
<p>Finally the main section is indicated by <b>tasks:</b>. This is where most of the instructions are located. Each task should have a <b>- name:</b>. This is what is displayed as Ansible is carrying out a <b>run</b>, or playbook execution.</p>
<p>The <b>authorized_key:</b> heading is the name of the Ansible Module that the playbook is using. Information about Ansible Modules can be accessed on the command line via <b>ansible-doc -a</b>; however it may be more convenient to view the documentation in a web browser. The authorized_key module has plenty of great examples to get started with. To run the playbook in Example 4, simply use the <b>ansible-playbook</b> command:</p>
<p>If this is the first time adding an SSH key to the box, SSH will prompt you for a password for the root user.</p>
<p>Now that your servers have SSH keys propagated its time to do something a little more interesting.</p>
<h2>Ansible and gathering facts</h2>
<p>Ansible has the ability to gather all kinds of facts about the target system. This can consume a significant amount of time if you have a large number of hosts. In my experience, it can take 1 to 2 seconds per host, and possibly longer; however, there are benefits to fact gathering. Consider the following playbook used for turning off the ability for users to log in with a password as the root user:</p>
<h4>Example 5: Lock down root SSH account</h4>
<p>In Example 5 the <b>sshd_config</b> file is modified with the lineinfile module to ensure that the line <b>PermitRootLogin without-password</b> is present in the file. Once the line exists, special action sequences called <b>handlers</b> are notified. Notice the line <b>when: ansible_distribution ==</b>. This conditional only executes if a distribution match is found. In this case Red Hat-based distributions name their SSH service different than Debian-based, which is the purpose for the conditional statement. Although there are other ways to achieve this same effect, the example helps demonstrate Ansible facts. If you want to see all of the facts that Ansible gathers by default, you can run the <b>setup</b> module on your localhost:</p>
<p>Any fact that is discovered by Ansible can be used to base decisions upon much the same way the <b>vars:</b> section that was shown in Example 4 is used. The difference is Ansible facts are considered to be <b>built in</b> variables, and thus do not have to be defined by the administrator.</p>
<h2>Next steps</h2>
<p>Now you have the tools to start investigating Ansible and creating your own playbooks. Ansible is a tool that has so much depth, complexity, and flexibility that it would be impossible to cover everything in one article. This article should be enough to pique your interest and inspire you to explore the possibilities Ansible provides. In my next article, I will discuss the <b>Copy</b>, <b>systemd</b>, <b>service</b>, <b>apt</b>, <b>yum</b>, <b>virt</b>, and <b>user</b> modules. We can combine these to create update and installation playbooks, and to create a basic Git server to store all of the playbooks that may get created.</p>
<h2>Ansible deployment automation</h2>

<h3>Ansible deployment automation</h3>
<p>[youtube]</p>
Ansible deployment automation <a href="remmont.com">News headlines</a> Ansible deployment automation
<h4>Ansible deployment automation</h4>
Sharpen your sysadmin and Linux skills and learn how to set up tooling to simplify administering multiple machines.
<h5>Ansible deployment automation</h5>
Ansible deployment automation <a href="remmont.com">Ansible deployment automation</a> Ansible deployment automation
SOURCE: <h6>Ansible deployment automation</h6> <a href="dev-ops.engineer/">Ansible deployment automation</a> Ansible deployment automation
#tags#[replace: -,-Ansible deployment automation] Ansible deployment automation#tags#

Eduard Kabrinskiy
breaking news
  • RENTAgole
  • RENTAgole аватар
  • Немає на сайті
  • Елітний учасник
  • Дописи: 317
  • Репутація: 0
Адміністратор заборонив доступ на запис.
Час відкриття сторінки: 0.054 секунд