Created
October 19, 2023 11:09
-
-
Save jpmens/1f1bacc067b2b5ba5dd4fc407aedd571 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- name: testplaybook | |
become: true | |
become_method: sudo | |
hosts: ansible-test | |
gather_facts: false | |
vars: | |
new_ip: 10.65.5.14 | |
interfaces_content: | | |
auto eth0 | |
iface eth0 inet static | |
address {{ new_ip }}/11 | |
tasks: | |
- name: install ifupdown2 | |
ansible.builtin.package: | |
name: ifupdown2 | |
state: present | |
- name: write content | |
ansible.builtin.lineinfile: | |
path: /etc/network/interfaces | |
regexp: "auto eth0" | |
line: "{{ interfaces_content }}" | |
- name: restart networking | |
ansible.builtin.systemd: | |
service: networking | |
state: restarted | |
no_block: true | |
- name: write new ip to ansible host | |
ansible.builtin.set_fact: | |
ansible_host: "{{ new_ip }}" | |
- name: wait | |
ansible.builtin.wait_for: | |
connect_timeout: 60 | |
port: 22 | |
- name: gather_facts | |
ansible.builtin.setup: | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment