How to pass ip-address from terraform to ansible

I found several articles and answers on the internet how to pass outputs from terraform to ansible ( But i still can’t pass ip-address of ec2 from terraform to ansible. For example (look below), Should i declare var.ip in file? terraform doesn’t accept var.ip without declaration. How to declare this variable if it is terraform output?

resource "local_file" "tf_ansible_vars_file_new" {
  content = <<-DOC
    tf_ip: ${var.ip}
  filename = "./tf_ansible_vars_file.yml"

I think you can get your IP address from your EC2 block instead of a static variable in case your IP is dynamically provisioned.

I found another solution how to do it. I used 1 provisioner local-exec. I created the 2nd provisioner, that creates a file with ip address, then my 2nd provisioner launches ansible cmd that uses a file with ip.