summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Göhler <github@ghlr.de>2021-08-30 20:19:18 +0200
committerGitHub <noreply@github.com>2021-08-30 20:19:18 +0200
commitc5305d9597a6cc5cfc114589bcba1a972753ec56 (patch)
treef220a2f60b5db53750a75a49f0c6c5558a235368
parentd53bf91a4f1f5c37b22bf59c41c9a9ea68411f1d (diff)
parent8f2e92b96412ab019a9190e09295f16016f8cd81 (diff)
downloadvyos-documentation-c5305d9597a6cc5cfc114589bcba1a972753ec56.tar.gz
vyos-documentation-c5305d9597a6cc5cfc114589bcba1a972753ec56.zip
Merge pull request #602 from jeffbrl/cloud-init-command-execution
Add command execution at initial boot section to cloud-init
-rw-r--r--docs/automation/cloud-init.rst81
1 files changed, 75 insertions, 6 deletions
diff --git a/docs/automation/cloud-init.rst b/docs/automation/cloud-init.rst
index 2be66f7f..10bab72c 100644
--- a/docs/automation/cloud-init.rst
+++ b/docs/automation/cloud-init.rst
@@ -58,9 +58,19 @@ cloud-config file format
************************
A cloud-config document is written in YAML. The file must begin
-with ``#cloud-config`` line. The key used to designate a VyOS configuration
-is ``vyos_config_commands``. What follows is VyOS configuration using
-the "set-style" syntax. Both "set" and "delete" commands are supported.
+with ``#cloud-config`` line. The only supported top-level keys are
+``vyos_config_commands`` and ``write_files``. The use of these keys is described
+in the following two sections.
+
+
+************************
+Initial Configuration
+************************
+
+
+The key used to designate a VyOS configuration is ``vyos_config_commands``. What
+follows is VyOS configuration using the "set-style" syntax. Both "set" and "delete"
+commands are supported.
Commands requirements:
@@ -75,7 +85,7 @@ proper commands list by copying it from another router.
The configuration specified in the cloud-config document overwrites default
configuration values and values configured via Metadata.
-Here is an example cloud-config.
+Here is an example cloud-config that appends configuration at the time of first boot.
.. code-block:: yaml
@@ -88,9 +98,9 @@ Here is an example cloud-config.
- set interfaces ethernet eth1 address '192.0.2.247/24'
- set protocols static route 198.51.100.0/24 next-hop '192.0.2.1'
-*************************
+-------------------------
System Defaults/Fallbacks
-*************************
+-------------------------
These are the VyOS defaults and fallbacks.
@@ -100,6 +110,65 @@ These are the VyOS defaults and fallbacks.
All of these can be overridden using the configuration in user-data.
+
+*********************************
+Command Execution at Initial Boot
+*********************************
+
+VyOS supports the execution of operational commands and linux commands at
+initial boot. This is accomplished using ``write_files`` to certain
+files in the /opt/vyatta/etc/config/scripts directory. Commands specified
+in opt/vyatta/etc/config/scripts/vyos-preconfig-bootup.script are executed
+prior to configuration. The
+/opt/vyatta/etc/config/scripts/vyos-postconfig-bootup.script file contains
+commands to be executed after configuration. In both cases, commands are
+executed as the root user.
+
+Note that the /opt/vyatta/etc/config is used instead of the /config/scripts
+directory referenced in the :ref:`command-scripting` section of the
+documentation because the /config/script directory isn't mounted when the
+``write_files`` module executes.
+
+The following example shows how to execute commands after the initial
+configuration.
+
+.. code-block:: yaml
+
+ #cloud-config
+ write_files:
+ - path: /opt/vyatta/etc/config/scripts/vyos-postconfig-bootup.script
+ owner: root:vyattacfg
+ permissions: '0775'
+ content: |
+ #!/bin/vbash
+ source /opt/vyatta/etc/functions/script-template
+ filename=/tmp/bgp_status_`date +"%Y_%m_%d_%I_%M_%p"`.log
+ run show ip bgp summary >> $filename
+
+
+If you need to gather information from linux commands to configure VyOS, you can
+execute commands and then configure VyOS in the same script.
+
+The following example sets the hostname based on the instance identifier
+obtained from the EC2 metadata service.
+
+.. code-block:: yaml
+
+
+ #cloud-config
+ write_files:
+ - path: /opt/vyatta/etc/config/scripts/vyos-postconfig-bootup.script
+ owner: root:vyattacfg
+ permissions: '0775'
+ content: |
+ #!/bin/vbash
+ source /opt/vyatta/etc/functions/script-template
+ hostname=`curl -s http://169.254.169.254/latest/meta-data/instance-id`
+ configure
+ set system host-name $hostname
+ commit
+ exit
+
***************
Troubleshooting
***************