# Salt Upgrade Notes ## Places where code might need to be updated for a new version ( salt.repo ) - [packer/scripts/add-saltstack-repo.sh](https://github.xdr.accenturefederalcyber.com/mdr-engineering/msoc-infrastructure/blob/develop/packer/scripts/add-saltstack-repo.sh) - [salt/pillar/dev/yumrepos.sls](https://github.xdr.accenturefederalcyber.com/mdr-engineering/msoc-infrastructure/blob/develop/salt/pillar/dev/yumrepos.sls) - [salt/pillar/prod/yumrepos.sls](https://github.xdr.accenturefederalcyber.com/mdr-engineering/msoc-infrastructure/blob/develop/salt/pillar/prod/yumrepos.sls) - Search code for previous version! <<<< Do THIS Many places ## Salt Upgrade Steps Always upgrade salt master then minions Dev Steps Update the pillar in git salt/pillar/dev/yumrepos.sls ``` salt 'salt*' cmd.run 'salt-run fileserver.update' salt 'salt*' cmd.run 'salt-run git_pillar.update' salt 'salt*' saltutil.refresh_pillar salt 'salt*' pillar.get yumrepos:salt:version ``` Update salt master ``` salt 'salt*' cmd.run 'cat /etc/yum.repos.d/salt.repo' salt 'salt*' state.sls os_modifications.repo_update_redhat --output-diff test=true salt 'salt*' cmd.run 'cat /etc/yum.repos.d/salt.repo' salt 'salt*' cmd.run 'yum clean all ; yum makecache fast' salt 'salt*' cmd.run 'yum check-update | grep salt' salt 'salt*' pkg.upgrade name=salt-master # NOTE: this might upgrade the salt-minion at the same time. sudo systemctl start salt-minion sudo salt 'salt*' state.sls salt_master.salt_posix_acl --output-diff salt 'salt*' test.version ``` Update salt minions using minion_upgrade salt state ``` salt '*' saltutil.refresh_pillar salt '*' pillar.get yumrepos:salt:version salt sensu* state.sls salt_minion.minion_upgrade --output-diff test=true salt sensu* test.version salt vault* state.sls salt_minion.minion_upgrade --output-diff test=true salt vault* test.version # focus on just Redhat first? salt -G 'os:RedHat' state.sls salt_minion.minion_upgrade --output-diff test=true salt -G 'os:RedHat' test.version # then debian based salt -C '* not G@os:RedHat' state.sls salt_minion.minion_upgrade --output-diff test=true salt -C '* not G@os:RedHat' test.version ``` Did you miss any? ``` salt -G saltversion:300X.X test.version salt -C '* not G@saltversion:300X.X' test.version ``` Ensure the vmray /etc/apt/sources.list.d/salt.list is correctly showing only one repo. repeat for PROD. ### Salt Upgrade 3003.3 -> 3004.1 Upgrading the minion first will result in loss of connectivity ### Salt Upgrade 3002.6 -> 3003.3 ### Salt Upgrade 3001.6 -> 3002.6 Notes next time try this: `salt/fileroots/os_modifications/minion_upgrade.sls` ( move it to the salt folder or something ) upgrade salt master then minions Update the pillar in git ``` salt salt* cmd.run 'salt-run fileserver.update' salt salt* cmd.run 'salt-run git_pillar.update' salt salt* saltutil.refresh_pillar salt salt* pillar.get yumrepos:salt:version ``` Update salt master ``` salt salt* cmd.run 'cat /etc/yum.repos.d/salt.repo' salt salt* state.sls os_modifications.repo_update --output-diff test=true salt salt* cmd.run 'cat /etc/yum.repos.d/salt.repo' salt salt* cmd.run 'yum clean all ; yum makecache fast' salt salt* cmd.run 'yum check-update | grep salt' salt salt* pkg.upgrade name=salt-master sudo salt salt* state.sls salt_master.salt_posix_acl --output-diff ``` Update salt minions ``` salt sensu* cmd.run 'cat /etc/yum.repos.d/salt.repo' salt sensu* state.sls os_modifications.repo_update --output-diff test=true salt sensu* cmd.run 'cat /etc/yum.repos.d/salt.repo' salt sensu* cmd.run 'yum clean all ; yum makecache fast' salt sensu* cmd.run 'yum check-update | grep salt' salt sensu* cmd.run_bg 'systemd-run --scope yum update salt-minion -y && sleep 20 && systemctl daemon-reload && sleep 20 && systemctl start salt-minion' salt sensu* test.version ``` Did you miss any? `salt -G saltversion:3002.6 test.ping` repeat for PROD. ### Salt Upgrade 3001.2 -> 3001.6 Notes #### Places where code might need to be updated for a new version ( salt.repo ) - [packer/scripts/add-saltstack-repo.sh](https://github.xdr.accenturefederalcyber.com/mdr-engineering/msoc-infrastructure/blob/develop/packer/scripts/add-saltstack-repo.sh) - [salt/pillar/dev/yumrepos.sls](https://github.xdr.accenturefederalcyber.com/mdr-engineering/msoc-infrastructure/blob/develop/salt/pillar/dev/yumrepos.sls) - [salt/pillar/prod/yumrepos.sls](https://github.xdr.accenturefederalcyber.com/mdr-engineering/msoc-infrastructure/blob/develop/salt/pillar/prod/yumrepos.sls) ( you can wait until after testing is done in test before deploying to prod ) For your reference.... - [packer/scripts/provision-salt-master.sh](https://github.xdr.accenturefederalcyber.com/mdr-engineering/msoc-infrastructure/blob/develop/packer/scripts/provision-salt-master.sh) <- salt master is installed here - [base/salt_master/cloud-init/provision_salt_master.sh](https://github.xdr.accenturefederalcyber.com/mdr-engineering/xdr-terraform-modules/blob/master/base/salt_master/cloud-init/provision_salt_master.sh) <- salt master is configured here - dev - legacy test - gc test - legacy prod - gc prod - LCP nodes Prep In the dev environment, the salt minion failed to start up after the upgrade. Might need a cronjob on the LCP nodes. Ensure the pillar has been updated to the correct version. ``` salt salt* cmd.run 'salt-run fileserver.update' salt salt* pillar.get yumrepos:salt:version ``` Update repo ``` salt salt* cmd.run 'cat /etc/yum.repos.d/salt.repo' salt salt* state.sls os_modifications.repo_update --output-diff test=true salt salt* cmd.run 'cat /etc/yum.repos.d/salt.repo' salt salt* cmd.run 'yum clean all ; yum makecache fast' salt salt* cmd.run 'yum check-update | grep salt' salt salt* pkg.upgrade name=salt-master sudo salt salt* state.sls salt_master.salt_posix_acl --output-diff ``` Ack the minions didn't come back! stupid salt! Let's try something different ``` salt salt* cmd.run 'cat /etc/yum.repos.d/salt.repo' salt salt* state.sls os_modifications.repo_update --output-diff test=true salt salt* cmd.run 'cat /etc/yum.repos.d/salt.repo' salt salt* cmd.run 'yum clean all ; yum makecache fast' salt salt* cmd.run 'yum check-update | grep salt' cmd.run_bg 'systemd-run --scope yum update salt-minion -y && sleep 240 && systemctl daemon-reload && sleep 20 && systemctl start salt-minion' ``` Did you miss any? `salt -G saltversion:3001.3 test.ping` BAD DNS for Splunk returner `requests.packages.urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='moose-hec.xdr.accenturefederalcyber.com', port=8088): Max retries exceeded with url: /services/collector/event` (Caused by `NewConnectionError(': Failed to establish a new connection: [Errno 110] Connection timed out'`,)) ### Salt Upgrade 2019 -> 3001 Notes #### Places where code might need to be updated for a new version ( salt.repo ) - [packer/scripts/add-saltstack-repo.sh](https://github.xdr.accenturefederalcyber.com/mdr-engineering/msoc-infrastructure/blob/develop/packer/scripts/add-saltstack-repo.sh) - [base/salt_master/cloud-init/provision_salt_master.sh](https://github.xdr.accenturefederalcyber.com/mdr-engineering/xdr-terraform-modules/blob/master/base/salt_master/cloud-init/provision_salt_master.sh) - [salt/pillar/dev/yumrepos.sls](https://github.xdr.accenturefederalcyber.com/mdr-engineering/msoc-infrastructure/blob/develop/salt/pillar/dev/yumrepos.sls) Prep - update Pillars `yumrepos:salt:version` and `yumrepos:salt:baseurl` On the master - update repo `salt salt* state.sls os_modifications.repo_update --output-diff` - install gitpython on salt master for py3 `pip3 install gitpython` - `salt salt-master* cmd.run 'yum clean all ; yum makecache fast'` - `salt salt* cmd.run 'yum check-update'` - update `salt salt* pkg.upgrade name=salt-master` - `salt salt* state.sls salt_master.salt_posix_acl --output-diff` - `salt salt* cmd.run 'systemctl restart salt-master'` - `salt salt*com state.sls salt_master.salt_master_configs test=true` On the minions - update repo `salt salt* state.sls os_modifications.repo_update --output-diff` - `salt salt* cmd.run 'yum clean all ; yum makecache fast'` - `salt salt* cmd.run 'yum check-update'` - update `salt salt* pkg.upgrade name=salt-minion` - yum install python36-zmq <- might need that for some minions. - `watch 'salt salt* test.ping'` - `salt cmd.run 'pip3 install boto'` - `salt cmd.run 'pip3 install boto3'` - `salt cmd.run 'pip3 install pyinotify'` - `salt saltutil.sync_all` - `salt saltutil.refresh_modules` - `salt grains.get ec2:placement:availability_zone` - `salt grains.get environment` - RESTART to apply beacon inotify changes `service.restart salt-minion` - `cmd.run 'tail /var/log/salt/minion'` ``` salt sensu* pkg.upgrade name=salt-minion salt vault*local pkg.upgrade name=salt-minion salt moose*local pkg.upgrade name=salt-minion salt -C '* not ( moose* or afs* or nga* or ma-* or mo-* or la-* or dc-* or vault* or sensu* or interconnect* or resolver* or salt-master* )' pkg.upgrade name=salt-minion salt -C 'resol* or interc*' pkg.upgrade name=salt-minion ``` #### 3001 Upgrade PROBLEMS salt-call -ldebug --local grains.get ec2_info salt-call -ldebug --local grains.get ec2_tags boto and boto3 needs to be installed for py3 for ec2 grains pip3 install boto pip3 install boto3 pip3 list installed | grep boto push out new grain that was updated for py3. fixes the ec2:placement:availability_zone grain salt *local saltutil.sync_all salt *com saltutil.sync_all salt *local grains.get ec2:placement:availability_zone salt *com grains.get ec2:placement:availability_zone ISSUE: ``` [ERROR ] Returner splunk.returner could not be loaded: 'splunk.returner' is not available. SOLUTION: manually restart minion ``` ISSUE: ``` 2020-11-23 18:13:09,719 [salt.beacons :144 ][WARNING ][15141] Unable to process beacon inotify cmd.run 'ls -larth /etc/salt/minion.d/beacons.conf' ``` ISSUE: ``` requests.packages.urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='iratemoses.mdr.defpoint.com', port=8088): Max retries exceeded with url: /services/collector/event (Caused by NewConnectionError(': Failed to establish a new connection: [Errno -2] Name or service not known',)) ``` SOLUTION: ``` IGNORE: this was happening with previous version of salt and python2. ``` ISSUE on reposerver: ``` 2020-11-23 19:42:20,061 [salt.state :328 ][ERROR ][18267] Cron /usr/local/bin/repomirror-cron.sh for user root failed to commit with error "/tmp/__salt.tmp.9b64eos8":1: bad minute errors in crontab file, can't install. ``` SOLUTION: ``` bad cron file? ``` ISSUE: ``` [CRITICAL][1745] Pillar render error: Rendering SLS 'mailrelay' failed 2020-11-23 19:26:11,255 [salt.pillar :889 ] [CRITICAL][1745] Rendering SLS 'mailrelay' failed, render error: Jinja variable 'salt.utils.context.NamespacedDictWrapper object' has no attribute 'ec2' Traceback (most recent call last): File "/usr/lib/python3.6/site-packages/salt/utils/templates.py", line 400, in render_jinja_tmpl output = template.render(**decoded_context) File "/usr/lib/python3.6/site-packages/jinja2/environment.py", line 989, in render return self.environment.handle_exception(exc_info, True) File "/usr/lib/python3.6/site-packages/jinja2/environment.py", line 754, in handle_exception reraise(exc_type, exc_value, tb) File "/usr/lib/python3.6/site-packages/jinja2/_compat.py", line 37, in reraise raise value.with_traceback(tb) File "