Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ansible idempotency #404

Merged
merged 3 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"AWSCLIV",
"azurerm",
"Bento",
"Billings-Alston",
"blaa",
"boto",
"Brolliar",
Expand Down Expand Up @@ -62,6 +63,7 @@
"liatr",
"Liatrians",
"Liatrio",
"Mikayla",
"msdemo",
"mumoshu",
"mydeployment",
Expand Down
31 changes: 29 additions & 2 deletions docs/7-infrastructure-configuration-management/7.2-ansible.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ docs/7-infrastructure-configuration-management/7.2-ansible.md:
- Ansible
- Vagrant
- GitHub self-hosted runner
-
name: Idempotency
description: Provision a virtual machine and install a Github self-hosted runner using Ansible as a provisioner in Vagrant while maintaining idempotency.
estMinutes: 300
technologies:
- Ansible
- Vagrant
- Github self-hosted runner
-
name: Ansible and AWS EC2
description: Provision an AWS EC2 instance and install a GitHub self-hosted runner using Ansible.
Expand Down Expand Up @@ -179,14 +187,33 @@ For this exercise you will use Ansible as a provisioner in Vagrant to setup a ne
3. Follow [this](https://docs.ansible.com/ansible/latest/scenario_guides/guide_vagrant.html) guide to use the playbook as a Vagrant provisioner.
4. Run a GitHub workflow using the newly provisioned GitHub self-hosted runner.

## 2. Exercise - Ansible and AWS EC2
## 2. Exercise - Ansible and Idempotency

Depending on your implementation of the previous exercise, your playbook may or may not be considered **idempotent**.

Idempotency is a concept in both mathematics and computer science that indicates a given mathematical operation or function can be applied multiple times and yield the same result. An example of this in mathematics could be `x + 0`. No matter how many times you add `0` to `x`, the result will always be `x`.

More relevantly, in order for an Ansible playbook to be idempotent, it must be able to be run repeatedly and yield the same result each time. Generally, most Ansible modules are idempotent, only making changes when a system is not in line with the specified desired state, but there are some that aren't, notably the command and shell modules.

1. Recreate exercise 1 with idempotency in mind.
>Some potentially helpful resources for making your playbook idempotent:
>
>[Ansible handlers](https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_handlers.html#handlers)
>
>[Self-Hosted runners as a service](https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_handlers.html#handlers)

2. Ensure you can successfully rerun your playbook using `vagrant provision`, and that doing so results in the same configuration as running it only once.

For the following exercises, try to challenge yourself by making each of your following playbooks idempotent.

## 3. Exercise - Ansible and AWS EC2

Provisioning local virtual machines is good practice but now let move onto something more practical. In this exercise you will provision and AWS EC2 instance and install a GitHub self-hosted runner.

1. Follow [this](https://docs.ansible.com/ansible/latest/scenario_guides/guide_aws.html) guide to adapt your playbook to provision an EC2 instance and then install a GitHub self-hosted runner.
2. Run a GitHub workflow using the newly provisioned GitHub self-hosted runner.

## 3. Exercise - Terraform and Ansible
## 4. Exercise - Terraform and Ansible

Ansible can do a lot of different things but it is not always the best tool for every use case. It is common to combine different tools to use the advantages of each.

Expand Down
7 changes: 7 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,13 @@ docs/7-infrastructure-configuration-management/7.2-ansible.md:
- Ansible
- Vagrant
- GitHub self-hosted runner
- name: Idempotency
description: Provision a virtual machine and install a Github self-hosted runner using Ansible as a provisioner in Vagrant while maintaining idempotency.
estMinutes: 300
technologies:
- Ansible
- Vagrant
- Github self-hosted runner
- name: Ansible and AWS EC2
description: >-
Provision an AWS EC2 instance and install a GitHub self-hosted runner
Expand Down
1 change: 1 addition & 0 deletions docs/contributors.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@
- [Ryan McGuire](https://github.com/ramcguire)
- [Joshua Burns](https://github.com/jburns24)
- [Travis Kroll](https://github.com/tjvkroll)
- [Mikayla Billings-Alston](https://github.com/mcbillings)

[back](/)
Loading