Chef infra 使用厨师食谱识别PostgreSQL版本
是否可以在chef中的recipes中识别数据库服务器上运行的PostgreSQL版本 现在我可以使用awk命令识别它 例如:Chef infra 使用厨师食谱识别PostgreSQL版本,chef-infra,chef-recipe,Chef Infra,Chef Recipe,是否可以在chef中的recipes中识别数据库服务器上运行的PostgreSQL版本 现在我可以使用awk命令识别它 例如: [postgres@hostname]$ ps -aux | grep postgres psharm89 39532 0.0 0.0 112644 960 pts/2 S+ 12:31 0:00 grep -- color=auto postgres postgres 56958 0.0 0.9 2345396 77444 ?
[postgres@hostname]$ ps -aux | grep postgres
psharm89 39532 0.0 0.0 112644 960 pts/2 S+ 12:31 0:00 grep -- color=auto postgres
postgres 56958 0.0 0.9 2345396 77444 ? S May21 1:10 /opt/postgres/9.5/bin/postgres -D /opt/pgdata/9.5/data
postgres 56959 0.0 0.0 166416 1836 ? Ss May21 0:57 postgres: logger process
postgres 56961 0.0 2.1 2347908 173768 ? Ss May21 0:45 postgres: checkpointer process
postgres 56962 0.0 0.2 2345412 21096 ? Ss May21 0:14 postgres: writer process
postgres 56963 0.0 0.2 2345352 18284 ? Ss May21 0:25 postgres: wal writer process
postgres 56964 0.0 0.0 2345788 2820 ? Ss May21 1:14 postgres: autovacuum launcher process
postgres 56965 0.0 0.0 168668 2156 ? Ss May21 2:22 postgres: stats collector process
[postgres@hostname]$ PGHOME=$(ps -aux | grep postgres | grep -- -D |grep -v grep |awk '{NF=NF-2;print $NF}'|awk -F"/bin" '{print $1}')
[postgres@hostname]$ PGVER=$(/bin/basename $PGHOME)
[postgres@hostname]$ echo $PGVER
9.5
但是,类似地,我需要在chef中查找配方,以便创建变量PGVER=9.5,并在postgresql数据库配置配方中使用它。这通常不是使用chef的方式。Chef将是强制使用哪个版本的Postgres的东西 但如果你必须这样做,你可以这样做:
pgver = shell_out!('ps -aux').stdout[%r{postgres/(9\.\d+)/bin}, 1]
这主要是将字符串解析移到Ruby而不是Bash中,但基本思想相同