On 22/11/2021 09:00, dudu.c...@gmail.com wrote:
Hi, In my inventory file i have 3 server, I need to set the hostname including prefix1-3web1 web2 web3 *Inventory fie:* [web] 192.168.0.47 192.168.0.48 192.168.0.49
Add the hostname to the inventory file: web1 ansible_host=192.168.0.47
*Playbook* - hosts: - web become: true any_errors_fatal: true tasks: - name: update hostname hostname: name : "web ????"
Now you can use the inventory_hostname variable in your task: - name: update hostname hostname: name: "{{ inventory_hostname }}" Please note that might not survive reboots, e.g on Ubuntu I'm doing: - name: Enable preserving hostname in Cloud configuration lineinfile: path: /etc/cloud/cloud.cfg line: 'preserve_hostname: true' regexp: '^preserve_hostname:' tags: hostname Regards Racke
-- 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 ansible-project+unsubscr...@googlegroups.com <mailto:ansible-project+unsubscr...@googlegroups.com>. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/2dd18239-c65d-4717-9d90-af4c2aba1a68n%40googlegroups.com <https://groups.google.com/d/msgid/ansible-project/2dd18239-c65d-4717-9d90-af4c2aba1a68n%40googlegroups.com?utm_medium=email&utm_source=footer>.
-- Ecommerce and Linux consulting + Perl and web application programming. Debian and Sympa administration. -- 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 ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/6c6ac5f1-51a6-c067-472b-e22316a489d2%40linuxia.de.
OpenPGP_signature
Description: OpenPGP digital signature