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

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/7fad1f58-a8a4-434b-9bda-b5de920736ee%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to