Is it possible cat files role in ansible? my defaults/main.yml is :

srv1: webserver
srv2: db
srv3: dns

I want cat defaults/main.yml and register in a variable.

  • By register, do you mean to register the file contents as ansible variables or just the file as it is? – man0v Feb 19 '18 at 8:39
  • register the file contents as ansible variables – pyramid13 Feb 19 '18 at 8:46
  • You could use the command module with the options once: true and delegate_to: localhost, so that the cat command is only executed once on the host running Ansible (where the file is probably located?). But these variables seem to be more suited to be put in the host_vars directory or to be turned into groups with the respective servers in them? What exactly do you want to do with the variables afterwards? – Sethos II Feb 19 '18 at 9:37
  • Lookup function is for you... – MUY Belgium Mar 2 at 15:16

It's not exactly what you are looking for(in terms of cat) but if you want to include the variables in the playbook you can use include_vars:

- name: get me some vars
    file: your_file.yml
    name: your_var

this will make your variables accessible at your_var (your_var['srv1'] will be webserver)

According to the documentation, if you miss the name parameter the variables will be included at top level scope.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.