138 lines
5.7 KiB
YAML
138 lines
5.7 KiB
YAML
uuid:
|
|
- value: d06d1e0c-2e71-4928-922f-c587f712a8e9
|
|
langcode:
|
|
- value: en
|
|
type:
|
|
- target_id: daily_email
|
|
target_type: node_type
|
|
target_uuid: 8bde1f2f-eef9-4f2d-ae9c-96921f8193d7
|
|
revision_timestamp:
|
|
- value: '2025-05-11T09:00:55+00:00'
|
|
revision_uid:
|
|
- target_type: user
|
|
target_uuid: b8966985-d4b2-42a7-a319-2e94ccfbb849
|
|
revision_log: { }
|
|
status:
|
|
- value: true
|
|
uid:
|
|
- target_type: user
|
|
target_uuid: b8966985-d4b2-42a7-a319-2e94ccfbb849
|
|
title:
|
|
- value: 'Creating infrastructure with Ansible'
|
|
created:
|
|
- value: '2022-09-03T00:00:00+00:00'
|
|
changed:
|
|
- value: '2025-05-11T09:00:55+00:00'
|
|
promote:
|
|
- value: false
|
|
sticky:
|
|
- value: false
|
|
default_langcode:
|
|
- value: true
|
|
revision_translation_affected:
|
|
- value: true
|
|
path:
|
|
- alias: /dailys/2022/09/03/creating-infrastructure-with-ansible
|
|
langcode: en
|
|
body:
|
|
- value: |
|
|
<p>Let's start at the beginning.</p>
|
|
|
|
<p>If we want to automate our infrastructure then we first need to create it. This could be done manually or we can automate it.</p>
|
|
|
|
<p>Popular tools for this include Terraform and Pulumi, but Ansible also includes modules to interface with hosting providers such as Amazon Web Services, Microsoft Azure, DigitalOcean, and Linode.</p>
|
|
|
|
<p>By using one of these tools, you can programatically provision a new, blank server that is ready for you to be configered.</p>
|
|
|
|
<p>For example, to <a href="https://docs.ansible.com/ansible/latest/collections/community/digitalocean/digital_ocean_module.htm">create a DigitalOcean droplet</a>:</p>
|
|
|
|
<pre><code class="language-yaml">--- - community.digitalocean.digital_ocean_droplet:
|
|
image: ubuntu-20-04-x64
|
|
name: mydroplet
|
|
oauth_token: "..."
|
|
region: sfo3
|
|
size: s-1vcpu-1gb
|
|
ssh_keys: [ .... ]
|
|
state: present
|
|
wait_timeout: 500
|
|
register: my_droplet
|
|
</code></pre>
|
|
|
|
<p>Running this playbook will create a new Droplet with the specified name, size, and operating system, and within the specified region.</p>
|
|
|
|
<p>If you needed to create a separate database server or another server for a new environment, then the file can be updated and re-run.</p>
|
|
|
|
<p><a href="https://docs.ansible.com/ansible/latest/collections/amazon/aws/ec2_instance_module.html#ansible-collections-amazon-aws-ec2-instance-module">Creating an Amazon EC2 instance</a> looks very similar:</p>
|
|
|
|
<pre><code class="language-yaml">--- - amazon.aws.ec2_instance:
|
|
image_id: ami-123456
|
|
instance_type: c5.large
|
|
key_name: "prod-ssh-key"
|
|
name: "public-compute-instance"
|
|
network:
|
|
assign_public_ip: true
|
|
security_group: default
|
|
vpc_subnet_id: subnet-5ca1ab1e
|
|
</code></pre>
|
|
|
|
<p>This doesn't apply just to servers - you can also use Ansible to create security groups and S3 buckets, manage SSH keys, firewalls, and load balancers.</p>
|
|
|
|
<p>Once we have our infrastructure in place, we can start using Ansible to set and manage its configuration, which we'll do in tomorrow's email.</p>
|
|
|
|
<hr />
|
|
|
|
<p>Want to learn more about how I use Ansible? <a href="/ansible-course">Register for my upcoming free email course</a>.</p>
|
|
|
|
|
|
format: full_html
|
|
processed: |
|
|
<p>Let's start at the beginning.</p>
|
|
|
|
<p>If we want to automate our infrastructure then we first need to create it. This could be done manually or we can automate it.</p>
|
|
|
|
<p>Popular tools for this include Terraform and Pulumi, but Ansible also includes modules to interface with hosting providers such as Amazon Web Services, Microsoft Azure, DigitalOcean, and Linode.</p>
|
|
|
|
<p>By using one of these tools, you can programatically provision a new, blank server that is ready for you to be configered.</p>
|
|
|
|
<p>For example, to <a href="https://docs.ansible.com/ansible/latest/collections/community/digitalocean/digital_ocean_module.htm">create a DigitalOcean droplet</a>:</p>
|
|
|
|
<pre><code class="language-yaml">--- - community.digitalocean.digital_ocean_droplet:
|
|
image: ubuntu-20-04-x64
|
|
name: mydroplet
|
|
oauth_token: "..."
|
|
region: sfo3
|
|
size: s-1vcpu-1gb
|
|
ssh_keys: [ .... ]
|
|
state: present
|
|
wait_timeout: 500
|
|
register: my_droplet
|
|
</code></pre>
|
|
|
|
<p>Running this playbook will create a new Droplet with the specified name, size, and operating system, and within the specified region.</p>
|
|
|
|
<p>If you needed to create a separate database server or another server for a new environment, then the file can be updated and re-run.</p>
|
|
|
|
<p><a href="https://docs.ansible.com/ansible/latest/collections/amazon/aws/ec2_instance_module.html#ansible-collections-amazon-aws-ec2-instance-module">Creating an Amazon EC2 instance</a> looks very similar:</p>
|
|
|
|
<pre><code class="language-yaml">--- - amazon.aws.ec2_instance:
|
|
image_id: ami-123456
|
|
instance_type: c5.large
|
|
key_name: "prod-ssh-key"
|
|
name: "public-compute-instance"
|
|
network:
|
|
assign_public_ip: true
|
|
security_group: default
|
|
vpc_subnet_id: subnet-5ca1ab1e
|
|
</code></pre>
|
|
|
|
<p>This doesn't apply just to servers - you can also use Ansible to create security groups and S3 buckets, manage SSH keys, firewalls, and load balancers.</p>
|
|
|
|
<p>Once we have our infrastructure in place, we can start using Ansible to set and manage its configuration, which we'll do in tomorrow's email.</p>
|
|
|
|
<hr>
|
|
|
|
<p>Want to learn more about how I use Ansible? <a href="http://default/ansible-course">Register for my upcoming free email course</a>.</p>
|
|
|
|
|
|
summary: null
|
|
field_daily_email_cta: { }
|