标题基本上就是问题所在。我正在使用PostgreSQL8,并且想开始使用Saltstack状态来安装CentOS -13、AdoptOpenJDK等东西。
install-postgresql13-repository:
cmd.run:
- name: rpm -U --force https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm
install-postgresql13-server:
cmd.run:
- name: dnf install postgresql13-server -y
postgresql-first-run-init:
cmd.run:
- name: /usr/pgsql-13/bin/postgresql-13-setup initdb
- unless: stat /var/lib/pgsql/13/data/postgresql.conf
- runas: root
start-postgresql13-server:
cmd.run:
- name: systemctl start postgresql-13
enable-postgresql13-autostart:
cmd.run:
- name: systemctl enable postgresql-13但据我所知,cmd.run不是最好的选择。
发布于 2020-10-16 00:25:38
使用像Saltstack这样的工具的主要好处是它通过“状态”的方式提供的幂等性。
在没有深入了解完整解决方案的情况下,我建议您使用Salt states。
例如,下面的代码在第一次运行时运行良好,但在第二次运行时可能会出现错误。即使它起作用了,也是不必要的。
cmd.run:
- name: rpm -U --force https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm然而,如果您使用如下所示的Salt state模块,它们将仅在需要时更新。后续运行将不会尝试进行更改。
install-postgresql13-repository:
pkg.installed:
- sources:
- pgdg-redhat-repo: https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm
install-postgresql-server:
pkg.installed:
- name: postgresql13-server
# and similarly use salt states for other tasks where applicablehttps://stackoverflow.com/questions/64352921
复制相似问题