Skip to content

Commit 4cc374d

Browse files
committed
split tutorial
1 parent 674bb60 commit 4cc374d

File tree

2 files changed

+40
-78
lines changed
  • tutorials
    • how-to-setup-applesilicon-server-with-ansible
    • how-to-setup-applesilicon-server-with-terraform

2 files changed

+40
-78
lines changed

tutorials/how-to-setup-applesilicon-server-with-ansible/index.mdx

Whitespace-only changes.

tutorials/how-to-setup-applesilicon-server-with-terraform-ansible/index.mdx renamed to tutorials/how-to-setup-applesilicon-server-with-terraform/index.mdx

Lines changed: 40 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,35 @@
11
---
22
meta:
3-
title: Automating Apple Silicon Server Creation: A Step-by-Step Guide Using Terraform vs. Ansible
4-
description: Explore Two Powerful Approaches to Automating Apple Silicon Server Deployment with Terraform and Ansible
3+
title: Automating Apple Silicon Server Creation: A Step-by-Step Guide Using Terraform
4+
description: Explore Two Powerful Approaches to Automating Apple Silicon Server Deployment with Terraform
55
content:
6-
h1: Automating Apple Silicon Server Creation: A Step-by-Step Guide Using Terraform vs. Ansible
7-
description: Explore Two Powerful Approaches to Automating Apple Silicon Server Deployment with Terraform and Ansible
6+
h1: Automating Apple Silicon Server Creation: A Step-by-Step Guide Using Terraform
7+
description: Explore Two Powerful Approaches to Automating Apple Silicon Server Deployment with Terraform
88
categories:
99
- apple-silicon
1010
- terraform
11-
- ansible
12-
tags: apple-silicon terraform ansible
11+
tags: apple-silicon ansible
1312
---
1413

15-
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.
14+
In this tutorial, we will guide you through automating the setup and management of Apple Silicon servers using a powerful tool: [Terraform](https://www.terraform.io/). By leveraging these tools, you can streamline infrastructure management, reduce manual configuration, and ensure consistent environments.
1615

1716
<Macro id="requirements" />
1817

1918
- A Scaleway account logged into the [console](https://console.scaleway.com)
2019
- [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
2120
- A valid [API key](/identity-and-access-management/iam/how-to/create-api-keys/)
2221

23-
## Understanding the tools
22+
## Understanding the tool
23+
24+
### HashiCorp Terraform & OpenTofu
2425

25-
### HashiCorp Terraform
2626
[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.
2727

28-
### Ansible
29-
[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.
28+
A fork of this project, [OpenTofu](https://opentofu.org/), is an open-source alternative that aims to be fully compatible with Terraform, while offering an independent, community-driven approach. OpenTofu provides the same functionality as Terraform, allowing users to define infrastructure with HCL (HashiCorp Configuration Language) and automate resource management. Its goal is to offer a transparent and open solution, with an emphasis on inclusivity and community contributions.
3029

31-
## How to create an Apple silicon server
30+
Both Terraform and OpenTofu offer the same core functionality for provisioning and managing infrastructure. If you are familiar with Terraform, you can easily switch to OpenTofu without needing to change your configuration files.
3231

33-
### Using Terraform
32+
## How to create an Apple silicon server
3433

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

@@ -116,88 +115,51 @@ terraform apply
116115

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

119-
### Using Ansible
120-
121-
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:
122-
123-
```shell
124-
pip install ansible
125-
```
118+
## How to read server info using Terraform
126119

127-
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:
120+
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:
128121

129-
```shell
130-
ansible-galaxy collection install scaleway.scaleway
122+
```terraform
123+
#resources.tf
124+
output "server_ip" {
125+
value = scaleway_apple_silicon_server.server.ip
126+
}
131127
```
132128

133-
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.
134-
135-
Run the following commands to create and navigate into the project directory:
136-
137-
```shell
138-
mkdir apple_silicon_server_ansible
139-
cd apple_silicon_server_ansible
140-
```
141-
142-
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`:
129+
After applying the configuration, run:
143130

144131
```shell
145-
touch create_applesilicon_server.yml
146-
```
147-
148-
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:
149-
150-
```ansible
151-
---
152-
- name: Create Apple silicon server on Scaleway
153-
hosts: localhost
154-
gather_facts: no
155-
tasks:
156-
- name: Create an Apple silicon server
157-
scaleway.scaleway.scaleway_applesilicon_server:
158-
access_key: "{{ scw_access_key }}"
159-
secret_key: "{{ scw_secret_key }}"
160-
state: present
161-
type_: "M2-M"
162-
name: "my-applesilicon-server"
163-
zone: "fr-par-1"
164-
project_id: "{{scw_project_id}}"
165-
vpc_enabled: "false"
166-
register: applesilicon_server
132+
terraform output server_ip
167133
```
168134

169-
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.
170-
171-
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.
135+
## Delve into Terraform with local-exec, remote-exec and null_resource
172136

173-
Execute the following command:
174-
175-
```shell
176-
ansible-playbook create_applesilicon_server.yml
177-
```
178-
179-
Ansible will authenticate using your credentials, and the playbook will automatically provision the Apple Silicon server based on the defined parameters.
137+
In Terraform, provisioners like local-exec, remote-exec, and null_resource can be used to automate the execution of scripts and manage resource configuration. Here’s how you can use them:
180138

181-
8. Check the output: The playbook will output the details of the created server, including its ID, IP address, status, and other relevant information.
139+
[null_resource](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) is a special Terraform resource that doesn’t manage infrastructure directly. It serves as a placeholder for running provisioners and triggers actions without creating any infrastructure.
140+
[remote-exec](https://developer.hashicorp.com/terraform/language/resources/provisioners/remote-exec) provisioner allows you to execute scripts on remote resources after they’ve been created. It is useful for configuring remote servers or performing post-creation actions.
141+
[local-exec](https://developer.hashicorp.com/terraform/language/resources/provisioners/local-exec) provisioner enables you to run scripts on your local machine. This is helpful when you need to execute commands in your local environment based on the resources created by Terraform.
182142

183-
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.
143+
1. We want to connect to our server, so we are going to retrieve all the connection information
184144

185-
## How to read server info using Terraform
186-
187-
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:
145+
``` terraform
146+
#resource.tf
188147
189-
```terraform
190-
#resources.tf
191-
output "server_ip" {
192-
value = scaleway_apple_silicon_server.server.ip
148+
resource "null_resource" "store_ssh_key" {
149+
provisioner "local-exec" {
150+
command = <<-EOT
151+
mkdir -p ~/.ssh
152+
echo "${file("~/.ssh/id_rsa")}" > ~/.ssh/id_rsa
153+
chmod 600 ~/.ssh/id_rsa
154+
echo 'SSH key stored at ~/.ssh/id_rsa'
155+
EOT
156+
}
193157
}
194158
```
195159

196-
After applying the configuration, run:
160+
2. To install dependancies which can be usefull
161+
197162

198-
```shell
199-
terraform output server_ip
200-
```
201163

202164
## Conclusion
203165

0 commit comments

Comments
 (0)