Skip to content

Conversation

@noelmcloughlin
Copy link
Contributor

This PR fixes #186 finally.

All postgres_database.present states need a fcontext. This example from pillar.example ....

  # tablespaces to be created
  tablespaces:
    my_space:
      directory: /srv/my_tablespace            #<== new directory ....
      owner: localUser

  databases:
  ...
    db2:
      owner: 'remoteUser'
      template: 'template0'
      lc_ctype: 'en_US.UTF-8'
      lc_collate: 'en_US.UTF-8'
      tablespace: 'my_space'        #<== `postgres_database.present` will fail

Verified on Centos7 with selinux enforcing

ID: postgresql-tablespace-dir-my_space
    Function: file.directory
        Name: /srv/bob/my_tablespace
      Result: True
     Comment: Directory /srv/bob/my_tablespace is in the correct state
              Directory /srv/bob/my_tablespace updated
     Started: 13:13:06.584321
    Duration: 78.609 ms
     Changes:
----------
          ID: postgresql-tablespace-dir-my_space
    Function: pkg.installed
        Name: policycoreutils-python
      Result: True
     Comment: All specified packages are already installed
     Started: 13:13:06.663076
    Duration: 0.504 ms

          ID: postgresql-tablespace-dir-my_space
    Function: pkg.installed
        Name: selinux-policy-targeted
      Result: True
     Comment: All specified packages are already installed
     Started: 13:13:06.663680
    Duration: 0.37 ms
     Changes:
----------
          ID: postgresql-tablespace-dir-my_space
    Function: selinux.fcontext_policy_present
        Name: /srv/bob/my_tablespace(/.*)?
      Result: True
     Comment: SELinux policy for "/srv/bob/my_tablespace(/.*)?" already present with specified filetype "all files" and sel_type "postgresql_db_t".
     Started: 13:13:06.664657
    Duration: 175.454 ms
     Changes:
----------
          ID: postgresql-tablespace-dir-my_space-fcontext
    Function: selinux.fcontext_policy_applied
        Name: /srv/bob/my_tablespace
      Result: True
     Comment: SElinux policies are already applied for filespec "/srv/bob/my_tablespace"
     Started: 13:13:06.840530
    Duration: 11.444 ms

Solves the problem

          ID: postgres_database-db2
    Function: postgres_database.present
        Name: db2
      Result: True
     Comment: Database db2 is already present

@noelmcloughlin
Copy link
Contributor Author

Complimented by saltstack/salt#50045

{% endif %}
{% do postgres.update({'prepare_cluster_cmd': pc_cmd}) %}

{# handle selinux enforcing #}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not base it on the grains on the system:

sudo salt-call grains.item selinux
local:
    ----------
    selinux:
        ----------
        enabled:
            True
        enforced:
            Enforcing

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Which grain?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@noelmcloughlin : selinux:enforced

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry okay, there is selinux grain. good idea.

@noelmcloughlin
Copy link
Contributor Author

@aboe76 this is ready now (and much cleaner solution). Thanks.

ID: postgresql-tablespace-dir-my_space-fcontext
    Function: selinux.fcontext_policy_applied
        Name: /srv/my_tablespace
      Result: True
     Comment: 
     Started: 14:52:36.776389
    Duration: 48.675 ms
     Changes:   
              ----------
              /srv/my_tablespace:
                  ----------
                  new:
                      ----------
                      sel_type:
                          postgresql_db_t
                  old:
                      ----------
                      sel_type:
                          var_t

@aboe76 aboe76 merged commit 7cb86d1 into saltstack-formulas:master Oct 18, 2018
@noelmcloughlin noelmcloughlin deleted the fixes branch October 18, 2018 20:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

postgres_tablespace.present noisy error

2 participants