我从and运行ls
命令,但得到不同的结果:ssh
ansible
SSH:
mysystem:~$ ssh host5 -l user1 "ls -l /tmp/repos*"
-rw-r--r--. 1 root root 54936 Feb 16 22:00 /tmp/repos.yml
mysystem:~$
Ansible 即席
mysystem:~$ ansible hostlist -i ~/usr/ansible/hosts -m command -a "ls -l /tmp/repos*"
host6 | FAILED | rc=2 >>
ls: cannot access /tmp/repos*: No such file or directorynon-zero return code
host3 | FAILED | rc=2 >>
ls: cannot access /tmp/repos*: No such file or directorynon-zero return code
host5 | FAILED | rc=2 >>
ls: cannot access /tmp/repos*: No such file or directorynon-zero return code
host4 | FAILED | rc=2 >>
ls: cannot access /tmp/repos*: No such file or directorynon-zero return code
host1 | FAILED | rc=2 >>
ls: cannot access /tmp/repos*: No such file or directorynon-zero return code
mysystem:~$
我的主机文件:
mysystem:~$ cat ~/usr/ansible/hosts
[all:vars]
ansible_user=user1
[hostlist]
host1
host3
host4
host5
host6
问题1:我知道我正在尝试使用root
用户访问文件,但是应该可以user1
使用 ansible 进行访问,因为那里也使用了 SSH(我的理解)。为什么会有这种行为?
问题2:为什么ansible没有按照文件中提到的顺序运行~/usr/ansible/hosts
?