It's confirmed, if you set a variable on a playbook, and add_host and make 
new tasks, this variable is not "forwarded" to the next tasks

On Tuesday, May 8, 2018 at 5:04:03 PM UTC+2, David Villasmil wrote:
>
> Hello all,
>
> I've got a playbook that does:
>
> - name: Get db cluster endpoint
> shell: "aws --region=us-east-1 rds describe-db-clusters 
> --db-cluster-identifier {{ cluster }}-kam-db"
> register: aws_cluster_res
>
> - set_fact:
> myvar: "{{ aws_cluster_res.stdout | from_json }}"
>
> - set_fact:
> endpoint: "{{ myvar.DBClusters[0].Endpoint }}"
>
>
> and much later on:
>
> - replace:
> dest: /home/admin/myconfig.cfg
> regexp: '^(.*)!\{\{ DB_HOST \}\}(.*)$'
> replace: '\1!{{ endpoint }}\2'
>
> But ansible complaints that it is undefined, eve though it _has_ beed 
> defined:
>
> output:
>
> TASK [set_fact] 
> *************************************************************************************************************************************************************************
> task path: /home/admin/create_instances.yaml:107
> ok: [127.0.0.1] => {
>     "ansible_facts": {
>         "endpoint": "something.amazonaws.com"
>     },
>     "changed": false
> }
> Read vars_file 'vars/sts.yml'
> Read vars_file 'vars/default.yml'
>
>
> TASK [Print endpoint] 
> *******************************************************************************************************************************************************************
> task path: /home/admin/create_instances.yaml:110
> ok: [127.0.0.1] => {
>     "msg": "sonmething.amazonaws.com"
> }
>
>
>
> ....
>
>
> TASK [replace] 
> **************************************************************************************************************************************************************************
> task path: /home/admin/voice-conf/playbooks/create_instances.yaml:335
> fatal: [18.206.82.39]: FAILED! => {
>     "msg": "The task includes an option with an undefined variable. The 
> error was: 'endpoint' is undefined\n\nThe error appears to have been in 
> '/home/admin/create_instances.yaml': line 335, column 5, but may\nbe 
> elsewhere in the file depending on the exact syntax problem.\n\nThe 
> offending line appears to be:\n\n\n  - replace:\n    ^ here\n"
> }
> fatal: [18.206.108.97]: FAILED! => {
>     "msg": "The task includes an option with an undefined variable. The 
> error was: 'endpoint' is undefined\n\nThe error appears to have been in 
> '/home/admin/create_instances.yaml': line 335, column 5, but may\nbe 
> elsewhere in the file depending on the exact syntax problem.\n\nThe 
> offending line appears to be:\n\n\n  - replace:\n    ^ here\n"
> }
>
>
> I can't figure out why this is happening, can someone help?
>
> Thanks!
>
> David
>
>
>

-- 
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 ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/4d7ef400-818c-43fe-9959-d5e3f052bc19%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to