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,490 points
165 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
• 37,320 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
104 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,810 points
38 views
0 votes
1 answer
0 votes
1 answer
+13 votes
2 answers
0 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
23 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
• 37,320 points
41 views