Differences between revisions 4 and 23 (spanning 19 versions)
Revision 4 as of 2017-06-07 10:41:33
Size: 752
Editor: PieterSmit
Comment:
Revision 23 as of 2019-05-05 08:16:16
Size: 4281
Editor: PieterSmit
Comment:
Deletions are marked like this. Additions are marked like this.
Line 3: Line 3:
 * Links [[SaltCloudAzure]]
Line 6: Line 7:
   * sudo salt-call --state-verbose=false state.apply
Line 11: Line 14:
== Cloud deploy salt-cloud ==
 * With python debug pudb
   * sudo pudb /usr/bin/salt-cloud --log-level info --map=/etc/salt/cloud.maps.d/softlayer-maps-SVRCONFIG-SALTMASTER.conf
Line 12: Line 18:
== Fix salt-stack apt repo to stable version ==
 * edit /etc/apt/sources.list/saltstack.list
   * deb https://repo.saltstack.com/apt/ubuntu/14.04/amd64/2017.7 trusty main
 * Fix {{{ NO_PUBKEY 0E08A149DE57BFBE }}}
   * sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 0E08A149DE57BFBE

== Run from dev branch ==
 * Use pip {{{
$ sudo pip install salt==2018.3.0rc1
   }}}

 or
   
 * $ git clone git@github.com:saltstack/salt.git
 * git remote add upstream https://github.com/saltstack/salt
 * $ git fetch --tags
 * virtualenv salt
 * source ./salt/bin/activate
 *
 * pip install -e ./salt

== Do grains lookups for mine values ==
 * Salt mine is a db of all the minion grains.
 * It can be used to lookup a value for another minion, e.g. IP
 {{{
$ sudo salt-call mine.get 'role:mysql' network.ip_addrs grain
 }}}
 * Using a grain to find the ip of a host with a specific role.(Using mine.sls function that is network.ip_addrs + cidr {{{
{% set db_ip = salt.saltutil.runner('mine.get',
                tgt='G@environment:'+grains['environment']+' and G@role:database',
                fun='internal_ip_addrs',
                tgt_type='compound')[0] %}
}}}
Line 13: Line 52:

 * Online yaml parser - http://yaml-online-parser.appspot.com/
Line 19: Line 61:
= SaltStack errors and notes =

== ERROR:201904 - state.apply "- Rendering SLS 'base:<xx>' failed: did not find expected alphabetic or numeric character" ==
  * Cause was un-quoted context, that received a value "*-serv.jar"
  * Fix {{{
  context:
    file: "{{ file-src }}"
}}}

== ERROR:201811 - mine.get - Unable to manage file: Jinja error: too many values to unpack ==
  * snippet of salt.sls state giving the error {{{
{#% for server, addrs in salt['mine.get'](
      'G@environment:'+grains['environment']+' and G@role:webserver'
    , 'network.ip_addrs'
    , tgt_type='compound') %}
}}}
  * Fix: add dictsort ??? {{{
{#% for server, addrs in salt['mine.get'](
      'G@environment:'+grains['environment']+' and G@role:webserver'
    , 'network.ip_addrs'
    , tgt_type='compound') | dictsort() }
}}}
 * Explanation: in for loop, python just return the dict keys same as .keys(), but if we add " | dictsort() " we get loop over dicts, not keys.

 
== ERROR:201811 - unicode ==
 * Found offending character with {{{
grep -n -r -P '[^\x00-\x7f]' salt/common/
}}}


== ERROR:201810 - docker ==
 * https://github.com/saltstack/salt/issues/45292
 * my error {{{
----------
          ID: pull down docker_image xxx
    Function: docker_image.present
        Name: xxx.docker.io/xxx.service.xxx:latest
      Result: False
     Comment: Encountered error pulling xxx.docker.io/xxx.service.xxx:latest: Unable to perform images: cannot import name universaldetector

}}}

== ERROR:201810: salt pip AttributeError: type object 'InstallRequirement' has no attribute 'from_line' ==

 * https://github.com/saltstack/salt/issues/49967

== Resolve error on Ubuntu 16.04 ==
 1. Uninstall all pip i can with {{{
pip2 freeze > req.all.txt
pip2 uninstall -y -r req.all.txt
#remove files i cant uninstall
# loop back to pip2 uninstall
}}}
 2. apt uninstall salt-minion and salt-common
 3. apt install salt-minion and salt-common


THE.END

Salt Stack configuration management

  • Links SaltCloudAzure

  • improve output of state.apply to a lot of minions
    • salt --state-output=mixed --summary "*" state.apply backups.deploy

    • sudo salt-call --state-verbose=false state.apply

salt edit /etc/fstab

  • Edit lines in fstab e.g. Match cloudimg-rootfs and set the last 0 to a 1

    •  $ sudo salt "*" cmd.run "sed -i '/cloudimg-rootfs\s/ s/0$/1/ ; /cloudimg-bootfs\s/ s/0$/2/' /etc/fstab ; cat /etc/fstab" 

Cloud deploy salt-cloud

  • With python debug pudb
    • sudo pudb /usr/bin/salt-cloud --log-level info --map=/etc/salt/cloud.maps.d/softlayer-maps-SVRCONFIG-SALTMASTER.conf

Fix salt-stack apt repo to stable version

Run from dev branch

  • Use pip

    $ sudo pip install salt==2018.3.0rc1
    or
  • $ git clone git@github.com:saltstack/salt.git

  • git remote add upstream https://github.com/saltstack/salt

  • $ git fetch --tags
  • virtualenv salt
  • source ./salt/bin/activate
  • pip install -e ./salt

Do grains lookups for mine values

  • Salt mine is a db of all the minion grains.
  • It can be used to lookup a value for another minion, e.g. IP
    $ sudo salt-call mine.get 'role:mysql' network.ip_addrs grain
  • Using a grain to find the ip of a host with a specific role.(Using mine.sls function that is network.ip_addrs + cidr

    {% set db_ip = salt.saltutil.runner('mine.get', 
                    tgt='G@environment:'+grains['environment']+' and G@role:database',
                    fun='internal_ip_addrs',
                    tgt_type='compound')[0] %}

SaltStack errors and notes

ERROR:201904 - state.apply "- Rendering SLS 'base:<xx>' failed: did not find expected alphabetic or numeric character"

  • Cause was un-quoted context, that received a value "*-serv.jar"
  • Fix

      context:
        file: "{{ file-src }}"

ERROR:201811 - mine.get - Unable to manage file: Jinja error: too many values to unpack

  • snippet of salt.sls state giving the error

    {#% for server, addrs in salt['mine.get'](
          'G@environment:'+grains['environment']+' and G@role:webserver'
        , 'network.ip_addrs'
        , tgt_type='compound')  %}
  • Fix: add dictsort ???

    {#% for server, addrs in salt['mine.get'](
          'G@environment:'+grains['environment']+' and G@role:webserver'
        , 'network.ip_addrs'
        , tgt_type='compound') | dictsort() }
  • Explanation: in for loop, python just return the dict keys same as .keys(), but if we add " | dictsort() " we get loop over dicts, not keys.

ERROR:201811 - unicode

  • Found offending character with

    grep -n -r -P '[^\x00-\x7f]' salt/common/

ERROR:201810 - docker

  • https://github.com/saltstack/salt/issues/45292

  • my error

    ----------
              ID: pull down docker_image xxx
        Function: docker_image.present
            Name: xxx.docker.io/xxx.service.xxx:latest
          Result: False
         Comment: Encountered error pulling xxx.docker.io/xxx.service.xxx:latest: Unable to perform images: cannot import name universaldetector

ERROR:201810: salt pip AttributeError: type object 'InstallRequirement' has no attribute 'from_line'

Resolve error on Ubuntu 16.04

  1. Uninstall all pip i can with

    pip2 freeze > req.all.txt
    pip2 uninstall -y -r req.all.txt
    #remove files i cant uninstall
    # loop back to pip2 uninstall
  2. apt uninstall salt-minion and salt-common
  3. apt install salt-minion and salt-common

THE.END ...

SaltStack (last edited 2019-06-16 10:28:54 by PieterSmit)