diff --git a/linux-config-hostname.yaml b/linux-config-hostname.yaml new file mode 100644 index 0000000..e4d2c29 --- /dev/null +++ b/linux-config-hostname.yaml @@ -0,0 +1,12 @@ +--- + +- hosts: '{{ ip_addr }}' + become: yes + become_method: sudo + gather_facts: yes + + tasks: + + - name: "[CONFIG HOSTNAME] Configure hostname" + import_role: + name: config-hostname diff --git a/roles/config-hostname/tasks/main.yaml b/roles/config-hostname/tasks/main.yaml new file mode 100644 index 0000000..d93d446 --- /dev/null +++ b/roles/config-hostname/tasks/main.yaml @@ -0,0 +1,21 @@ +# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +# Configure HOSTNAME and HOSTS with new HOSTNAME +# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + +# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +# Configure HOSTNAME /etc/hostname +- name: Set a hostname specifying strategy in /etc/hostname + ansible.builtin.hostname: + name: "{{ name_hostname }}" + use: debian +# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +- name: Replace old hostname with new hostname in /etc/hosts + lineinfile: + dest: /etc/hosts + regexp: '^127\.0\.1\.1\tplantilladebian12\.verdnatura\.es\tplantilladebian12' + line: '127.0.1.1 "{{ name_hostname }}".verdnatura.es "{{ name_hostname }}"' +# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +# https://docs.ansible.com/ansible/latest/collections/ansible/builtin/hostname_module.html#ansible-collections-ansible-builtin-hostname-module +# https://docs.ansible.com/ansible/latest/collections/ansible/builtin/replace_module.html#ansible-collections-ansible-builtin-replace-module +# https://docs.ansible.com/ansible/latest/collections/ansible/builtin/lineinfile_module.html#ansible-collections-ansible-builtin-lineinfile-module