I cant create a simple .txt file using ansible.

57 views
Skip to first unread message

Muhammad Mahir

unread,
Dec 4, 2017, 3:38:03 AM12/4/17
to Ansible Project
Hello there,

I just want to test my script if it creates a simple .txt file into a destination put instead it is creating that same file into the source vm that is where the ansible is installed. 

Here is the simple script I'm running.

---

- hosts: Cassandra
  remote_user: murtaza
  connection: local
  sudo: yes
  tasks:
       - name: Create an empty file with name myfile.txt
         shell: touch myfile.txt state=touch

Output :-

[DEPRECATION WARNING]: Instead of sudo/sudo_user, use become/become_user and 
make sure become_method is 'sudo' (default). This feature will be removed in 
version 2.6. Deprecation warnings can be disabled by setting 
deprecation_warnings=False in ansible.cfg.

PLAY [Cassandra] ***************************************************************

TASK [Gathering Facts] *********************************************************
ok: [10.0.0.243]

TASK [Create an empty file with name myfile.txt] *******************************
 [WARNING]: Consider using file module with state=touch rather than running
touch

changed: [10.0.0.243]

PLAY RECAP *********************************************************************
10.0.0.243                 : ok=2    changed=1    unreachable=0    failed=0  

This shows that it is creating and doing the job all right. But still when I ssh into 10.0.0.243 it doesnt create any .txt file with this name but instead creates the file into the source where the ansilbe is installed.

Please have a look into this issue

Kai Stian Olstad

unread,
Dec 4, 2017, 3:43:00 AM12/4/17
to ansible...@googlegroups.com
On 04.12.2017 09:38, Muhammad Mahir wrote:
> Hello there,
>
> I just want to test my script if it creates a simple .txt file into a
> destination put instead it is creating that same file into the source
> vm that is where the ansible is installed.
>
> Here is the simple script I'm running.
>
> ---
>
> *- hosts: Cassandra*
> * remote_user: murtaza*
> * connection: local*

That's because of the connection line
http://docs.ansible.com/ansible/latest/playbooks_delegation.html#local-playbooks


--
Kai Stian Olstad

Muhammad Mahir

unread,
Dec 4, 2017, 7:03:57 AM12/4/17
to Ansible Project
Thank you so much for your reply.

I've got your point and have removed connection: local from my playbook. But after that a new output appears this time.

[DEPRECATION WARNING]: Instead of sudo/sudo_user, use become/become_user and 
make sure become_method is 'sudo' (default). This feature will be removed in 
version 2.6. Deprecation warnings can be disabled by setting 
deprecation_warnings=False in ansible.cfg.

PLAY [Cassandra] ***************************************************************

TASK [Gathering Facts] *********************************************************
fatal: [10.0.0.243]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: Permission denied (publickey,password).\r\n", "unreachable": true}
to retry, use: --limit @/etc/ansible/playbooks/cassandra-playbook.retry

PLAY RECAP *********************************************************************
10.0.0.243                 : ok=0    changed=0    unreachable=1    failed=0 

although when I ping 10.0.0.243 it perfectly connects. what can be the issue

Dick Visser

unread,
Dec 4, 2017, 10:33:38 AM12/4/17
to ansible...@googlegroups.com
Your comment "it perfectly connects" indicates you used ansible -m
ping, but the authentication error suggests you did ICMP ping.

So, which ping did you use?


Thanks

DIck
> --
> 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/346e4fca-e340-486e-9312-45e3e46ef47a%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.



--
Dick Visser
GÉANT

Want to join us? We're hiring: https://www.geant.org/jobs

Muhammad Mahir

unread,
Dec 5, 2017, 2:52:52 AM12/5/17
to Ansible Project
I'am using "ansible cassandra -m ping " or "ansible all -m ping " and is can easily ssh also but the moment I run the playbook it shows me this error.
Reply all
Reply to author
Forward
0 new messages