4. Write a Minimalist Spec File¶
Writing a spec file should be easy, let’s build a minimalist spec file to print the system information of a server.
4.1. Create a File¶
Let’s create an empty file spec.yml
in any directory.
4.2. Add a Name¶
We should add the name of the spec for what it does by appending the following
snippet to spec.yml
.
name: Get server name
4.3. Add a Description¶
We can optionally add a more verbose description. It’s a good practice to let people understand what the file is doing.
description: Use the command "uname" to get the server name
4.4. Add Experiments¶
Now it’s time to add some experiments. In this example, we only want to check the system information once, so there is only one experiment.
experiments:
- name: Get server name
commands:
run: "uname -a"
run
is the command type we’ll be using. It can be any
other string (e.g., get_info
, get_info_on_the_server
)
Tip
The experiments can be anything as long as they can be done by any Linux commands.
4.5. Add Servers¶
Then we should add some servers for the experiments to deploy. We should add at least one server. Feel free to modify the following text to specify your own server.
servers:
- name: Server 1
private_key_path: $HOME/.ssh/id_rsa
username: $USER
hostname: server1
name
is only used for Noodles to print the information,
private_key_path
is the path to the private key on the local machine,
username
is the username on the remote server (We use $USER
to set the
same username as on the local machine), and hostname
is usually a domain
name (e.g., example.com
) or an IP address (e.g., 123.123.123.123
) of
the remote server.
Note
Using password is not secure, so it’s not supported by Noodles. If you haven’t set up the SSH keys, please follow this tutorial.
4.6. Final Spec File¶
The final spec file can be seen here and also on GitHub:
name: Get server name
description: Use the command "uname" to get the server name
experiments:
- name: Get server name
commands:
run: "uname -a"
servers:
- name: Server 1
private_key_path: $HOME/.ssh/id_rsa
username: $USER
hostname: server1
4.7. Run the Spec File¶
Execute the following command:
noodles run spec.yml
and we should see something like:
2019-06-10 16:42:23 run INFO Start stage "before_all_experiments"
2019-06-10 16:42:23 run INFO Finished stage "before_all_experiments"
2019-06-10 16:42:23 run INFO Start stage "experiments"
2019-06-10 16:42:23 run INFO Deploy experiment "Get server name" to server "Server 1"
2019-06-10 16:42:25 run INFO Commands output from STDOUT->
Linux XXX 4.4.0-131-generic #157-Ubuntu SMP Thu Jul 12 15:51:36 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
2019-06-10 16:42:25 run INFO Finished stage "experiments"
2019-06-10 16:42:25 run INFO Start stage "after_all_experiments"
2019-06-10 16:42:25 run INFO Finished stage "after_all_experiments"
2019-06-10 16:42:25 run INFO Total elapsed time: 1.828s
2019-06-10 16:42:25 run INFO Successfully deployed 100% (1/1) "run" experiments
See the highlighted line. If XXX
is shown as the hostname of your server,
the deployment is successful.