Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- What I'm trying to achieve
- --------------------------
- Run 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".
- FILE: /etc/salt/master/master.d/lystable.conf
- --------------------------------------------
- # Automatically accept minion connections -- we're assuming use in a VPC
- # or otherwise closed environment.
- auto_accept: True
- file_client: local
- # Network interface
- interface: 0.0.0.0
- worker_threads: 5
- # Home directory for the salt:// file server
- file_roots:
- base:
- - /srv/salt/states
- # Pillar locations
- pillar_roots:
- base:
- - /srv/salt/pillars
- gitfs_remotes:
- - https://github.com/saltstack-formulas/logrotate-formula.git
- runner_dirs:
- - /srv/salt/runners
- # Reactor configuration
- reactor:
- - 'minion_start':
- - salt://reactor/start.sls
- - 'salt/netapi/hook/build/success':
- - salt://reactor/deploy.sls
- rest_cherrypy:
- port: 8000
- host: 0.0.0.0
- webhook_disable_auth: True
- disable_ssl: True # we are managing SSL at the proxy level
- log_level: info
- fileserver_backend:
- - roots
- - git
- # Show terse output for successful states and full output for failures.
- state_output: mixed
- # Only show changes
- state_verbose: False
- Scenario 1 - I try to run the states/reactor/deploy.sls from command-line
- ----------------------------------------
- FILE: states/reactor/deploy.sls
- ------------------------
- ######
- # Parameters
- #
- # roles - EC2-level role to target VM instances
- # environment - chooses environment configuration
- # version - specifies a version for this component
- #
- ######
- {% if data is defined %}
- {% set form = data['post'] %}
- {% else %}
- {% set form = pillar['post'] %}
- {% endif %}
- {% if form.get('key') == 'secret-key' %}
- {% set role = form['roles'] %}
- {% set environment = form['environment'] %}
- {% set version = form.get('versions') %}
- {% set states = form.get('states') %}
- sync_grains:
- cmd.saltutil.sync_grains:
- - tgt: G@role:{{ role }}
- - expr_form: compound
- deploy_{{ environment }}_{{ role }}:
- cmd.state.sls:
- - arg:
- - {{ states }}
- - tgt: G@role:{{ role }}
- - expr_form: compound
- - kwarg:
- pillar:
- version: {{ version }}
- role: {{ role }}
- state: {{ states }}
- environment: {{ environment }}
- queue: True
- {% endif %}
- ----------------------
- root@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}}'
- [INFO ] Found minion id from generate_minion_id(): ip-10-1-2-250.ec2.internal
- [INFO ] Found minion id from generate_minion_id(): ip-10-1-2-250.ec2.internal
- [INFO ] Loading fresh modules for state activity
- [INFO ] Fetching file from saltenv 'base', ** done ** 'reactor/deploy.sls'
- [INFO ] Executing command ['git', '--version'] in directory '/root'
- [INFO ] Running state [sync_grains] at time 11:35:23.477144
- [ERROR ] State 'cmd.saltutil' was not found in SLS 'reactor.deploy'
- Reason: 'cmd.saltutil' is not available.
- [INFO ] Running state [deploy_staging_lws] at time 11:35:23.481043
- [ERROR ] State 'cmd.state' was not found in SLS 'reactor.deploy'
- Reason: 'cmd.state' is not available.
- ip-10-1-2-250.ec2.internal_master:
- ----------
- ID: sync_grains
- Function: cmd.saltutil
- Result: False
- Comment: State 'cmd.saltutil' was not found in SLS 'reactor.deploy'
- Reason: 'cmd.saltutil' is not available.
- Started:
- Duration:
- Changes:
- ----------
- ID: deploy_staging_lws
- Function: cmd.state
- Result: False
- Comment: State 'cmd.state' was not found in SLS 'reactor.deploy'
- Reason: 'cmd.state' is not available.
- Started:
- Duration:
- Changes:
- Summary for ip-10-1-2-250.ec2.internal_master
- ------------
- Succeeded: 0
- Failed: 2
- ------------
- Total states run: 2
- [INFO ] Runner completed: 20170126113522181561
- Scenario 2 - I try to re-write the states/reactor/deploy.sls
- ----------------------------------------
- FILE: states/reactor/deploy.sls (half-converted)
- ######
- # Parameters
- #
- # roles - EC2-level role to target VM instances
- # environment - chooses environment configuration
- # version - specifies a version for this component
- # report_role (optional) - name to help deployment report find the pillars
- # states (optional) - narrows down the deployment to just some states
- #
- ######
- {% if data is defined %}
- {% set form = data['post'] %}
- {% else %}
- {% set form = pillar['post'] %}
- {% endif %}
- {% if form.get('key') == 'secret-key' %}
- {% set role = form['roles'] %}
- {% set environment = form['environment'] %}
- {% set version = form.get('versions') %}
- {% set report_role = form.get('report_role') %}
- # State parameter is not mandatory, it is used to
- # make the deployment leaner
- {% set states = form.get('states') %}
- #sync_grains:
- # cmd.saltutil.sync_grains:
- # - tgt: G@role:{{ role }}
- # - expr_form: compound
- sync-grains:
- salt.function:
- - name: saltutil.sync_grains
- - tgt: G@role:{{ role }}
- - expr_form: compound
- deploy_{{ environment }}_{{ role }}:
- cmd.state.sls:
- - arg:
- - {{ states }}
- - tgt: G@role:{{ role }}
- - expr_form: compound
- - kwarg:
- pillar:
- version: {{ version }}
- role: {{ role }}
- state: {{ states }}
- environment: {{ environment }}
- {%- if report_role %}
- report_role: {{ report_role }}
- {%- endif %}
- queue: True
- {% endif %}
- -----------------------
- curl -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
- 2017-01-26 11:39:38,489 [salt.utils.process ][ERROR ][23856] An un-handled exception from the multiprocessing process 'Reactor-6' was caught:
- Traceback (most recent call last):
- File "/usr/lib/python2.7/dist-packages/salt/utils/process.py", line 613, in _run
- return self._original_run()
- File "/usr/lib/python2.7/dist-packages/salt/utils/reactor.py", line 241, in run
- self.call_reactions(chunks)
- File "/usr/lib/python2.7/dist-packages/salt/utils/reactor.py", line 198, in call_reactions
- self.wrap.run(chunk)
- File "/usr/lib/python2.7/dist-packages/salt/utils/reactor.py", line 269, in run
- l_fun = getattr(self, low['state'])
- AttributeError: 'ReactWrap' object has no attribute 'salt'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement