Skip to content

Instantly share code, notes, and snippets.

@jpmens
Created October 19, 2023 11:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jpmens/1f1bacc067b2b5ba5dd4fc407aedd571 to your computer and use it in GitHub Desktop.
Save jpmens/1f1bacc067b2b5ba5dd4fc407aedd571 to your computer and use it in GitHub Desktop.
---
- 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