chef [SOLVED]: How can a node read a role file?

chef [SOLVED]: How can a node read a role file?

Home Forums Automation Tools Chef Tutorials chef [SOLVED]: How can a node read a role file?

Tagged: ,

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #205396

    Cloudy Point
    Keymaster

    QuestionQuestion

    Say we have a node named mycomputer. And it has a role in it’s run_list say myrole.

    Now, the mycomputer wants to access and read the role file which is present in it’s run_list.

    Is there a way to do this ?


    I tried

    knife role show myrole
    

    As it doesn’t have knife.rb and user-key.pem file (.chef directory) so it cannot access it.


    Please let me know if there is a way to access the role file viz. myrole.

    #205397

    Cloudy Point
    Keymaster

    Accepted AnswerAnswer

    As you write that the node “mycomputer” has the given role in its run list applied, the contained information is kind of “automatically” available. To be precise, the attributes (and additional run list entries) are automatically merged with other attributes (from environments, cookbooks, etc).

    So if your role “myrole” defines the following attributes:

    default_attributes 'apache2' => {
      'listen_ports' => [ '80', '443' ]
    }
    

    this will be accessible during the chef run on your node via

    node['apache2']['listen_ports']
    

    Attributes are fundamental concept of chef and should solve your problem to define some information in a role and read it during the chef run on some node.

    You find more information about that concept in the docs about Attribute Precedence. There’s not really a way to read the plain file – if you really think you need to do so, you’re using Chef in a wrong way. Better state with your next question, what your ultimate goal is.

    Source: https://stackoverflow.com/questions/46677666/how-can-a-node-read-a-role-file
    Author: StephenKing
    Creative Commons License
    This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.