I have a playbook with is creating vms and then i want to add the ip 
address to the inventory file to when it comes time to provision i can just 
call the updated inventory file. lineinfile will only add to the found 
lines at the end of the file. replace will update all the matches. What is 
the recommended way to do this?


===playbook===
---
- name: create instances
  hosts: all
  gather_facts: no
  connection: local
  sudo: no
  tasks:
    - name: "create instance and assign floating-ip (if available)"
      os_server:
       state: present
       auth:
         auth_url: http://10.10.81.227:5000/v2.0
         username: "{{openstack_username | mandatory }}"
         password: "{{openstack_password | mandatory }}"
         project_name: cups
       name: "{{ inventory_hostname | mandatory }}"
       image: "{{ openstack_image | mandatory }}"
       key_name:  "{{ openstack_key_name | mandatory }}"
       flavor: "{{ openstack_flavor | mandatory }}"
      register: result
      
    - debug: var=result
    
    - debug: var=inventory_hostname

    
    - lineinfile: backrefs=yes state=present  dest="{{inventory_dir}}/test" 
regexp='{{inventory_hostname}}\s' line='{{inventory_hostname}} 
ansible_ssh_host={{result.openstack.accessIPv4}}'
      
===inventory file====
[tomcat]
tomcat

[jenkins]
jenkins

[downloads]
downloads

[project:children]
tomcat
jenkins
downloads

[cups:vars]
ansible_ssh_user=centos



-- 
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 post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/dc0ffdd5-4ce6-4254-8284-058d7d6563cd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to