Cloudformation module does not read the template file with .json extension

125 views
Skip to first unread message

Bhotu

unread,
Feb 1, 2016, 2:57:40 PM2/1/16
to Ansible Project

I am working with the following script and I have got an error. Saying that your file is not found. Although my file is already there. 


What could be the possible problem ?


Script:

.....

cas_cloud.yml

--------------


---

- name: Create Cloudformation Template for Cassandra Servers

  hosts: awsserver

  gather_facts: no

  tasks:

     - name: Cloudformation | Cloudformation template location

       command: "echo /Users/suthata/Downloads/playbooks/ansible/cassandra.json"

       register: template_location

 

     - name: Cloudformation | Full path to cloudformation template

       debug: var=template_location.stdout

 

     - name: Cloudformation | Use the module cloudformation

       cloudformation:

         stack_name: "imdev-omniavpc-securitygroup"

         state: "present"

         region: "us-east-1"

         template: cassandra.json

       args:

         template_parameters:

           Environment: "imdev"

           VpcCidr: "10.123.0.0/16"

           VpcId: "vpc-4ec51e1b"

           VpcName: "omniavpc"

         tags:

           revision: "1.0"

           type: "security group"

 

Output:



PLAY [Create Cloudformation Template for Cassandra Servers] ********************

 

TASK [Cloudformation | Cloudformation template location] ***********************

changed: [52.90.52.201]

 

TASK [Cloudformation | Full path to cloudformation template] *******************

ok: [52.90.52.201] => {

    "changed": false,

    "template_location.stdout": "/Users/suthata/Downloads/playbooks/ansible/cassandra.json"

}

 

TASK [Cloudformation | Use the module cloudformation] **************************

fatal: [52.90.52.201]: FAILED! => {"changed": false, "failed": true, "msg": "Traceback (most recent call last):\r\n  File \"/home/ec2-user/.ansible/tmp/ansible-tmp-1454356045.33-97534776320654/cloudformation\", line 2535, in <module>\r\n    main()\r\n  File \"/home/ec2-user/.ansible/tmp/ansible-tmp-1454356045.33-97534776320654/cloudformation\", line 273, in main\r\n    template_body = open(module.params['template'], 'r').read()\r\nIOError: [Errno 2] No such file or directory: 'cassandra.json'\r\n", "parsed": false}

 

PLAY RECAP *********************************************************************

52.90.52.201               : ok=2    changed=1    unreachable=0    failed=1   

Brian Coca

unread,
Feb 1, 2016, 3:45:42 PM2/1/16
to Ansible Project
where is the file cassandra.json? what directory and which machine
(the one executing ansible or the target)?

also note that:
command: "echo /Users/suthata/Downloads/playbooks/ansible/cassandra.json"

does not test that the file is there, it just prints out the path.



--
Brian Coca

Bhotu

unread,
Feb 1, 2016, 3:52:03 PM2/1/16
to Ansible Project
Hi Brian,

I have tried the "cassandra.json" file with the following paths:

/Users/suthata/Downloads/playbooks/ansible/cassandra.json
and /Users/suthata/Downloads/playbooks/cassandra.json...Still no directory found error. 

I am running ansible on following path: /Users/suthata/Downloads/playbooks/ansible/cas_cloud.yml...

Brian Coca

unread,
Feb 1, 2016, 4:31:41 PM2/1/16
to Ansible Project
you did not respond the other 1/2 of the question, is the file on the
machine you are executing ansible on or on the 'target'?
> --
> 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-proje...@googlegroups.com.
> To post to this group, send email to ansible...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/5886ebdf-a54d-49b0-b697-990e56a33db9%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.



--
Brian Coca
Message has been deleted

Bhotu

unread,
Feb 1, 2016, 4:38:46 PM2/1/16
to Ansible Project
I am executing the cloud formation template file on the remote machine or i want to implement all the resource on the remote machine from the template itself. Path I have set up is on the local side and it will implement it on the remote side. 

Brian Coca

unread,
Feb 1, 2016, 4:45:38 PM2/1/16
to Ansible Project
that is your problem, the module executes on the remote machine, the
file is not there, you can either make it a 'local_action' as this is
an API call and should work from any machine. But if you need to run
it from THAT specific machine you'll need to copy the file to it
first.



--
Brian Coca
Message has been deleted

Bhotu

unread,
Feb 1, 2016, 5:05:25 PM2/1/16
to Ansible Project
Here I have modified. Now getting some other error.

---

- name: Create Cloudformation Template for Cassandra Servers

  hosts: awsserver

  sudo: yes

  gather_facts: no

  tasks:

    - name: Cloudformation | Use the module cloudformation

      local_action:

        module: cloudformation

        stack_name: "imdev-omniavpc-securitygroup"

        region: "us-east-1"

        state: "present"

        template: "cassandra.json"

      #  template_format: "json"

        template_parameters:

          Environment: "imdev"

          VpcCidr: 10.123.0.0/16

          VpcId: "vpc-4ec48e2b"

          VpcName: "omniavpc"

        tags:

          revision: "1.0"

          type: "security group"

Output:

PLAY [Create Cloudformation Template for Cassandra Servers] ********************

 

TASK [Cloudformation | Use the module cloudformation] **************************

fatal: [52.90.239.23 -> localhost]: FAILED! => {"changed": false, "failed": true, "msg": "No handler was ready to authenticate. 1 handlers were checked. ['HmacAuthV4Handler'] Check your credentials"}

Brian Coca

unread,
Feb 1, 2016, 5:15:24 PM2/1/16
to Ansible Project
That seems to be an issue with cloud authentication, are you setup on
the machine you run ansible from?


--
Brian Coca

Bhotu

unread,
Feb 1, 2016, 5:26:03 PM2/1/16
to Ansible Project
Yes. I have exported the environment variable AWS_ACCESS_KEY and AWS_SECRET_ACCESS_KEY for my remote AWS machine. Earlier it was "boto" error. Now it is showing the credential error. What could be the possible problem ? 

Brian Coca

unread,
Feb 1, 2016, 5:59:16 PM2/1/16
to Ansible Project
if you export them on the remote machine, you won't have them on the local one

boto is a required library for the module and MUST be present on the
machine you execute the module on.

There are always 2 machines involved with ansible tasks, the machine
you run 'ansible' on and the machine that runs the task itself.
normally the task runs on the remote target, exceptions to this are
when targeting localhost or using 'local_action/delegate_to: localhost
or connection: local'

You seem to be confusing both hosts, I believe you want to execute the
cloudformation task (really an API call) for the target host but it
should run on your ansible 'master'. You need boto and authentication
working on that machine.


--
Brian Coca

Bhotu

unread,
Feb 1, 2016, 6:10:27 PM2/1/16
to Ansible Project
Perfect. Now its done it successfully. Thanks for your help. Really appreciate...!!!!
Reply all
Reply to author
Forward
0 new messages