user3311890
user3311890

Reputation: 341

Ansible conf file changes

So, I am a complete noob on Ansible and YAML and I'm trying to learn a bit but this is driving me crazy so far...I am using ansible tower. What I'm trying to do is to replace some text on the ntp.conf file of certain servers and update them with a new server. So my playbook looks like this:

---
- hosts: range_1
  tasks:
    - name: ntp change
      become_user: ansible
      blockinfile:
        content: |
          server Server1 iburst
          server Server2 iburst
        dest: /etc/ntp.conf
        insertafter: "Please consider joining the pool"
        marker: "<!-- {mark} ANSIBLE MANAGED BLOCK -->"
    - name: restart ntp
      service: name=ntpd state=restarted

But I am getting the

PLAY RECAP


Host_1 : ok=1 changed=0 unreachable=0 failed=0
Host_2 : ok=1 changed=0 unreachable=0 failed=0
Host_3 : ok=1 changed=0 unreachable=0 failed=0

Ansible is running and it does not exit with an error. However, is not making any chnages to the systems. (I assumed because of the changed = 0) I indeed logged on to those systems and no changes have been applied.

I have checked and the syntax is correct but Im not sure what I'm missing. I really need to understand how can I add two servers into the ntp.conf and if a server has some wrong info, to delete it and add just those 2 servers. Any help or guidance will be very much appreciated.

Upvotes: 1

Views: 530

Answers (1)

user3311890
user3311890

Reputation: 341

For anybody that might be reading, when running a playbook from ansible or ansible tower, set the verbose output to 2. When I ran it, it showed me the error:

AILED! => {"changed": false, "failed": true, "msg": "The destination directory (/etc) is not writable by the current user."}

But it was fixed by adding the become: yes line on my playbook which it now looks like this:

---
- hosts: range_1
  tasks:
    - name: ntp change
      become: yes
      blockinfile:
        content: |
          server Server1 iburst
          server Server2 iburst
        dest: /etc/ntp.conf
        insertafter: "Please consider joining the pool"
        marker: "<!-- {mark} ANSIBLE MANAGED BLOCK -->"
    - name: restart ntp
      become: yes
      service: name=ntpd state=restarted

Upvotes: 1

Related Questions