91 lines
4.3 KiB
YAML
91 lines
4.3 KiB
YAML
uuid:
|
|
- value: add68937-4a3d-410d-a0d3-4510e3cb9e19
|
|
langcode:
|
|
- value: en
|
|
type:
|
|
- target_id: daily_email
|
|
target_type: node_type
|
|
target_uuid: 8bde1f2f-eef9-4f2d-ae9c-96921f8193d7
|
|
revision_timestamp:
|
|
- value: '2025-07-04T19:42:30+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: 'Imperative or declarative'
|
|
created:
|
|
- value: '2025-07-03T18:47:13+00:00'
|
|
changed:
|
|
- value: '2025-07-04T19:42:30+00:00'
|
|
promote:
|
|
- value: false
|
|
sticky:
|
|
- value: false
|
|
default_langcode:
|
|
- value: true
|
|
revision_translation_affected:
|
|
- value: true
|
|
path:
|
|
- alias: /daily/2025/07/03/imperative-or-declarative
|
|
langcode: en
|
|
body:
|
|
- value: |-
|
|
Yesterday, I wrote about [infrastructure as code][0] and mentioned some of the IaC tools that are available.
|
|
|
|
I use Terraform to manage the DNS records for my websites, and use NixOS to configure my laptops and home server.
|
|
|
|
Before NixOS, I used Ansible to provision servers and [deploy application code][1].
|
|
|
|
Ansible is imperative, which means you need to declare each step that needs to be run.
|
|
|
|
You need to say to install a package, like a web server.
|
|
|
|
You need to say to create any required users or groups.
|
|
|
|
You need to configure the service so it starts when the server boots.
|
|
|
|
You need to create the configuration files and symlink or copy them to the correct path.
|
|
|
|
You need to add as many steps as needed to perform the task, that will be executed in the given order.
|
|
|
|
## Declarative configuration
|
|
|
|
This makes sense for application deployments, but for server configuration, you can also use declarative tools like Terraform and NixOS.
|
|
|
|
Instead of writing each step, you declare what the final desired state is.
|
|
|
|
You say Nginx should be enabled by writing `services.nginx.enable = true;` or declaring what the configuration file contents should be - not how to create or symlink the file.
|
|
|
|
This also makes the underlying code easier to update or refactor.
|
|
|
|
If how you install or configure a program changes, you don't need to update your infrastructure code as the final state will be the same - regardless of how it's done.
|
|
|
|
[0]: /daily/2025/07/02/what-infrastructure-code
|
|
[1]: /presentations/deploying-php-ansible-ansistrano
|
|
format: markdown
|
|
processed: |
|
|
<p>Yesterday, I wrote about <a href="http://default/daily/2025/07/02/what-infrastructure-code">infrastructure as code</a> and mentioned some of the IaC tools that are available.</p>
|
|
<p>I use Terraform to manage the DNS records for my websites, and use NixOS to configure my laptops and home server.</p>
|
|
<p>Before NixOS, I used Ansible to provision servers and <a href="http://default/presentations/deploying-php-ansible-ansistrano">deploy application code</a>.</p>
|
|
<p>Ansible is imperative, which means you need to declare each step that needs to be run.</p>
|
|
<p>You need to say to install a package, like a web server.</p>
|
|
<p>You need to say to create any required users or groups.</p>
|
|
<p>You need to configure the service so it starts when the server boots.</p>
|
|
<p>You need to create the configuration files and symlink or copy them to the correct path.</p>
|
|
<p>You need to add as many steps as needed to perform the task, that will be executed in the given order.</p>
|
|
<h2>Declarative configuration</h2>
|
|
<p>This makes sense for application deployments, but for server configuration, you can also use declarative tools like Terraform and NixOS.</p>
|
|
<p>Instead of writing each step, you declare what the final desired state is.</p>
|
|
<p>You say Nginx should be enabled by writing <code>services.nginx.enable = true;</code> or declaring what the configuration file contents should be - not how to create or symlink the file.</p>
|
|
<p>This also makes the underlying code easier to update or refactor.</p>
|
|
<p>If how you install or configure a program changes, you don't need to update your infrastructure code as the final state will be the same - regardless of how it's done.</p>
|
|
summary: ''
|
|
field_daily_email_cta:
|
|
- target_type: node
|
|
target_uuid: 3074e1e9-c691-4f73-a71c-cfe5920f884e
|