using variable from another file

19 views
Skip to first unread message

Noctis Geek

unread,
Aug 6, 2019, 10:42:26 AM8/6/19
to Ansible Project

Hello, I would like to know the syntax that would allow me to retrieve the contents of a file and use it to make a variable in a new file in my example I have my YAML configuration file and I have a VARIABLE file and I do not know how to get my first line and make it a variable in my 1st file




############ config.yml ############
---
- hosts: my-computer
  remote_user: toto
  tasks:

-vars:
   - my-first-vars: {{ THIS IS VARS }}

- name: "config host"
   lineinfile:
   path: /etc/file.cfg
   regexp: '(.*)this_to_change_with_vars(.*)'
   line: '{{ my-first-vars }}'

########### file.vars #########

THIS IS VARS : 10.10.10.10
THIS IS OTHER VARS: 10.10.9.9

Sebastian Meyer

unread,
Aug 6, 2019, 10:44:11 AM8/6/19
to ansible...@googlegroups.com
On 06.08.19 16:42, Noctis Geek wrote:
>
> Hello, I would like to know the syntax that would allow me to retrieve the
> contents of a file and use it to make a variable in a new file in my
> example I have my YAML configuration file and I have a VARIABLE file and I
> do not know how to get my first line and make it a variable in my 1st file
>

See:

https://docs.ansible.com/ansible/latest/user_guide/playbooks_variables.html#defining-variables-in-files

Sebastian

--
Sebastian Meyer
Linux Consultant & Trainer
Mail: me...@b1-systems.de

B1 Systems GmbH
Osterfeldstraße 7 / 85088 Vohburg / http://www.b1-systems.de
GF: Ralph Dehner / Unternehmenssitz: Vohburg / AG: Ingolstadt,HRB 3537


-- Deutsche OpenStack Tage 2019 -- 10% Rabatt auf den Ticketpreis ----
------------------------ https://openstack-tage.de (Code DOST-B1) ----

Noctis Geek

unread,
Aug 6, 2019, 10:48:03 AM8/6/19
to Ansible Project
thanks for this, but if i come here it's for get help, i already read the doc

Philippe Eveque

unread,
Aug 7, 2019, 8:10:53 AM8/7/19
to ansible...@googlegroups.com
So Sebastian did provide the answer and help ;-)

Hint: read the vars_files in the the provided links 

Phil

Le mar. 6 août 2019 à 16:48, Noctis Geek <medidou...@gmail.com> a écrit :
thanks for this, but if i come here it's for get help, i already read the doc

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/deca4b2e-376b-475a-81c1-734b3b107e3c%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages