why dont you..concatenate strings to a list and then join the list instead 
to make the string?


On Monday, March 20, 2017 at 11:02:39 AM UTC-4, [email protected] 
wrote:
>
> I need to save two 2 IPs to a variable in a vars_file when launching 
> ec2_instances, which are used later during deployment.
>
>
> This is how I am saving a single server ip:
>
>
> - name: Save server public IP to vars file
>   lineinfile: line="server_public_ip{{':'}} {{ item.public_ip }}"
>               dest="{{ansible_env.HOME}}/dynamic_ips_{{ec2_environment}}"
>   with_items: server.instances  #server is registered in previous task
>
>
> The output I have in dynamic_ips file is *server_public_ip: xxx.xxx.xx.x*
>
>
> Now I have 2 servers launched and registered as servers.
>
>
> I need to save this as *server_public_ips: xxx.xx.x.xx , xxx.x.xx.x*
>
>
> I tried to declare an empty string and append ips to it, something like 
> this, but I am getting errors.
>
>
> set_fact:
>    ips: ""
> set_fact:
>    ips: " {{ ips }} + {{ item.public_ip}} "
> with_items: servers.instances  #servers is registered in previous task
> lineinfile: line="server_public_ips{{':'}} {{ ips }}"
>             dest="{{ansible_env.HOME}}/dynamic_ips_{{ec2_environment}}"
>
>
> I think it can be done using lineinfile insertafter and regex.
>
>
> Finally, I need this to do this in a different server,
>
>
> - name: Restrict access to outside world
>   command: iptables INPUT {{ item }} ACCEPT
>   with_items: {{ server_public_ips }}.split(,) #grant access for each ip 
>   command: iptables INPUT DROP
>
>

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/782f65bb-8e06-45cc-b023-cebd47cc6e6e%40googlegroups.com.

Reply via email to