这是我action :create
的自定义 LWRP,但它始终运行。我想做一个幂等动作。
这是我的实现:
action :create do
converge_by "Create [#{@new_resource}]" do
USER_NAME = @new_resource.username
USER_PASSWORD = @new_resource.password unless (@new_resource.password.nil? ||
@new_resource.password.empty?)
USER_PASSWORD = USER_NAME
DATABASE_NAME = @new_resource.database_name unless (@new_resource.database_name.nil? ||
@new_resource.database_name.empty?)
DATABASE_NAME = USER_NAME
execute "create user [#{USER_NAME}]" do
user "postgres"
exists = <<-EOH
PGPASSWORD='postgres' psql -U postgres -c "select * from pg_user where usename='#{USER_NAME}'" | grep -c #{USER_NAME}
EOH
command "PGPASSWORD='postgres' createuser -U postgres -sw #{USER_NAME}"
not_if exists, :user => "postgres"
end
execute "set-password" do
user "postgres"
command "PGPASSWORD='postgres' psql -U postgres -c \"alter role #{USER_NAME} with password '#{USER_PASSWORD}'\""
end
execute "create-database" do
user "postgres"
exists = <<-EOH
PGPASSWORD='postgres' psql -U postgres -c "select * from pg_database WHERE datname='#{DATABASE_NAME}'" | grep -c #{DATABASE_NAME}
EOH
command "PGPASSWORD='postgres' createdb -U postgres -O #{USER_NAME} -T template0 #{DATABASE_NAME}"
not_if exists, :user => "postgres"
end
end
@new_resource.updated_by_last_action(true)
end
为什么最后一行不起作用@new_resource.updated_by_last_action(true)
?