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

feat(apple-silicon): add tutorial ansible and terraform #3823

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
da54342
feat(apple-silicon): add tutorial ansible and terraform
Laure-di Oct 10, 2024
6e55a8e
add some informations
Laure-di Feb 20, 2025
942b17c
fix ansible and add conclusion
Laure-di Feb 25, 2025
c5c89f5
improve title
Laure-di Feb 26, 2025
daeda84
Update tutorials/how-to-setup-applesilicon-server-with-terraform-ansi…
Laure-di Feb 27, 2025
10f14b8
Update tutorials/how-to-setup-applesilicon-server-with-terraform-ansi…
Laure-di Feb 27, 2025
f95f5ac
Update tutorials/how-to-setup-applesilicon-server-with-terraform-ansi…
Laure-di Feb 27, 2025
e7e06c5
Update tutorials/how-to-setup-applesilicon-server-with-terraform-ansi…
Laure-di Feb 27, 2025
3de7474
Update tutorials/how-to-setup-applesilicon-server-with-terraform-ansi…
Laure-di Feb 27, 2025
e1e1e70
Update tutorials/how-to-setup-applesilicon-server-with-terraform-ansi…
Laure-di Feb 27, 2025
bf46921
Update tutorials/how-to-setup-applesilicon-server-with-terraform-ansi…
Laure-di Feb 27, 2025
69e20b7
Update tutorials/how-to-setup-applesilicon-server-with-terraform-ansi…
Laure-di Feb 27, 2025
15d131b
Update tutorials/how-to-setup-applesilicon-server-with-terraform-ansi…
Laure-di Feb 27, 2025
f391702
Update tutorials/how-to-setup-applesilicon-server-with-terraform-ansi…
Laure-di Feb 27, 2025
e2cf6a3
Update tutorials/how-to-setup-applesilicon-server-with-terraform-ansi…
Laure-di Feb 27, 2025
77dd5c8
Update tutorials/how-to-setup-applesilicon-server-with-terraform-ansi…
Laure-di Feb 27, 2025
99201b0
Update tutorials/how-to-setup-applesilicon-server-with-terraform-ansi…
Laure-di Feb 27, 2025
ab8bfd5
Update tutorials/how-to-setup-applesilicon-server-with-terraform-ansi…
Laure-di Feb 27, 2025
5014db3
Update tutorials/how-to-setup-applesilicon-server-with-terraform-ansi…
Laure-di Feb 27, 2025
18e463b
Update tutorials/how-to-setup-applesilicon-server-with-terraform-ansi…
Laure-di Feb 27, 2025
09f3338
Update tutorials/how-to-setup-applesilicon-server-with-terraform-ansi…
Laure-di Feb 27, 2025
c8fb09b
Update tutorials/how-to-setup-applesilicon-server-with-terraform-ansi…
Laure-di Feb 27, 2025
3680e53
Update tutorials/how-to-setup-applesilicon-server-with-terraform-ansi…
Laure-di Feb 27, 2025
f529dd2
Apply suggestions from code review
Laure-di Feb 27, 2025
2995768
split tutorial
Laure-di Mar 11, 2025
0f533c7
feat(apple-silicon): ansible tutorial
Laure-di Mar 12, 2025
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
229 changes: 229 additions & 0 deletions tutorials/how-to-setup-applesilicon-server-with-ansible/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,229 @@
---
meta:
title: Automating Apple Silicon Server Creation: A Step-by-Step Guide Using Terraform vs. Ansible
description: Explore Two Powerful Approaches to Automating Apple Silicon Server Deployment with Terraform and Ansible
content:
h1: Automating Apple Silicon Server Creation: A Step-by-Step Guide Using Terraform vs. Ansible
description: Explore Two Powerful Approaches to Automating Apple Silicon Server Deployment with Terraform and Ansible
categories:
- apple-silicon
- terraform
- ansible
tags: apple-silicon terraform ansible
---

In this tutorial, we will guide you through automating the setup and management of Apple Silicon servers using two powerful tools: [Terraform](https://www.terraform.io/) and [Ansible](https://www.ansible.com/). By leveraging these tools, you can streamline infrastructure management, reduce manual configuration, and ensure consistent environments.

<Macro id="requirements" />

- A Scaleway account logged into the [console](https://console.scaleway.com)
- [Owner](/identity-and-access-management/iam/concepts/#owner) status or [IAM permissions](/identity-and-access-management/iam/concepts/#permission) allowing you to perform actions in the intended Organization
- A valid [API key](/identity-and-access-management/iam/how-to/create-api-keys/)

## Understanding the tools

### HashiCorp Terraform
[Terraform](https://www.terraform.io/) is an open-source Infrastructure as Code (IaC) tool that allows you to define and manage infrastructure using declarative configuration files. Terraform enables you to create reproducible and scalable environments while automating the deployment of resources.

### Ansible
[Ansible](https://www.ansible.com/) is an automation tool that simplifies configuration management, application deployment, and task automation. By using playbooks, Ansible helps automate and streamline processes, ensuring consistency and efficiency in managing complex infrastructure.

## How to create an Apple silicon server

### Using Terraform

1. Download and install [Terraform](https://developer.hashicorp.com/terraform/install).

2. Create a Directory: First, create a directory for your Terraform project. Open your terminal and run:

```shell
mkdir apple_silicon_server_terraform
cd apple_silicon_server_terraform
```

3. Create a Terraform configuration file: Inside this directory, create a file named `resources.tf`:

```shell
touch resources.tf
```

4. Define the required providers: Open the `resources.tf` file and add the following configuration to define the Scaleway provider and set the required Terraform version:

```shell
terraform {
required_providers {
scaleway = {
source = "scaleway/scaleway"
}
}
required_version = ">=0.13"
}

```

5. Define the Apple silicon server: Add the following code to define your Apple silicon server (M2-M type) in the same `resources.tf` file:

```terraform
#resources.tf
resource "scaleway_apple_silicon_server" "server" {
name = "MyAwesomeServer"
type = "M2-M"
zone = "fr-par-1"
}
```

6. Apply the configuration: To apply this configuration, run the following commands in your terminal:

```shell
#Initialize Terraform
terraform init
#Plan the deployment
terraform plan
#Create the server
terraform apply
```

When prompted, type **yes** to confirm the creation of the resources.

7. Enable Virtual Private Cloud (VPC) and a Private Network: To enhance the network setup, you can update the configuration to enable VPC option and attach a Private Network to your Apple silicon server. Update your `resources.tf` file with the following:

```terraform
#resources.tf
resource "scaleway_vpc" "vpc01" {
name = "MyAwesomeVPC"
}

resource "scaleway_vpc_private_network" "pn01" {
name = "MyAwesomePN"
vpc_id = scaleway_vpc.vpc01.id
}

resource "scaleway_apple_silicon_server" "server" {
name = "MyAwesomeServer"
type = "M2-M"
zone = "fr-par-1"
enable_vpc = true
private_network {
id = scaleway_vpc_private_network.pn01.id
}
}
```
8. Apply the configuration update: Run the following command to apply the changes and update the server configuration

```shell
terraform apply
```

This will apply the new settings, ensuring that the server is launched within the specified VPC and connected to the Private Network.

### Using Ansible

1. Install Ansible: If you don't have Ansible installed on your system, you can easily install it using pip, the Python package manager. Run the following command:

```shell
pip install ansible
```

2. Install Scaleway Ansible Collection: Scaleway provides an official Ansible collection that enables you to interact with Scaleway resources, such as creating servers. Install this collection using the `ansible-galaxy` command:

```shell
ansible-galaxy collection install scaleway.scaleway
```

3. Create a directory: Now that you have Ansible and the Scaleway collection installed, create a directory for your Ansible project. This will help you keep everything organized.

Run the following commands to create and navigate into the project directory:

```shell
mkdir apple_silicon_server_ansible
cd apple_silicon_server_ansible
```

4. Create a playbook: In Ansible, a playbook is a YAML file that defines the tasks to automate. Create a new file for your playbook named `create_applesilicon_server.yml`:

```shell
touch create_applesilicon_server.yml
```

5. Define the playbook content: Open the `create_applesilicon_server.yml` file in your preferred text editor. Add the following content to define the task of provisioning an Apple silicon server:

```ansible
---
- name: Create Apple silicon server on Scaleway
hosts: localhost
gather_facts: no
tasks:
- name: Create an Apple silicon server
scaleway.scaleway.scaleway_applesilicon_server:
access_key: "{{ scw_access_key }}"
secret_key: "{{ scw_secret_key }}"
state: present
type_: "M2-M"
name: "my-applesilicon-server"
zone: "fr-par-1"
project_id: "{{scw_project_id}}"
vpc_enabled: "false"
register: applesilicon_server
```

6. Set up your Scaleway credentials: Replace the placeholders {{ scw_access_key }}, {{ scw_secret_key }}, and {{ scw_project_id }} with your actual credentials. It is a good practice to store these values in environment variables or an Ansible vault for added security. Alternatively, you can use a `.env` file or an external credentials file.

7. Run the playbook: Now that your playbook is ready and your credentials are set, you can run the playbook to create your Apple silicon server.

Execute the following command:

```shell
ansible-playbook create_applesilicon_server.yml
```

Ansible will authenticate using your credentials, and the playbook will automatically provision the Apple Silicon server based on the defined parameters.

8. Check the output: The playbook will output the details of the created server, including its ID, IP address, status, and other relevant information.

With these steps, you have successfully automated the creation of an Apple silicon server on Scaleway using Ansible. You can now extend the playbook to configure your server or automate additional tasks as needed.

## How to read server info using Terraform

To read server information after creation, you can use the terraform output command, assuming you have defined output variables in your `resources.tf`. For example:

```terraform
#resources.tf
output "server_ip" {
value = scaleway_apple_silicon_server.server.ip
}
```

After applying the configuration, run:

```shell
terraform output server_ip
```

## Conclusion

In this tutorial, we have explored how to automate the creation and management of Apple silicon servers on Scaleway using two powerful tools: Terraform and Ansible. While both tools offer significant automation benefits, they each operate in distinct ways, which makes them suitable for different use cases.

### Keys differences

#### Terraform's state management

Terraform maintains a state file that tracks the current status of your infrastructure. This state file acts as the source of truth for the resources created and managed by Terraform, providing you with visibility and control over any changes. This allows Terraform to efficiently handle infrastructure updates and deletions while ensuring consistency across environments.

#### Ansible’s idempotency

Ansible, on the other hand, does not have a built-in state management system. Instead, it focuses on idempotency, meaning that Ansible playbooks can be executed multiple times without causing unwanted side effects. Each run checks whether the desired state is already achieved, and if not, it makes the necessary changes. However, Ansible does not retain a record of resource states, so it might be less efficient for large-scale infrastructure management compared to Terraform.

### Which to choose?

Terraform is an excellent choice for infrastructure provisioning where you need to keep track of your resources and manage dependencies between them. It is especially useful for handling lifecycle management (creation, modification, and deletion) of your infrastructure.

Ansible shines in configuration management, automation, and orchestrating tasks across your infrastructure. It’s ideal for deploying applications, configuring services, and ensuring your systems are in the desired state after provisioning.

You can also combine both tools for optimal results! Use Terraform for provisioning the infrastructure and Ansible for configuring the servers and deploying applications on top of it. This hybrid approach allows you to leverage the best of both worlds.

By following this guide, you now have a solid understanding of how to automate the creation and management of Apple silicon servers on Scaleway, whether you're using Terraform or Ansible. Both tools can greatly streamline your workflow, reduce manual effort, and help you maintain consistency across your infrastructure.

For more advanced topics, consider exploring Terraform’s state management and Ansible’s playbook design to enhance your automation skills further. Happy automating!



Loading