我在 Linux 机器上使用ansible-2.0
并创建ansible-galaxy
,在它上创建了dns.yml
替换/etc/resolv.conf
远程机器上的文件,但它不起作用。 Ansible 状态显示OK
.
dns.yml
---
- name: place dns configuration
become: true
template:
src: resolv.conf.j1
dest: /tmp/resolv.conf
输出 :
....
TASK [lab : include ansible related tasks] *************************************
included: /home/adminto/ansible/lab/tasks/dns.yml for pc1
TASK [lab : place dns configuration] *******************************************
ok: [pc1]
PLAY RECAP *********************************************************************
as : ok=3 changed=0 unreachable=0 failed=0
mypc# : ~/ansible$ ansible all -i 'pc1,' -c local -m ping
as | SUCCESS => {
"changed": false,
"ping": "pong"
`enter code here`}
深度视图中的错误:
admin:~/ansible$ sudo ansible-playbook -i "pc1," lab-data.yml -t dns.yml -vvvv
Using /etc/ansible/ansible.cfg as config file
Loaded callback default of type stdout, v2.0
1 plays in lab-push.yml
PLAY ***************************************************************************
TASK [setup] *******************************************************************
<pc1> ESTABLISH SSH CONNECTION FOR USER: None
<pc1> SSH: EXEC ssh -C -vvv -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/home/adminto/.ansible/cp/ansible-ssh-%h-%p-%r -tt as '( umask 22 && mkdir -p "$( echo $HOME/.ansible/tmp/ansible-tmp-1487592713.4-221225682479967 )" && echo "$( echo $HOME/.ansible/tmp/ansible-tmp-1487592713.4-221225682479967 )" )'
<pc1> PUT /tmp/tmpPNuqMM TO /home/admin/.ansible/tmp/ansible-tmp-1487592713.4-221225682479967/setup
<pc1> SSH: EXEC sftp -b - -C -vvv -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/home/adminto/.ansible/cp/ansible-ssh-%h-%p-%r '[as]'
<pc1> ESTABLISH SSH CONNECTION FOR USER: None
<pc1> SSH: EXEC ssh -C -vvv -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/home/adminto/.ansible/cp/ansible-ssh-%h-%p-%r -tt pc1 'LANG=en_IN LC_ALL=en_IN LC_MESSAGES=en_IN /usr/bin/python /home/admin/.ansible/tmp/ansible-tmp-1487592713.4-221225682479967/setup; rm -rf "/home/admin/.ansible/tmp/ansible-tmp-1487592713.4-221225682479967/" > /dev/null 2>&1'
ok: [pc1]
TASK [lab : include ansible related tasks] *************************************
task path: /home/adminto/ansible/lab/tasks/main.yml:1
included: /home/adminto/ansible/lab/tasks/dns.yml for pc1
pc1 : ok=2 changed=0 unreachable=0 failed=0
任何人都知道为什么即使状态显示该文件也没有复制ok
。
答案1
嗯..在您提到的问题中/etc/resolv.conf
,虽然您创建的任务将模板部署在/tmp/resolv.conf
.像这样改变它:
---
- name: place dns configuration
become: true
template:
src: resolv.conf.j1
dest: /etc/resolv.conf
检查你的命令:sudo ansible-playbook -i "pc1," lab-data.yml -t dns.yml -vvvv
-t
选择标签后,您确定您的标签实际上已命名吗dns.yml
,因为它听起来像剧本名称
非常有趣的库存文件名。