summaryrefslogtreecommitdiff
path: root/docs/automation/vyos-salt.rst
blob: 12be32a1ddf97a803852ab23ec1137975c0ba067 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
:lastproofread: 2023-01-16

.. _vyos-salt:

.. include:: /_include/need_improvement.txt

Salt
====

VyOS supports op-mode and configuration via salt_.

Without proxy it requires VyOS minion configuration
and supports op-mode data:

.. code-block:: none

  set service salt-minion id 'r14'
  set service salt-minion master '192.0.2.250'

Check salt-keys on the salt master

.. code-block:: none

  / # salt-key --list-all
  Accepted Keys:
  r11
  Denied Keys:
  Unaccepted Keys:
  r14
  Rejected Keys:

Accept minion key

.. code-block:: none

  / # salt-key --accept r14
  The following keys are going to be accepted:
  Unaccepted Keys:
  r14
  Proceed? [n/Y] y
  Key for minion r14 accepted.



Check that salt master can communicate with minions

.. code-block:: none

  / # salt '*' test.ping
  r14:
      True
  r11:
      True

At this step we can get some op-mode information from VyOS nodes:

.. code-block:: none

  / # salt '*' network.interface eth0
  r11:
      |_
        ----------
        address:
            192.0.2.11
        broadcast:
            192.0.2.255
        label:
            eth0
        netmask:
            255.255.255.0
  r14:
      |_
        ----------
        address:
            192.0.2.14
        broadcast:
            192.0.2.255
        label:
            eth0
        netmask:
            255.255.255.0


  / # salt r14 network.arp
  r14:
      ----------
      aa:bb:cc:dd:f3:db:
          192.0.2.1
      aa:bb:cc:dd:2e:80:
          203.0.113.1




Netmiko-proxy
-------------

It is possible to configure VyOS via netmiko_ proxy module.
It requires a minion with installed packet  ``python3-netmiko`` module
who has a connection to VyOS nodes. Salt-minion have to communicate
with salt master

Configuration
^^^^^^^^^^^^^

Salt master configuration:

.. code-block:: none

  / # cat /etc/salt/master
  file_roots:
    base:
      - /srv/salt/states

  pillar_roots:
    base:
      - /srv/salt/pillars

Structure of /srv/salt:

.. code-block:: none

  / # tree /srv/salt/
  /srv/salt/
  |___ pillars
  |      |__ r11-proxy.sls
  |      |__ top.sls
  |___ states
         |__ commands.txt

top.sls

.. code-block:: none

  / # cat /srv/salt/pillars/top.sls
  base:
    r11-proxy:
      - r11-proxy


r11-proxy.sls Includes parameters for connecting to salt-proxy minion

.. code-block:: none

  / # cat /srv/salt/pillars/r11-proxy.sls 
  proxy:
    proxytype: netmiko # how to connect to proxy minion, change it
    device_type: vyos  # 
    host: 192.0.2.250
    username: user
    password: secret_passwd

commands.txt

.. code-block:: none

  / # cat /srv/salt/states/commands.txt 
  set interfaces ethernet eth0 description 'WAN'
  set interfaces ethernet eth1 description 'LAN'

Check that proxy minion is alive:

.. code-block:: none

  / # salt r11-proxy test.ping
  r11-proxy:
      True
  / #

Examples
^^^^^^^^

Example of op-mode:

.. code-block:: none

  / # salt r11-proxy netmiko.send_command 'show interfaces ethernet eth0 brief' host=192.0.2.14 device_type=vyos username=vyos password=vyos
  r11-proxy:
      Codes: S - State, L - Link, u - Up, D - Down, A - Admin Down
      Interface        IP Address                        S/L  Description
      ---------        ----------                        ---  -----------
      eth0             192.0.2.14/24                     u/u  Upstream
  / # 

Example of configuration:

.. code-block:: none

  / # salt r11-proxy netmiko.send_config config_commands=['set interfaces ethernet eth0 description Link_to_WAN'] commit=True host=192.0.2.14 device_type=vyos username=vyos password=vyos
  r11-proxy:
      configure
      set interfaces ethernet eth0 description Link_to_WAN
      [edit]
      vyos@r14# commit
      [edit]
      vyos@r14#
  / #

Example of configuration commands from the file "/srv/salt/states/commands.txt"

.. code-block:: none

  / # salt r11-proxy netmiko.send_config config_file=salt://commands.txt commit=True host=192.0.2.11 device_type=vyos username=vyos password=vyos
  r11-proxy:
      configure
      set interfaces ethernet eth0 description 'WAN'
      [edit]
      vyos@r1# set interfaces ethernet eth1 description 'LAN'
      [edit]
      vyos@r1# commit
      [edit]
      vyos@r1#
  / #

.. _salt: https://docs.saltproject.io/en/latest/contents.html
.. _netmiko: https://docs.saltproject.io/en/latest/ref/modules/all/salt.modules.netmiko_mod.html#module-salt.modules.netmiko_mod