-1

I am using ansible-2.0 on linux machine and create the ansible-galaxy, on it created the dns.yml file which replace the /etc/resolv.conf on remote machine but it's not working. Ansible status showing OK.

dns.yml

---
- name: place dns configuration
  become: true
  template:
    src: resolv.conf.j1
    dest: /tmp/resolv.conf

Output :

....
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`}

Error in Deep view :

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  

Anyone have idea why this file is not copy even status showing ok.

1

Well.. in your question you're mentioning /etc/resolv.conf, while the task you've created deploys the template in /tmp/resolv.conf. Change it like this:

---
- name: place dns configuration
  become: true
  template:
    src: resolv.conf.j1
    dest: /etc/resolv.conf

Check out your command: sudo ansible-playbook -i "pc1," lab-data.yml -t dns.yml -vvvv

  • with -t you select a tag, are you sure that your tag is actually named dns.yml, as it sounds like a playbook name

Quite interesting inventory filename.

  • here temporary I've added /tmp because I was think, file is exist so that may not work. but here resolve.conf file is not copy to remote pc, Is there any way to troubleshooting same? – Nullpointer Feb 20 '17 at 10:47
  • @Ravi In your test, was the file copied to /tmp? – Zumo de Vidrio Feb 20 '17 at 10:48
  • Nop, even /tmp folder :( – Nullpointer Feb 20 '17 at 10:51
  • What is your playbook structure? Is resolv.conf.j1 located in the templates folder, or in files folder? And shouldn't resolv.conf.j1 be actually named resolv.conf.j2, as the templates are Jinja2 ones? – 13dimitar Feb 20 '17 at 10:56
  • resolv.conf.j1 is in templates folder and change to ` resolv.conf.j2` but still not copy file; but in localhost, its working – Nullpointer Feb 20 '17 at 10:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.