Giter Club home page Giter Club logo

salt-describe's Introduction

Salt Describe

Salt Describe is a Salt Extension used to automate the generation of infrastructure as code files using Salt to query target machines.

Quickstart

To get started with your new project:

# Create a new venv
python3 -m venv env --prompt salt-describe
source env/bin/activate

# On mac, you may need to upgrade pip
python -m pip install --upgrade pip

# On WSL or some flavors of linux you may need to install the `enchant`
# library in order to build the docs
sudo apt-get install -y enchant

# Install extension + test/dev/doc dependencies into your environment
python -m pip install -e .[tests,dev,docs]

# Run tests!
python -m nox -e tests-3

# skip requirements install for next time
export SKIP_REQUIREMENTS_INSTALL=1

# Build the docs, serve, and view in your web browser:
python -m nox -e docs && (cd docs/_build/html; python -m webbrowser localhost:8000; python -m http.server; cd -)

# Run the pkg describe function
salt-run describe.pkg <minion-tgt>

# Run the file describe function
salt-run describe.file <minion-tgt> <file name>

# Generate the top file for the minion target based off of previously generated SLS files.
salt-run describe.top <minion-tgt>

salt-describe's People

Contributors

ch3ll avatar garethgreenaway avatar mkleb avatar vmwghbot avatar whytewolf avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

salt-describe's Issues

Change the return data of salt-describe

Currently when you run salt-describe it returns True/False.

We want to change this return to include the path where the SLS file was created, so the user will know where to look for the file.

Do not add password arg to user state if does not exist in pillar data

The user describe runner will generate a sls file like so:

user-ch3ll:
  user.present:
  - name: ch3ll
  - uid: 1000
  - gid: 1000
  - allow_uid_change: true
  - allow_gid_change: true
  - home: /home/ch3ll
  - shell: /usr/bin/zsh
  - groups:
    - ch3ll
    - lp
    - network
    - power
    - sys
    - wheel
  - password: '{{ salt["pillar.get"]("users:ch3ll","*") }}'
  - date: 18590
  - mindays: 0
  - maxdays: 99999
  - inactdays: -1
  - expire: -1
  - createhome: true
  - fullname: Megan Wilhite

If users:ch3ll is not set in pillar, it will still try changing the password, which would be unexpected for a user who does not know that is a requirement for the user state. We should make this optional and only set the password argument if users:ch3ll is in pillar data. Most likely we will want to handle this with jinja.

Using describe.all gives error

Trying to use describe.all to geenerate all the supported state files gives this error

root@ip-10-27-57-178:~/salt-describe# salt-run describe.all frode 
[ERROR   ] string indices must be integers
No minions matched the target. No command was sent, no jid was assigned.
No minions matched the target. No command was sent, no jid was assigned.
No minions matched the target. No command was sent, no jid was assigned.
No minions matched the target. No command was sent, no jid was assigned.
No minions matched the target. No command was sent, no jid was assigned.
No minions matched the target. No command was sent, no jid was assigned.
No minions matched the target. No command was sent, no jid was assigned.
No minions matched the target. No command was sent, no jid was assigned.
No minions matched the target. No command was sent, no jid was assigned.
[ERROR   ] s not found in sysctl
[ERROR   ] a not found in sysctl
[ERROR   ] l not found in sysctl
[ERROR   ] t not found in sysctl
No minions matched the target. No command was sent, no jid was assigned.

Generate the top file for the minion target based off of previously generated SLS files fails

Trying to generate the top.sls file using describe.top files fails for me.

I see this

root@ip-10-27-56-243:~# ls -l /srv/salt/frode/
total 108
-rw-r--r-- 1 root root     3 Feb  7 18:21 cron.sls
drwxr-xr-x 3 root root  4096 Feb  7 17:53 files
-rw-r--r-- 1 root root   130 Feb  7 18:19 files.sls
-rw-r--r-- 1 root root   104 Feb  7 18:21 firewalld.sls
-rw-r--r-- 1 root root  3602 Feb  7 18:21 groups.sls
-rw-r--r-- 1 root root   601 Feb  7 18:21 host.sls
-rw-r--r-- 1 root root   201 Feb  7 18:21 init.sls
-rw-r--r-- 1 root root  1774 Feb  7 18:21 iptables.sls
-rw-r--r-- 1 root root   303 Feb  7 18:21 pip.sls
-rw-r--r-- 1 root root 23864 Feb  7 18:21 pkg.sls
-rw-r--r-- 1 root root  4955 Feb  7 18:21 pkgrepo.sls
-rw-r--r-- 1 root root 14950 Feb  7 18:21 service.sls
-rw-r--r-- 1 root root     3 Feb  7 18:00 sysctl.sls
-rw-r--r-- 1 root root    31 Feb  7 18:21 timezone.sls
-rw-r--r-- 1 root root 13673 Feb  7 18:14 users.sls
root@ip-10-27-56-243:~# 
root@ip-10-27-56-243:~# salt-run describe.top frode

Passed invalid arguments: argument of type 'NoneType' is not iterable

Usage:

    Add the generated states to top.sls

    CLI Example:

    .. code-block:: bash

        salt-run describe.top minion-tgt
    
root@ip-10-27-56-243:~# 

Traceback when using firewalld function

(salt-describe) [root@localhost centos7-test]# salt-run describe.firewalld centos7-test
Exception occurred in runner describe.firewalld: Traceback (most recent call last):
File "/root/.pyenv/versions/3.9.13/envs/salt-describe/lib/python3.9/site-packages/salt/client/mixins.py", line 390, in low
data["return"] = func(*args, **kwargs)
File "/root/.pyenv/versions/3.9.13/envs/salt-describe/lib/python3.9/site-packages/salt/loader/lazy.py", line 149, in call
return self.loader.run(run_func, *args, **kwargs)
File "/root/.pyenv/versions/3.9.13/envs/salt-describe/lib/python3.9/site-packages/salt/loader/lazy.py", line 1201, in run
return self._last_context.run(self._run_as, _func_or_method, *args, **kwargs)
File "/root/.pyenv/versions/3.9.13/envs/salt-describe/lib/python3.9/site-packages/salt/loader/lazy.py", line 1216, in _run_as
return _func_or_method(*args, **kwargs)
File "/root/.pyenv/versions/3.9.13/envs/salt-describe/lib/python3.9/site-packages/saltext/salt_describe/runners/salt_describe.py", line 575, in firewalld
zones = rule.keys()
AttributeError: 'str' object has no attribute 'keys'

Traceback when using pkgrepo function

(salt-describe) [root@localhost centos7-test]# salt-run describe.pkgrepo centos7-test
Exception occurred in runner describe.pkgrepo: Traceback (most recent call last):
File "/root/.pyenv/versions/3.9.13/envs/salt-describe/lib/python3.9/site-packages/salt/client/mixins.py", line 390, in low
data["return"] = func(*args, **kwargs)
File "/root/.pyenv/versions/3.9.13/envs/salt-describe/lib/python3.9/site-packages/salt/loader/lazy.py", line 149, in call
return self.loader.run(run_func, *args, **kwargs)
File "/root/.pyenv/versions/3.9.13/envs/salt-describe/lib/python3.9/site-packages/salt/loader/lazy.py", line 1201, in run
return self._last_context.run(self._run_as, _func_or_method, *args, **kwargs)
File "/root/.pyenv/versions/3.9.13/envs/salt-describe/lib/python3.9/site-packages/salt/loader/lazy.py", line 1216, in _run_as
return _func_or_method(*args, **kwargs)
File "/root/.pyenv/versions/3.9.13/envs/salt-describe/lib/python3.9/site-packages/saltext/salt_describe/runners/salt_describe.py", line 798, in pkgrepo
{"enabled": pkgrepo[_pkgrepo_name]["enabled"]}]}
KeyError: 'enabled'

Exclude dont seem to work when using with describe.all

When using describe.all I get error that I need to use args, which is fine.

root@ip-10-27-56-243:~# salt-run describe.all frode
[ERROR   ] Missing positional arg paths for describe.file
[ERROR   ] Missing positional arg sysctl_items for describe.sysctl

But if I try to use exclude, it doesnt seem to work for me.

Unless I am doing something wrong.

root@ip-10-27-56-243:~# salt-run describe.all frode exclude='["file", "sysctl"]'

Passed invalid arguments: argument of type 'NoneType' is not iterable

Usage:

    Run all describe methods against target.

    One of either a exclude or include can be given to specify
    which functions to run.  These can be either a string or python list.

    CLI Example:

    .. code-block:: bash

        salt-run describe.all minion-tgt exclude='["file", "user"]'

    You can supply args and kwargs to functions that require them as well.
    These are passed as explicit kwargs.

    CLI Example:

    .. code-block:: bash

        salt-run describe.all minion-tgt include='["file", "pip"]' paths='["/tmp/testfile", "/tmp/testfile2"]'

    If two functions take an arg or kwarg of the same name, you can differentiate them
    by prefixing the argument name.

    CLI Example:

    .. code-block:: bash

        salt-run describe.all minion-tgt include='["file", "pip"]' file_paths='["/tmp/testfile", "/tmp/testfile2"]'
    
root@ip-10-27-56-243:~# 

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.