diff --git a/changelogs/fragments/add_commit_confirm_to_rm.yaml b/changelogs/fragments/add_commit_confirm_to_rm.yaml
new file mode 100644
index 00000000..c790e88e
--- /dev/null
+++ b/changelogs/fragments/add_commit_confirm_to_rm.yaml
@@ -0,0 +1,7 @@
+---
+minor_changes:
+ - check out the full motivation behind this enhancement(https://github.com/ansible-collections/junipernetworks.junos/issues/384).
+ - ability to revert changes if the playbook executes multiple Junos modules in a row and results are undesired.
+ - with task level var `ansible_junos_commit_confirmed` leverage upon confirm commit feature supported by junos.
+ timer can be set with var `commit_confirmed_timeout`
+ - it can also help to reduce large CPU utilization when using single commit for mulitple tasks.
diff --git a/docs/junipernetworks.junos.junos_netconf.rst b/docs/junipernetworks.junos.junos_netconf.rst
index fef45678..be0b63b6 100644
--- a/docs/junipernetworks.junos.junos_netconf.rst
+++ b/docs/junipernetworks.junos.junos_netconf.rst
@@ -34,6 +34,45 @@ Parameters
Configuration |
Comments |
+
+
+
+ commit_confirmed
+
+
+ boolean
+
+ |
+
+ Default:
"no"
+ |
+
+ env:ANSIBLE_JUNOS_COMMIT_CONFIRMED
+ var: ansible_junos_commit_confirmed
+ |
+
+ enable or disable commit confirmed mode
+ |
+
+
+
+
+ commit_confirmed_timeout
+
+
+ integer
+
+ |
+
+ |
+
+ env:ANSIBLE_JUNOS_COMMIT_CONFIRMED_TIMEOUT
+ var: ansible_junos_commit_confirmed_timeout
+ |
+
+ Commits the configuration on a trial basis for the time specified in minutes.
+ |
+
diff --git a/plugins/netconf/junos.py b/plugins/netconf/junos.py
index 9c7986a8..27982cd1 100644
--- a/plugins/netconf/junos.py
+++ b/plugins/netconf/junos.py
@@ -31,6 +31,23 @@
netconf commands from Juniper JUNOS network devices.
version_added: 1.0.0
options:
+ commit_confirmed:
+ type: boolean
+ default: false
+ description:
+ - enable or disable commit confirmed mode
+ env:
+ - name: ANSIBLE_JUNOS_COMMIT_CONFIRMED
+ vars:
+ - name: ansible_junos_commit_confirmed
+ commit_confirmed_timeout:
+ type: int
+ description:
+ - Commits the configuration on a trial basis for the time specified in minutes.
+ env:
+ - name: ANSIBLE_JUNOS_COMMIT_CONFIRMED_TIMEOUT
+ vars:
+ - name: ansible_junos_commit_confirmed_timeout
ncclient_device_handler:
type: str
default: junos
@@ -267,6 +284,8 @@ def commit(
obj = new_ele("commit-configuration")
if confirmed:
sub_ele(obj, "confirmed")
+ elif self.get_option("commit_confirmed"):
+ sub_ele(obj, "confirmed")
if check:
sub_ele(obj, "check")
if synchronize:
@@ -277,7 +296,11 @@ def commit(
if comment:
subele = sub_ele(obj, "log")
subele.text = str(comment)
- if timeout:
+ if self.get_option("commit_confirmed_timeout"):
subele = sub_ele(obj, "confirm-timeout")
- subele.text = str(timeout)
+ subele.text = str(self.get_option("commit_confirmed_timeout"))
+ else:
+ if timeout:
+ subele = sub_ele(obj, "confirm-timeout")
+ subele.text = str(timeout)
return self.rpc(obj)
diff --git a/tests/integration/targets/junos_hostname/tests/netconf/commit_conf.yaml b/tests/integration/targets/junos_hostname/tests/netconf/commit_conf.yaml
new file mode 100644
index 00000000..34a7f7bf
--- /dev/null
+++ b/tests/integration/targets/junos_hostname/tests/netconf/commit_conf.yaml
@@ -0,0 +1,50 @@
+---
+- ansible.builtin.debug:
+ msg: START ios_cliconf integration tests on connection={{ ansible_connection }}
+
+- name: Reset
+ junipernetworks.junos.junos_hostname:
+ state: deleted
+
+- name: Verify hostname changed immediately
+ register: get_hostname
+ junipernetworks.junos.junos_hostname:
+ state: gathered
+
+- name: Change hostname with commit_confirm_immediate true and timer 2 minutes
+ vars:
+ ansible_junos_commit_confirmed: true
+ ansible_junos_commit_confirmed_timeout: 2
+ junipernetworks.junos.junos_hostname:
+ state: merged
+ config:
+ hostname: testConfirmCommitAppliance
+
+- name: Gather hostname
+ register: get_hostname
+ junipernetworks.junos.junos_hostname:
+ state: gathered
+
+- name: Assert that the hostname is correctly set
+ ansible.builtin.assert:
+ that:
+ - "'testConfirmCommitAppliance' == get_hostname.gathered.hostname"
+
+- name: Sleep for 300 seconds and continue with play
+ ansible.builtin.wait_for:
+ timeout: 150
+ delegate_to: localhost
+
+- name: Verify hostname change is persistent even after timeout
+ register: get_hostname
+ junipernetworks.junos.junos_hostname:
+ state: gathered
+
+- name: Assert that the hostname is correctly set
+ ansible.builtin.assert:
+ that:
+ - "{} == get_hostname.gathered"
+
+- name: Clenup
+ junipernetworks.junos.junos_hostname:
+ state: deleted
|