Ansible paybook not doing anything despite saying "succesful"

57 views
Skip to first unread message

G Stewart

unread,
Jun 13, 2016, 1:39:46 PM6/13/16
to Ansible Project
I have been trying to create a playbook to modify system config files--in this case, postifx configs--and, to restart the postfix service when done. While I've gotten the script to run without errors (I think), despit the ansible output suggesting everything was done successfully, nothing actually happened on the remote system

Here is my playbook:

---
- name: correct postfix inet_protocol configuration for ipv4 only
  hosts
: '{{ target }}'
  remote_user
: my_user_name
  become
: yes
  become_method
: sudo
  tasks
:
 
   
- name: Test become
      command
: whoami
     
register: the_user

   
- name: Debug become
      debug
:
        msg
: "{{ the_user }}"

   
- name: Ensure /etc/postfix directory is present
      file
: path=/etc/postfix state=directory

   
- name: validate /etc/postfix/main.cf
      local_action
: stat path="/etc/postfix/main.cf"
     
register: result
      ignore_errors
: True

   
- name: Limit inet_protocol in postfix/main.cf to IPv4 only
      lineinfile
:
        dest
:  dest=/etc/postfix/main.cf
        state
: present
        regexp
: '^inet_protocols\s+=\s+all'
        line
: '#inet_protocols = all\ninet_protocols = ipv4'
        validate
: 'grep "inet_protocols = ipv4" %s'
     
register: postfix_inet_proto_ok
      tags
: postfix_inet_proto

   
- name: Restart postfix
      service
: name=postfix state=restarted
     
when: postfix_inet_proto_ok|success
...


I added the debug to show that become is actually working, and I'm not getting any sudo password errors--I shouldn't, my username is able to sudo (on both local and remote systems) without a password.

I have even tried mofifying the ansible.cfg "sudo_flags" parameter, but that made no difference. I set it back to: "sudo_flags = -H -S -n"

Here is the output of running that playbook:


[my_user_name@fedora_linux ansible]$ ansible-playbook -i hosts pb/postfix_ipv6_fix.yml --extra-vars "target=rhel_linux_server"

PLAY
[correct postfix inet_protocol configuration for ipv4 only] ***************

TASK
[setup] *******************************************************************
ok
: [rhel_linux_server]

TASK
[Test become] *************************************************************
changed
: [rhel_linux_server]

TASK
[Debug become] ************************************************************
ok
: [rhel_linux_server] => {
   
"msg": {
       
"changed": true,
       
"cmd": [
           
"whoami"
       
],
       
"delta": "0:00:00.003188",
       
"end": "2016-06-13 12:13:22.763731",
       
"rc": 0,
       
"start": "2016-06-13 12:13:22.760543",
       
"stderr": "",
       
"stdout": "root",
       
"stdout_lines": [
           
"root"
       
],
       
"warnings": []
   
}
}

TASK
[Ensure /etc/postfix directory is present] ********************************
ok
: [rhel_linux_server]

TASK
[validate /etc/postfix/main.cf] *******************************************
ok
: [rhel_linux_server -> localhost]

TASK
[Limit inet_protocol in postfix/main.cf to IPv4 only] *********************
changed
: [rhel_linux_server]

TASK
[Restart postfix] *********************************************************
changed
: [rhel_linux_server]

PLAY RECAP
*********************************************************************
rhel_linux_server          
: ok=7    changed=3    unreachable=0    failed=0  

[my_user_name@fedora_linux ansible]$


I have also tried using templates, and that doesn't work either.

But, in the end, the postfix config is not actually modified, and the postfix service is not actually restarted.

Does anyone have any clue what I'm doing wrong?

Thanks!

--Greg

G Stewart

unread,
Jun 13, 2016, 1:59:12 PM6/13/16
to Ansible Project
Okay... I'm an idiot.

After poking around, I discovered that I had a .ansible dir in my home dir, and exploring there I realised that my script was writing the changes I asked for to a directory path under my home dir.

When I compared that odd directory path to my YAML code, I found this:


    - name: Limit inet_protocol in postfix/main.cf to IPv4 only
      lineinfile
:
        dest
:  dest=/etc/postfix/main.cf

I had converted a one-line lineinfile syntax to multi-line, and I didn't notice I forgot to remove the "dest=" after I added the "dest:".

Well, if it helps anyone in debug code who may not already know: there's a hidden .ansible dir in the user home dir to look at on the remote host.

--Greg

Reply all
Reply to author
Forward
0 new messages