· 9 years ago · Jan 26, 2017, 11:42 AM
1What I'm trying to achieve
2--------------------------
3
4Run the states/reactor/deploy.sls file in the command-line, synchronously, so that I can debug errors more easily and not rely on the salt master log file. The same way we can do for orchestration files with "state.orchestrate".
5
6FILE: /etc/salt/master/master.d/lystable.conf
7--------------------------------------------
8
9# Automatically accept minion connections -- we're assuming use in a VPC
10# or otherwise closed environment.
11auto_accept: True
12
13file_client: local
14
15# Network interface
16interface: 0.0.0.0
17
18worker_threads: 5
19
20# Home directory for the salt:// file server
21file_roots:
22 base:
23 - /srv/salt/states
24
25# Pillar locations
26pillar_roots:
27 base:
28 - /srv/salt/pillars
29
30gitfs_remotes:
31 - https://github.com/saltstack-formulas/logrotate-formula.git
32
33runner_dirs:
34 - /srv/salt/runners
35
36# Reactor configuration
37reactor:
38 - 'minion_start':
39 - salt://reactor/start.sls
40 - 'salt/netapi/hook/build/success':
41 - salt://reactor/deploy.sls
42
43rest_cherrypy:
44 port: 8000
45 host: 0.0.0.0
46 webhook_disable_auth: True
47 disable_ssl: True # we are managing SSL at the proxy level
48
49log_level: info
50
51fileserver_backend:
52 - roots
53 - git
54
55# Show terse output for successful states and full output for failures.
56state_output: mixed
57# Only show changes
58state_verbose: False
59
60Scenario 1 - I try to run the states/reactor/deploy.sls from command-line
61----------------------------------------
62
63FILE: states/reactor/deploy.sls
64------------------------
65
66######
67# Parameters
68#
69# roles - EC2-level role to target VM instances
70# environment - chooses environment configuration
71# version - specifies a version for this component
72#
73######
74
75{% if data is defined %}
76{% set form = data['post'] %}
77{% else %}
78{% set form = pillar['post'] %}
79{% endif %}
80
81{% if form.get('key') == 'secret-key' %}
82
83{% set role = form['roles'] %}
84{% set environment = form['environment'] %}
85{% set version = form.get('versions') %}
86{% set states = form.get('states') %}
87
88sync_grains:
89 cmd.saltutil.sync_grains:
90 - tgt: G@role:{{ role }}
91 - expr_form: compound
92
93deploy_{{ environment }}_{{ role }}:
94 cmd.state.sls:
95 - arg:
96 - {{ states }}
97 - tgt: G@role:{{ role }}
98 - expr_form: compound
99 - kwarg:
100 pillar:
101 version: {{ version }}
102 role: {{ role }}
103 state: {{ states }}
104 environment: {{ environment }}
105 queue: True
106
107{% endif %}
108
109----------------------
110
111root@ip-10-1-2-250:~/lystable-salt# salt-run state.orchestrate reactor.deploy pillar='{post: {key: secret-key, roles: lws, versions: 0.181.1, environment: staging}}'
112[INFO ] Found minion id from generate_minion_id(): ip-10-1-2-250.ec2.internal
113[INFO ] Found minion id from generate_minion_id(): ip-10-1-2-250.ec2.internal
114[INFO ] Loading fresh modules for state activity
115[INFO ] Fetching file from saltenv 'base', ** done ** 'reactor/deploy.sls'
116[INFO ] Executing command ['git', '--version'] in directory '/root'
117[INFO ] Running state [sync_grains] at time 11:35:23.477144
118[ERROR ] State 'cmd.saltutil' was not found in SLS 'reactor.deploy'
119Reason: 'cmd.saltutil' is not available.
120
121[INFO ] Running state [deploy_staging_lws] at time 11:35:23.481043
122[ERROR ] State 'cmd.state' was not found in SLS 'reactor.deploy'
123Reason: 'cmd.state' is not available.
124
125ip-10-1-2-250.ec2.internal_master:
126----------
127 ID: sync_grains
128 Function: cmd.saltutil
129 Result: False
130 Comment: State 'cmd.saltutil' was not found in SLS 'reactor.deploy'
131 Reason: 'cmd.saltutil' is not available.
132 Started:
133 Duration:
134 Changes:
135----------
136 ID: deploy_staging_lws
137 Function: cmd.state
138 Result: False
139 Comment: State 'cmd.state' was not found in SLS 'reactor.deploy'
140 Reason: 'cmd.state' is not available.
141 Started:
142 Duration:
143 Changes:
144
145Summary for ip-10-1-2-250.ec2.internal_master
146------------
147Succeeded: 0
148Failed: 2
149------------
150Total states run: 2
151[INFO ] Runner completed: 20170126113522181561
152
153
154Scenario 2 - I try to re-write the states/reactor/deploy.sls
155----------------------------------------
156
157FILE: states/reactor/deploy.sls (half-converted)
158
159######
160# Parameters
161#
162# roles - EC2-level role to target VM instances
163# environment - chooses environment configuration
164# version - specifies a version for this component
165# report_role (optional) - name to help deployment report find the pillars
166# states (optional) - narrows down the deployment to just some states
167#
168######
169
170{% if data is defined %}
171{% set form = data['post'] %}
172{% else %}
173{% set form = pillar['post'] %}
174{% endif %}
175
176{% if form.get('key') == 'secret-key' %}
177
178{% set role = form['roles'] %}
179{% set environment = form['environment'] %}
180{% set version = form.get('versions') %}
181{% set report_role = form.get('report_role') %}
182
183# State parameter is not mandatory, it is used to
184# make the deployment leaner
185{% set states = form.get('states') %}
186
187#sync_grains:
188# cmd.saltutil.sync_grains:
189# - tgt: G@role:{{ role }}
190# - expr_form: compound
191
192sync-grains:
193 salt.function:
194 - name: saltutil.sync_grains
195 - tgt: G@role:{{ role }}
196 - expr_form: compound
197
198deploy_{{ environment }}_{{ role }}:
199 cmd.state.sls:
200 - arg:
201 - {{ states }}
202 - tgt: G@role:{{ role }}
203 - expr_form: compound
204 - kwarg:
205 pillar:
206 version: {{ version }}
207 role: {{ role }}
208 state: {{ states }}
209 environment: {{ environment }}
210{%- if report_role %}
211 report_role: {{ report_role }}
212{%- endif %}
213 queue: True
214
215{% endif %}
216
217-----------------------
218
219curl -sSk http://localhost:8000/hook/build/success -d environment="staging" -d roles=lws -d key="secret-key" -d versions=0.181.1 -d states=lws
220
2212017-01-26 11:39:38,489 [salt.utils.process ][ERROR ][23856] An un-handled exception from the multiprocessing process 'Reactor-6' was caught:
222Traceback (most recent call last):
223 File "/usr/lib/python2.7/dist-packages/salt/utils/process.py", line 613, in _run
224 return self._original_run()
225 File "/usr/lib/python2.7/dist-packages/salt/utils/reactor.py", line 241, in run
226 self.call_reactions(chunks)
227 File "/usr/lib/python2.7/dist-packages/salt/utils/reactor.py", line 198, in call_reactions
228 self.wrap.run(chunk)
229 File "/usr/lib/python2.7/dist-packages/salt/utils/reactor.py", line 269, in run
230 l_fun = getattr(self, low['state'])
231AttributeError: 'ReactWrap' object has no attribute 'salt'