Require sls by its ID Declaration - salt-stack

I have two state files:
php/init.sls
php-fpm.sls
php/init.sls installs the package php53u
I'm trying to get php-fpm.sls to require php as that is how I declare it inside php/init.sls, however it only works if I require the pkg: php53u and not sls: php
Contents of php/init.sh:
php:
pkg:
- name: php53u
- installed
Contents of php-fpm.sls (using pkg where it works):
include:
- nginx
- php
php-fpm:
pkg:
- name: php53u-fpm
- installed
service:
- running
- enable: True
- require:
- pkg: php53u-fpm
- pkg: php53u
extend:
nginx:
file:
- name: /etc/nginx/php-fpm
- source: salt://nginx/src/etc/nginx/php-fpm
- managed
- template: jinja
(note that this has extra stuff about nginx that currently isn't a require though it should be)

You are correctly including the php sls file. You just need to set your require like this:
- pkg: php
Here's an example that should work:
php-fpm:
pkg:
- name: php53u-fpm
- installed
- require:
- pkg: php
service:
- running
- enable: True
- watch:
- pkg: php53u-fpm
- pkg: php
Notice that I also added the require to the pkg stanza to make sure that the php package is installed before the php53u-fpm package.
I also changed the "require" under the service stanza to a "watch". A "watch" acts as a "require", but also will restart the service if the "watched" pkg changes. So if there's a package upgrade it will restart the service automatically.

It's perfectly normal, in the require list, you need to use ID Declaration (http://docs.saltstack.com/ref/states/highstate.html#term-id-declaration).
The module php/init.sls contains only one ID Declaration : {pkg: php53u}. ID Declaration is composed of state name (pkg) and component name (php53u).
You can't require an entire module in salt, but in the last versions, modules will be executed in order of declaration, so the php module should be executed before the php-fm one. Salt will respect require requisite references in any cases.
Vocabulary in salt-stack could be a little difficult for beginners, here is a page which can helps you : http://docs.saltstack.com/ref/states/highstate.html.

Related

Symfony/Codeception Run Errors

I have a Symfony 2.4.4 site with simple Codeception (2.1.7) acceptance tests setup. When running the acceptance tests I get the following error:
[Codeception\Exception\ConfigurationException]
AcceptanceTester class doesn't exist in suite folder.
Run the 'build' command to generate it
The AcceptanceTester class does exist in the tests/acceptance directory. If I run a build I get the following error:
[Codeception\Exception\ConfigurationException]
Configuration file could not be found.
Run `bootstrap` to initialize Codeception.
The codeception.yml file does exist and contains the following:
actor: Tester
paths:
tests: tests
log: tests/_output
data: tests/_data
helpers: tests/_support
settings:
bootstrap: _bootstrap.php
colors: false
memory_limit: 1024M
coverage:
enabled: true
remote: true
include:
- app/*
exclude:
- app/cache/*
include:
...
modules:
config:
Db:
dsn: ''
user: ''
password: ''
dump: tests/_data/dump.sql
If I run a bootstrap it confirms this:
Project is already initialized in '.'
acceptance.suite.yml contains:
class_name: AcceptanceTester
modules:
enabled:
- AcceptanceHelper
Any suggestions?
AcceptanceTester.php file should be in tests/_support directory.
Run codecept build to regenerate Tester files.
You have no modules enabled acceptance.suite.yml.
You have to enable one of Symfony2, PhpBrowser and WebDriver.
Your site uses an old version of Symfony and it can cause issues for Codeception if Symfony2 module is used, so I recommend to test it using PhpBrowser or WebDriver.
I believe, you need to run command codecept bootstrap.
I had this problem, and I realise that I ran the codecept bootstrap but the vendor and the tests folders were in a wrong directory.
I followed this video and it helped me.

SaltStack error: could not cache the WAR file

Trying to deploy war file using tomcat module in salt.
Getting error as below
Salt Script
tomcat-server:
archive:
- extracted
- name: /opt/
- source: http://www.us.apache.org/dist/tomcat/tomcat-9/v9.0.0.M1/bin/apache-tomcat-9.0.0.M1.tar.gz
- source_hash: md5=e794b1c8a4d1427db42b3cc033e0ba2e
- archive_format: tar
- if_missing: /opt/apache-tomcat-9.0.0.M1/
tomcat_symlink:
file.symlink:
- name: /opt/tomcat
- target: apache-tomcat-9.0.0.M1
- require:
- archive: tomcat-server
deploy_war:
tomcat.war_deployed:
- name: /order-management
- war: salt://order-management.war
- require:
- file: /opt/tomcat
Not very sure what seems to be the issue. tried googling around but couldn't get anything concrete
As suggested by mootmoot ... Issue was war file not found ... I saw this : Could not find file from saltenv 'development', 'salt://order-management.war' . please check whether the war file is place under the salt:// folder (refer to your /etc/salt/master, files_root)

Configuration issue in behat

I use behat v3.0.15 and i want to put my features in the ./app/features reposistory.
As i can read in the documentation http://docs.behat.org/en/v3.0/guides/6.profiles.html#custom-autoloading all i have to do is to add theses lines in my behat.yml file
# behat.yml
default:
autoload:
'': %paths.base%/app/features/bootstrap
Sadly it doesn't work
When i try to init behat with this command ./bin/behat --config ./app/config/behat.yml --init, the program creates a features folder under the config folder.
So what can i do?
You've configured autoloader. Location of features is configured in paths section.
default:
autoload: %paths.base%/app/features/bootstrap
suites:
default:
paths:
- %paths.base%/app/features
Configuration of paths and autoloader is documented on different pages, so it's confusing. Behat 2.5 documentation is little better (but yaml structure is different).
Example is taken from feature test for custom paths
This is how you can define your customized php featureContext files:
autoload:
'': %paths.base%/features/bootstrap
suites:
default:
contexts:
-

Problems with basic usage of saltstack apache-formula

I'm new to Saltstack and I'm just trying to do some simple installs on a subset of minions. I want to include Environments so I have my file roots as:
file_roots:
base:
- /srv/salt/base
dev:
- /srv/salt/dev
qa:
- /srv/salt/qa
stage:
- /srv/salt/stage
prod:
- /srv/salt/prod
I set up the git backend:
fileserver_backend:
- git
- roots
I'm using gitfs set as:
gitfs_remotes:
- https://github.com/saltstack-formulas/postgres-formula
- https://github.com/saltstack-formulas/apache-formula
- https://github.com/saltstack-formulas/memcached-formula
- https://github.com/saltstack-formulas/redis-formula
So I have the master set up and I add top.sls to /srv/salt/stage with
include:
- apache
stage:
'stage01*':
- apache
But I get an error when I execute
salt -l debug \* state.highstate test=True
Error
stage01.example.net:
Data failed to compile:
----------
No matching sls found for 'apache' in env 'stage'
I've tried many ways and the master just can't seem to find the apache formula I configured for it.
I found the answer and it was sitting in the Saltstack docs the whole time.
First you will need to fork the current repository such as postgres-formula.
Depending on the environment create a branch of the same name in your newly create fork of the repo.
So for example I wanted to use postgres in my stage environment. So it wouldn't work until I created a branch named stage ined my forked repo of postgres-formula then it worked like a charm.

How to force pkgrepo refresh only one time per highstate?

I have a bunch of packages in a private debian repository. Following salt documentation (http://docs.saltstack.com/en/latest/ref/states/all/salt.states.pkgrepo.html), in a salt state I defined a pkgerepo entry like this:
my-private-repo:
pkgrepo.managed:
- hmanname: My Deb
- name: deb <url>....
- dist: my-repo
- require_in:
- pkg: pkg1
- pkg: pkg2
- pkg: ...
and in each pkg definition added the refresh: True stanza:
pkg1:
pkg:
- latest
- fromrepo: my-repo
- refresh: True
Now, it works in the sense that I get an "apt-get update" before installing (upgrading) each package, but there are quite a few of them (around 20) and I get an update for each one. Is there a way to have apt update just once after the repo state has been tested?
Helices and Antstud answers put me in the right direction. Anyway in the end I found out some interesting things that might be helpful for others:
"refresh: True" is useless with pkg.latest, seems like 'latest' implies "refresh: True"
What's stated in SaltStack doc seems not to apply (at last with version 2014.7.1)
require_in:
Set this to a list of pkg.installed or pkg.latest to trigger the running of apt-get update prior to attempting to install these packages. Setting a require in the pkg will not work for this.
I just added
- require:
- pkgrepo: my_repo
to my pkg definition and it's working (making includes less of a mess).
I believe you can just install multiple packages with a single state by using pkgs:. It works for me, even with a custom repository:
install packages:
pkg:
- latest
- fromrepo: my-repo
- refresh: True
- pkgs:
- pkg1
- pkg2
...
You can try to define pkg list in the pillars for every minion and than get the list in the state.
install packages:
pkg:
- latest
- fromrepo: my-repo
- refresh: True
- pkgs:
{% for pkg in pillar.get('packages', {}).items() %}
{{pkg}}
{% endfor %}

Resources