WIP3
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
<section data-state="title alt" id="RedIntro-AnsibleRoles-Intro">
|
||||
<h1>USING ROLES:</h1>
|
||||
<img src="<?=$workshop_image?>" style="background-color: transparent; border: none;" height="250">
|
||||
<font color="white">
|
||||
<li>Improves readability and maintainability of complex plays</li>
|
||||
<li>Eases sharing, reuse and standardization of automation processes</li>
|
||||
<li>Enables Ansible content to exist independently of playbooks, projects -- even organizations</li>
|
||||
<li>Provides functional conveniences such as file path resolution and default values</li>
|
||||
</font>
|
||||
<aside class="notes">
|
||||
<p>Let's talk about what they are, how they work, and some of the ways we can use them.</p>
|
||||
</aside>
|
||||
</section>
|
||||
@@ -0,0 +1,363 @@
|
||||
<section id="GranularRoles-RolesAnatomy">
|
||||
<center><h2>ROLES ANATOMY</h2></center>
|
||||
|
||||
<div class="terminal space shadow">
|
||||
<div class="top">
|
||||
<div class="title">Ansible Terminal</div>
|
||||
</div>
|
||||
<pre class="bodymw">
|
||||
<font color="gray"><?=$terminal_prompt?></font> tree example_role/
|
||||
|
||||
example_role/
|
||||
├── defaults
|
||||
│ └── main.yml
|
||||
├── files
|
||||
├── handlers
|
||||
│ └── main.yml
|
||||
├── meta
|
||||
│ └── main.yml
|
||||
├── README.md
|
||||
├── tasks
|
||||
│ └── main.yml
|
||||
├── templates
|
||||
├── tests
|
||||
│ ├── inventory
|
||||
│ └── test.yml
|
||||
└── vars
|
||||
└── main.yml
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
<aside class="notes">
|
||||
<p>Let's take a moment to look at the anatomy of a role and discuss the various directories and files we see in a newly created role.</p>
|
||||
</aside>
|
||||
</section>
|
||||
|
||||
|
||||
<section id="GranularRoles-00-MainDirectory">
|
||||
<center><h2>MAIN ROLE DIRECTORY</h2></center>
|
||||
|
||||
<div class="terminal space shadow">
|
||||
<div class="top">
|
||||
<div class="title">Ansible Terminal</div>
|
||||
</div>
|
||||
<pre class="bodymw">
|
||||
<font color="gray"><?=$terminal_prompt?></font> tree example_role/
|
||||
|
||||
<mark>example_role/</mark>
|
||||
├── defaults
|
||||
│ └── main.yml
|
||||
├── files
|
||||
├── handlers
|
||||
│ └── main.yml
|
||||
├── meta
|
||||
│ └── main.yml
|
||||
├── README.md
|
||||
├── tasks
|
||||
│ └── main.yml
|
||||
├── templates
|
||||
├── tests
|
||||
│ ├── inventory
|
||||
│ └── test.yml
|
||||
└── vars
|
||||
└── main.yml
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
<aside class="notes">
|
||||
<p>The role, by default, creates a directory with its own name, then subdirectories below that. When you call this role within an Ansible playbook, you use this directory name as the name of the role to include.</p>
|
||||
</aside>
|
||||
</section>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<section id="GranularRoles-01-DefaultsDirectory">
|
||||
<center><h2>DEFAULTS AND VARIABLES</h2></center>
|
||||
|
||||
<div class="terminal space shadow">
|
||||
<div class="top">
|
||||
<div class="title">Ansible Terminal</div>
|
||||
</div>
|
||||
<pre class="bodymw">
|
||||
<font color="gray"><?=$terminal_prompt?></font> tree example_role/
|
||||
|
||||
example_role/
|
||||
<mark>├── defaults
|
||||
│ └── main.yml</mark>
|
||||
├── files
|
||||
├── handlers
|
||||
│ └── main.yml
|
||||
├── meta
|
||||
│ └── main.yml
|
||||
├── README.md
|
||||
├── tasks
|
||||
│ └── main.yml
|
||||
├── templates
|
||||
├── tests
|
||||
│ ├── inventory
|
||||
│ └── test.yml
|
||||
<mark>└── vars
|
||||
└── main.yml</mark>
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
<aside class="notes">
|
||||
<p>The VARIABLES and DEFAULTS in a role are essentially the same type of information. But remember in the variable order of precedence, once is the highest and one is the lowest.</p>
|
||||
<p>For example, any variables we put in the DEFAULTS main.yml file will be overwritten anywhere else they are defined. This is because DEFAULTS is the lowest order of precedence for variables. We put in default values here, knowing they can and possibly will be overwritten at some point.</p>
|
||||
<p>On the other hand, the VARS are the highest level of precedence, aside from extra variables fed into the role at run-time. These can only be overridden by passing variables at the command line or Tower "extra vars" or, by re-declaring them with different values in the playbook itself.</p>
|
||||
<p>A real-world example might be a role with predefined defaults but a user who wants to overwrite their stored version of the role by adding new variables into vars/main.yml. These new variables will override the role defaults without having to delete or edit that file.</p>
|
||||
</aside>
|
||||
</section>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<section id="GranularRoles-02-FilesDirectory">
|
||||
<center><h2>FILES DIRECTORY</h2></center>
|
||||
|
||||
<div class="terminal space shadow">
|
||||
<div class="top">
|
||||
<div class="title">Ansible Terminal</div>
|
||||
</div>
|
||||
<pre class="bodymw">
|
||||
<font color="gray"><?=$terminal_prompt?></font> tree example_role/
|
||||
|
||||
example_role/
|
||||
├── defaults
|
||||
│ └── main.yml
|
||||
<mark>├── files</mark>
|
||||
├── handlers
|
||||
│ └── main.yml
|
||||
├── meta
|
||||
│ └── main.yml
|
||||
├── README.md
|
||||
├── tasks
|
||||
│ └── main.yml
|
||||
├── templates
|
||||
├── tests
|
||||
│ ├── inventory
|
||||
│ └── test.yml
|
||||
└── vars
|
||||
└── main.yml
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
<aside class="notes">
|
||||
<p>This directory commonly contains files intended to copy to a remote system or an entire directory structure to sync remotely. In the playbook, we can refer to these source files simply as the relative path files/filename (files slash filename)</p>
|
||||
</aside>
|
||||
</section>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<section id="GranularRoles-03-HandlersDirectory">
|
||||
<center><h2>HANDLERS DIRECTORY</h2></center>
|
||||
|
||||
<div class="terminal space shadow">
|
||||
<div class="top">
|
||||
<div class="title">Ansible Terminal</div>
|
||||
</div>
|
||||
<pre class="bodymw">
|
||||
<font color="gray"><?=$terminal_prompt?></font> tree example_role/
|
||||
|
||||
example_role/
|
||||
├── defaults
|
||||
│ └── main.yml
|
||||
├── files
|
||||
<mark>├── handlers
|
||||
│ └── main.yml</mark>
|
||||
├── meta
|
||||
│ └── main.yml
|
||||
├── README.md
|
||||
├── tasks
|
||||
│ └── main.yml
|
||||
├── templates
|
||||
├── tests
|
||||
│ ├── inventory
|
||||
│ └── test.yml
|
||||
└── vars
|
||||
└── main.yml
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
<aside class="notes">
|
||||
<p>Handlers run once the tasks are complete. Instead of putting handlers in-line in your playbook, we put them in this special location, to be evaluated once the tasks are complete.</p>
|
||||
</aside>
|
||||
</section>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<section id="GranularRoles-04-MetaData">
|
||||
<center><h2>METADATA AND README</h2></center>
|
||||
|
||||
<div class="terminal space shadow">
|
||||
<div class="top">
|
||||
<div class="title">Ansible Terminal</div>
|
||||
</div>
|
||||
<pre class="bodymw">
|
||||
<font color="gray"><?=$terminal_prompt?></font> tree example_role/
|
||||
|
||||
example_role/
|
||||
├── defaults
|
||||
│ └── main.yml
|
||||
├── files
|
||||
├── handlers
|
||||
│ └── main.yml
|
||||
<mark>├── meta
|
||||
│ └── main.yml
|
||||
├── README.md</mark>
|
||||
├── tasks
|
||||
│ └── main.yml
|
||||
├── templates
|
||||
├── tests
|
||||
│ ├── inventory
|
||||
│ └── test.yml
|
||||
└── vars
|
||||
└── main.yml
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
<aside class="notes">
|
||||
<p>This is mostly important for GIT communication and publishing to galaxy. The metadata is crucial for ansible galaxy to be able to search and filter on the metadata you include. The README is helpful for users who want to pull your code from a public git source. The README commonly includes examples of a playbook to run your role or specific variables that can / should be overwitten.</p>
|
||||
</aside>
|
||||
</section>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<section id="GranularRoles-05-Tasks">
|
||||
<center><h2>TASKS DIRECTORY</h2></center>
|
||||
|
||||
<div class="terminal space shadow">
|
||||
<div class="top">
|
||||
<div class="title">Ansible Terminal</div>
|
||||
</div>
|
||||
<pre class="bodymw">
|
||||
<font color="gray"><?=$terminal_prompt?></font> tree example_role/
|
||||
|
||||
example_role/
|
||||
├── defaults
|
||||
│ └── main.yml
|
||||
├── files
|
||||
├── handlers
|
||||
│ └── main.yml
|
||||
├── meta
|
||||
│ └── main.yml
|
||||
├── README.md
|
||||
<mark>├── tasks
|
||||
│ └── main.yml</mark>
|
||||
├── templates
|
||||
├── tests
|
||||
│ ├── inventory
|
||||
│ └── test.yml
|
||||
└── vars
|
||||
└── main.yml
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
<aside class="notes">
|
||||
<p>TASKS is possibly the most important location. Ansible looks inside tasks/main.yml first to determine what to do in a role. You can have all of your role's tasks in-line or your main.yml can conditionally (or statically) include additional files to separate and extend your tasks for organizational purposes.</p>
|
||||
</aside>
|
||||
</section>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<section id="GranularRoles-06-Templates">
|
||||
<center><h2>TEMPLATES DIRECTORY</h2></center>
|
||||
|
||||
<div class="terminal space shadow">
|
||||
<div class="top">
|
||||
<div class="title">Ansible Terminal</div>
|
||||
</div>
|
||||
<pre class="bodymw">
|
||||
<font color="gray"><?=$terminal_prompt?></font> tree example_role/
|
||||
|
||||
example_role/
|
||||
├── defaults
|
||||
│ └── main.yml
|
||||
├── files
|
||||
├── handlers
|
||||
│ └── main.yml
|
||||
├── meta
|
||||
│ └── main.yml
|
||||
├── README.md
|
||||
├── tasks
|
||||
│ └── main.yml
|
||||
<mark>├── templates</mark>
|
||||
├── tests
|
||||
│ ├── inventory
|
||||
│ └── test.yml
|
||||
└── vars
|
||||
└── main.yml
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
<aside class="notes">
|
||||
<p>Similar to files, this is a directory where your templates are stored. Unlike files, templates likely include a jinja2 syntax or variables inside them to make them dynamically change as they're copyied by Ansible.</p>
|
||||
</aside>
|
||||
</section>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<section id="GranularRoles-07-Tests">
|
||||
<center><h2>TESTS DIRECTORY</h2></center>
|
||||
|
||||
<div class="terminal space shadow">
|
||||
<div class="top">
|
||||
<div class="title">Ansible Terminal</div>
|
||||
</div>
|
||||
<pre class="bodymw">
|
||||
<font color="gray"><?=$terminal_prompt?></font> tree example_role/
|
||||
|
||||
example_role/
|
||||
├── defaults
|
||||
│ └── main.yml
|
||||
├── files
|
||||
├── handlers
|
||||
│ └── main.yml
|
||||
├── meta
|
||||
│ └── main.yml
|
||||
├── README.md
|
||||
├── tasks
|
||||
│ └── main.yml
|
||||
├── templates
|
||||
<mark>├── tests
|
||||
│ ├── inventory
|
||||
│ └── test.yml</mark>
|
||||
└── vars
|
||||
└── main.yml
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
<aside class="notes">
|
||||
<p>This directory is used for defining unit testing and validation of the role to confirm it ran the way you wanted it to run and that systems are responding as expected.</p>
|
||||
</aside>
|
||||
</section>
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
<section id="RoleInit">
|
||||
<center><h2>INITIALIZING A ROLE</h2>
|
||||
<p>ansible-galaxy command to init a new role:</p>
|
||||
</center>
|
||||
|
||||
<div class="terminal space shadow">
|
||||
<div class="top">
|
||||
<div class="title">Ansible Terminal</div>
|
||||
</div>
|
||||
<pre class="bodylw">
|
||||
<font color="gray"><?=$terminal_prompt?></font> ansible-galaxy init example_role
|
||||
|
||||
- example_role was created successfully
|
||||
|
||||
<font color="gray"><?=$terminal_prompt?></font>
|
||||
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
<aside class="notes">
|
||||
<p>This slide shows an example file system with a top-level playbook (site.yml) and two sample roles (common and apache) embedded in the project. Notice how the file structure under each role are similar to what we find in a play. Role deconstruct the content we'd put in a play and package it up in such a way that it is portable and easily shared and reused.</p>
|
||||
</aside>
|
||||
</section>
|
||||
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
<section id="Roles-Structure">
|
||||
<center><h2>INTRODUCTION TO ROLES</h2>
|
||||
<p>Project with Embedded Roles Example:</p>
|
||||
</center>
|
||||
|
||||
<div class="terminal space shadow">
|
||||
<div class="top">
|
||||
<div class="title">Ansible Terminal</div>
|
||||
</div>
|
||||
<pre class="bodymw">
|
||||
<font color="gray"><?=$terminal_prompt?></font> tree example_role/
|
||||
|
||||
example_role/
|
||||
├── defaults
|
||||
│ └── main.yml
|
||||
├── files
|
||||
├── handlers
|
||||
│ └── main.yml
|
||||
├── meta
|
||||
│ └── main.yml
|
||||
├── README.md
|
||||
├── tasks
|
||||
│ └── main.yml
|
||||
├── templates
|
||||
├── tests
|
||||
│ ├── inventory
|
||||
│ └── test.yml
|
||||
└── vars
|
||||
└── main.yml
|
||||
|
||||
|
||||
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
<aside class="notes">
|
||||
<p>This slide shows an example file system with a top-level playbook (site.yml) and two sample roles (common and apache) embedded in the project. Notice how the file structure under each role are similar to what we find in a play. Role deconstruct the content we'd put in a play and package it up in such a way that it is portable and easily shared and reused.</p>
|
||||
</aside>
|
||||
</section>
|
||||
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
<section id="RolesEmbeddedFiles">
|
||||
<center><h2>INTRODUCTION TO ROLES</h2>
|
||||
<p>Project with Embedded Roles Example:</p>
|
||||
</center>
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<td>
|
||||
<div class="terminal space shadow">
|
||||
<div class="top">
|
||||
<div class="title">Ansible Terminal</div>
|
||||
</div>
|
||||
<pre class="bodysw">
|
||||
<font color="silver">Some directories omitted for readability</font>
|
||||
├── site.yml
|
||||
└── roles
|
||||
├── apache_role
|
||||
│ ├── defaults
|
||||
│ │ └── main.yml
|
||||
│ ├── files
|
||||
│ │ └── index.html
|
||||
│ ├── handlers
|
||||
│ │ └── main.yml
|
||||
│ ├── tasks
|
||||
│ │ └── main.yml
|
||||
│ ├── templates
|
||||
│ │ └── http.conf.j2
|
||||
│ └── vars
|
||||
│ └── main.yml
|
||||
└── security_standards
|
||||
├── defaults
|
||||
│ └── main.yml
|
||||
├── files
|
||||
│ ├── sshd_conf
|
||||
│ └── sudoers
|
||||
├── handlers
|
||||
│ └── main.yml
|
||||
├── tasks
|
||||
│ └── main.yml
|
||||
├── templates
|
||||
│ ├── etc_issue
|
||||
│ └── etc_motd
|
||||
└── vars
|
||||
└── main.yml </pre>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<div class="terminal space shadow">
|
||||
<div class="top">
|
||||
<div class="title">Some Interesting Files To Consider</div>
|
||||
</div>
|
||||
<pre class="bodylw">
|
||||
apache_role
|
||||
<mark>tasks/main.yml</mark>
|
||||
defaults/<mark>main.yml</mark>
|
||||
files/<mark>index.html</mark>
|
||||
templates/<mark>http.conf.j2</mark>
|
||||
vars/main.yml
|
||||
|
||||
security_standards
|
||||
<mark>tasks/main.yml</mark>
|
||||
defaults/<mark>main.yml</mark>
|
||||
files/<mark>sshd_conf</mark>
|
||||
files/<mark>sudoers</mark>
|
||||
templates/<mark>etc_issue</mark>
|
||||
templates/<mark>etc_motd</mark>
|
||||
vars/main.yml
|
||||
</pre>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<aside class="notes">
|
||||
<p>This slide shows an example file system with a top-level playbook (site.yml) and two sample roles (common and apache) embedded in the project. Notice how the file structure under each role are similar to what we find in a play. Role deconstruct the content we'd put in a play and package it up in such a way that it is portable and easily shared and reused.</p>
|
||||
</aside>
|
||||
</section>
|
||||
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
<section id="PlaybookWithRoles">
|
||||
<center><h2>PLAYBOOKS WITH ROLES</h2>
|
||||
<p>See how simple it is to of a playbook with embedded roles.</p>
|
||||
</center>
|
||||
|
||||
<div class="terminal space shadow">
|
||||
<div class="top">
|
||||
<div class="title">Ansible Terminal</div>
|
||||
</div>
|
||||
<pre class="bodylw">
|
||||
<font color="silver"># site.yml</font>
|
||||
---
|
||||
- name: Apply some roles to our web servers
|
||||
hosts: web
|
||||
roles:
|
||||
- security_standards
|
||||
- apache_role
|
||||
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
|
||||
<aside class="notes">
|
||||
<p>This slide shows the site.yml playbook using the roles in our example project. Notice that it is much more concise than what we've seen.</p>
|
||||
</aside>
|
||||
</section>
|
||||
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
<section id="UsingRolesBullets">
|
||||
<h1>USING ROLES: <br/>A More Practical Playbook</h1>
|
||||
<p>Roles are a packages of closely related Ansible content that can be shared more easily than plays alone.</p>
|
||||
<ul>
|
||||
<li>Improves readability and maintainability of complex plays</li>
|
||||
<li>Eases sharing, reuse and standardization of automation processes</li>
|
||||
<li>Enables Ansible content to exist independently of playbooks, projects -- even organizations</li>
|
||||
<li>Provides functional conveniences such as file path resolution and default values</li>
|
||||
</ul>
|
||||
|
||||
<aside class="notes">
|
||||
<p>Roles are closely related Ansible content that are organized into a pre-defined directory structure, making them easier to reuse and share among groups.</p>
|
||||
</aside>
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
<section data-state="lab alt" id="<?=$labid?>-Sample01">
|
||||
<h1><?=$pretty_htmldir?> Lab Sample 01</h1>
|
||||
<img src="<?=$workshop_image?>" style="background-color: transparent; border: none;" height="250">
|
||||
<p>This is sample page #1 that discusses things about <?=$pretty_htmldir?> and is meant strictly as a lab placeholder to show dynamic content.</p>
|
||||
</section>
|
||||
<section data-state="lab alt" id="<?=$labid?>-Sample02">
|
||||
<h1><?=$pretty_htmldir?> Lab Sample 02</h1>
|
||||
<img src="<?=$workshop_image?>" style="background-color: transparent; border: none;" height="250">
|
||||
<p>This is sample page #2 that discusses things about <?=$pretty_htmldir?> and is meant strictly as a lab placeholder to show dynamic content.</p>
|
||||
</section>
|
||||
<section data-state="lab alt" id="<?=$labid?>-Sample03">
|
||||
<h1><?=$pretty_htmldir?> Lab Sample 03</h1>
|
||||
<img src="<?=$workshop_image?>" style="background-color: transparent; border: none;" height="250">
|
||||
<p>This is sample page #3 that discusses things about <?=$pretty_htmldir?> and is meant strictly as a lab placeholder to show dynamic content.</p>
|
||||
</section>
|
||||
Reference in New Issue
Block a user