Ask Your Question
0

file_line curl output

asked 2017-08-29 12:13:09 -0600

updated 2017-08-30 07:30:02 -0600

DarylW gravatar image

I need to add a file_line to a file with the return value from the curl output.

The code looks like this:

$curl_cmd = "curl \
--header \"X-Vault-Token: ${vault_root_token}\" \
--request POST \
--data @payload_${app_name}.json \
http://active.vault.service.consul:8200/v1/auth/token/create -o \"/opt/tech_admin/token_created_for_app.json\" | jq -r \'.auth.client_token\'"

And i have the file_line code as follows, not sure what to put in the file_line. It should actually contain the result obtained from the above curl command.

file { '/etc/profile.d/setenv.sh':
   ensure => present,
 } -> 
file_line {'Add vault token to env var':
   path => '/etc/profile.d',
    line => ??? ,
}
edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
0

answered 2017-08-30 07:33:45 -0600

DarylW gravatar image

updated 2017-08-30 07:34:13 -0600

The only way to get data into a catalog from a node is for either facter, hiera, or a custom resource to access it. Facter (via a custom fact), or hiera (via a backend) can make information available to the puppet master while it is compiling the catalog. A custom resource (type and provider) and do things on the node, and use that information within it's own definition.

If your curl command doesn't need to be run from that particular node, and you are only curling an external server, you can run any command from the puppet master and get it's output, using the [generate] (https://docs.puppet.com/puppet/latest...) function.

generate

Calls an external command on the Puppet master and returns the results of the command. Any arguments are passed to the external command as arguments. If the generator does not exit with return code of 0, the generator is considered to have failed and a parse error is thrown. Generators can only have file separators, alphanumerics, dashes, and periods in them. This function will attempt to protect you from malicious generator calls (e.g., those with ‘..’ in them), but it can never be entirely safe. No subshell is used to execute generators, so all shell metacharacters are passed directly to the generator.

edit flag offensive delete link more

Comments

Thank you very much for the detailed information. I need to run it from the node. I couldn't use a custom fact because I need values of few puppet variables to form the curl command.

Redsmile gravatar imageRedsmile ( 2017-08-31 11:30:39 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2017-08-29 12:13:09 -0600

Seen: 41 times

Last updated: Aug 30