Getting Error when trying to print IP to a file with terraform local-exec

0 votes

I am trying to print , private ip of the newly created instances into a host file locally where i run terraform from, to use it for ansible,but terraform is throwing errors, each time I modify my escape characters in the local-exec echo command.

here is the snippet where i am getting error:

 provisioner "local-exec"
{
command = " echo \"[servers]\["${aws_instance.seeds.*.private_ip}"\]\" >> /ec2-ansible/hosts"
}

expected output in the hosts file:

[servers]
ip1
ip2
ip3

errors I am getting:

Failed to load root config module: Error parsing /root/ec2-ansible/main.tf: At 33:1: expected: IDENT | STRING | ASSIGN | LBRACE got: RBRACE
Failed to load root config module: Error parsing /root/ec2-ansible/main.tf: At 29:25: illegal char

Can anyone help me with this ?

Jun 22, 2018 in DevOps Tools by Damon Salvatore
• 5,980 points
1,820 views

1 answer to this question.

0 votes

I think you go in the wrong direction for using both terraform and ansible.

In ansible, you can use Dynamic Inventory to get the host information such as private IPs easily from their tags, size, ami id, etc.

In terraform, if you need the state details and feed to ansible, recommend using terraform output to collect the information.

answered Aug 2, 2018 by Kalgi
• 52,350 points

Related Questions In DevOps Tools

0 votes
1 answer

Getting an Error while trying to push changes to cloud foundry

Here is an approach which you can ...READ MORE

answered Jul 19, 2018 in DevOps Tools by Atul
• 10,240 points
2,075 views
0 votes
1 answer

How to filter IP from a log file using Logstash?

Hi@akhtar, You can use the filter plugin in Logstash. It ...READ MORE

answered Jun 18, 2020 in DevOps Tools by MD
• 95,460 points
1,444 views
0 votes
1 answer

dpkg a deb file in a local fodler on vagrant

Copy the file in the vagrant folder ...READ MORE

answered Jun 14, 2018 in DevOps Tools by DareDev
• 6,890 points
660 views
+15 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 27, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
4,025 views
+2 votes
1 answer
+1 vote
2 answers

Trying to make a PHP code work in bluemix

example to @Nilesh's explanation: $html = '<html> ...READ MORE

answered Oct 25, 2018 in DevOps Tools by akaash
785 views
0 votes
1 answer

How to manage multiple components with IBM Bluemix Track & Plan

As of now, there is not a ...READ MORE

answered Jul 6, 2018 in DevOps Tools by Kalgi
• 52,350 points
574 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP