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:


errors I am getting:

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

Can anyone help me with this ?

Jun 22, 2018 in DevOps Tools by Damon Salvatore
• 5,540 points

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
• 51,830 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,250 points
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,850 points
0 votes
1 answer
0 votes
1 answer

How to get the current status of a local repository in Git?

Using 'git status' command in the repository ...READ MORE

answered Nov 26, 2019 in DevOps Tools by Sirajul
• 50,310 points
+13 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 26, 2018 in DevOps & Agile by DragonLord999
• 8,400 points
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
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
• 51,830 points