Re: [ansible-project] Having issue finding my hosts

96 views
Skip to first unread message
Message has been deleted

Brian Coca

unread,
Oct 25, 2017, 7:48:25 PM10/25/17
to Ansible Project
I think you are misusing the directives:

- hosts: /ansible/hosts <= this will NOT use that file as inventory
for the play.

The hosts keyword is supposed to be a 'pattern', not a file nor
inventory source.

to use that as your inventory you can do:
ansible-playbook /ansible/playbook/test.yml -i /ansible/hosts

and set hosts: to 'all'

- hosts: all


--
----------
Brian Coca
Message has been deleted

Jordan Borean

unread,
Oct 26, 2017, 3:57:42 PM10/26/17
to Ansible Project
YAML does not handle \ very well as it is an escaping character in most situations. When defining tasks I would highly recommend using the YAML for instead of the older key=arg form as it makes your code more readable and you don't have to escape \. Your task would now look like this

- name: Copies file to Windows
  win_copy:
    src: /ansible/ansible.cfg
    dest: C:\Users\YRunner\Desktop\test1

When using the YAML form, you don't need to escape \ unless you have double quoted the value. I found you don't need to quote a value unless you want to convert it to a string or it contains a :.


Thanks

Jordan

J Hawkesworth

unread,
Oct 26, 2017, 4:06:16 PM10/26/17
to Ansible Project
I think the \t in your path will be interpreted as a tab character, which is not valid in a Windows path.

It's best to use key: value syntax when working with Windows paths, rather than the key=value style.

Generally, for hard coded windows paths they will work fine if you use key: value and enter the path in single quotes.

Hope this helps,

Jon

Message has been deleted

Jordan Borean

unread,
Oct 26, 2017, 7:21:25 PM10/26/17
to Ansible Project
What I gave you is just the task to use in place of your win_copy one. You still need to specify the other playbook directives like hosts, tasks, roles and the like.

Thanks

Jordan
Message has been deleted

Zimidar Boy

unread,
Oct 30, 2017, 12:29:29 PM10/30/17
to Ansible Project
Hello Larry,
                   Any task in ansible comes under task module i think so your script will look like this:

- hosts: nuc

  tasks:

      - name: run simple script

        script: C:\Users\YRunner\Desktop\lp1.bat



On Friday, October 27, 2017 at 10:33:06 AM UTC-4, Larry Pescatore wrote:
HI Jordan, 
Thanks for your help. 
I've got it running now successfully. I have copied over a bat file successfully several times. 
Now, my next step is trying to get the batch files to run via ansible.
This is my play:

---

- hosts: nuc

- name: run simple script

  script: C:\Users\YRunner\Desktop\lp1.bat

When I run it I get:

root@Raspi_Ctrl:/ansible# ansible-playbook /ansible/playbook/test1.yml

ERROR! 'script' is not a valid attribute for a Play


The error appears to have been in '/ansible/playbook/test1.yml': line 3, column 3, but may

be elsewhere in the file depending on the exact syntax problem.


The offending line appears to be:


- hosts: nuc

- name: run simple script


  ^ here

So obv. That means I am using the wrong command. What is the right one?

--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/XEh1Fg3D9wE/unsubscribe.
To unsubscribe from this group and all its topics, 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/a99e8e5c-56fa-4ae2-80ab-16bafbaca778%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Thank you, 
Larry Pescatore
Lab Engineer, ERG Inc. @ Google
Reply all
Reply to author
Forward
Message has been deleted
0 new messages