Hi Dave,

I use a single play to get an RDS endpoint and write database.yml. It uses 
`local_action` to delegate the rds facts lookup to localhost.

For the example that you've shared, it would look like the following:

- hosts: tag_class_apps
  become: yes
  become_user: "{{ app_user }}"
  gather_facts: False

  tasks:
    - local_action:
        module: rds
        command: facts
        region: "{{ region }}"
        instance_name: "{{ database_instance }}"
      register: db_facts

    - name: Update database.yml with current rds endpoint
      template:
        src:  ../roles/app_directories/templates/config/database.yml


I hope this is helpful.

-Baraa
      

On Friday, July 17, 2015 at 10:04:26 PM UTC-4, Dave Thomas wrote:
>
> I’d trying to get the database endpoint into a Rails database.ml file. I 
> know the RDS id, so I can get the endpoint using reds/command: facts.
>
> Unfortunately, the RDS play has to use localhost, while the template write 
> uses the actual target host.
>
> So far I’ve done it using
>
> - hosts:      localhost
>   connection: local
>   gather_facts: False
>   vars_files:
>     - ../ec2/ec2_params.yml
>
>   tasks:
>     - rds:
>         command:       facts
>         region:        "{{ region }}"
>         instance_name: "{{ database_instance }}"
>       register:        db_facts
>
>     - name: save remote host
>       copy:
>         content: "{{ db_facts.instance }}"
>         dest:    /tmp/db_facts
>
> - hosts: tag_class_apps
>   become: yes
>   become_user: "{{ app_user }}"
>   gather_facts: False
>
>   vars:
>      db_facts: "{{ lookup('file', '/tmp/db_facts')|from_json }}"
>
>   tasks:
>     - name: Update database.yml with current rds endpoint
>       template:
>         src:  ../roles/app_directories/templates/config/database.yml  # this 
> template uses db_facts.endpoint
>         dest: "{{ shared_path }}/config/database.yml"I can’t help feeling I’m 
> making this too complex. What should I be doing?
>
> I can't help feeling I'm making this too complicated. What magic am I 
> missing?
>
>
> Cheers
>
>
> Dave
> ​
>

-- 
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/2c4a80d0-0bcf-49bf-be07-b8723bc53b73%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to