Hi, I created this playbook:

---
- name: basic host configuration
  hosts: ansibleclt00
  become: True
  tasks:
  - name: get hostname
    shell: hostname
    register: nomemacchina
  - name: change hostname
    vars:
      mio_ipaddr: 192.168.43.101
      mio_prefix: 24
      mio_gateway: 192.168.43.1
      mio_dns: 8.8.8.8
      mio_hostname: ansibleclt00
    command: hostnamectl set-hostname {{ mio_hostname }}
    when: nomemacchina != mio_hostname
    register: nomehost
  - name: reboot the server
    shell: /sbin/shutdown -r 1
    async: 0
    poll: 0
    ignore_errors: true
    register: riavvio
    when: nomehost.changed

When I run it:

PLAY [basic host configuration] 
************************************************

TASK [setup] 
*******************************************************************
ok: [ansibleclt00]

TASK [get hostname] 
************************************************************
changed: [ansibleclt00]

TASK [change hostname] 
*********************************************************
changed: [ansibleclt00]

TASK [reboot the server] 
*******************************************************
changed: [ansibleclt00]

PLAY RECAP 
*********************************************************************
ansibleclt00               : ok=4    changed=3    unreachable=0    failed=0

I'm experimenting with ansible, my idea is to verify the hostname of a 
server, if the name differs from the name in variable "mio_hostname", the 
hostname is changed (task "change hostname") to mio_hostname and then the 
server is rebooted.

But seems that the hostname differs everytime and I do not understand why.

Any idea?

ansible 2.1.1.0 on CentOS7

Thanks, Pietro.

-- 
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/2815f040-e382-436f-a09c-5714de9b94e8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to