From 9fee0bd112b12f0f8855d7570b484dabfb183ec7 Mon Sep 17 00:00:00 2001 From: David Wilson Date: Tue, 27 Feb 2018 15:42:14 +0545 Subject: [PATCH] ansible: basic regression test for delegation/sudo --- examples/playbook/connection_local.yml | 9 --- examples/playbook/delegate_to.yml | 86 ++++++++++++++++++++++++++ 2 files changed, 86 insertions(+), 9 deletions(-) delete mode 100644 examples/playbook/connection_local.yml create mode 100644 examples/playbook/delegate_to.yml diff --git a/examples/playbook/connection_local.yml b/examples/playbook/connection_local.yml deleted file mode 100644 index 4518dba5..00000000 --- a/examples/playbook/connection_local.yml +++ /dev/null @@ -1,9 +0,0 @@ ---- - -- hosts: all - gather_facts: false - tasks: - - name: "Run hostname" - connection: local - command: hostname - with_sequence: start=1 end=100 diff --git a/examples/playbook/delegate_to.yml b/examples/playbook/delegate_to.yml new file mode 100644 index 00000000..b4f85112 --- /dev/null +++ b/examples/playbook/delegate_to.yml @@ -0,0 +1,86 @@ +--- + +- hosts: all + gather_facts: false + tasks: + + # + # delegate_to, no sudo + # + - name: "delegate_to, no sudo" + copy: + dest: /tmp/delegate_to.yml.txt + content: "Hello, world." + register: out + delegate_to: localhost + + - name: "delegate_to, no sudo" + assert: + that: "lookup('file', '/tmp/delegate_to.yml.txt') == 'Hello, world.'" + + - name: "delegate_to, no sudo" + file: + path: /tmp/delegate_to.yml.txt + state: absent + delegate_to: localhost + + + # + # connection:local, no sudo + # + - name: "connection:local, no sudo" + copy: + dest: /tmp/delegate_to.yml.txt + content: "Hello, world." + register: out + connection: local + + - name: "connection:local, no sudo" + assert: + that: "lookup('file', '/tmp/delegate_to.yml.txt') == 'Hello, world.'" + + - name: "connection:local, no sudo" + file: + path: /tmp/delegate_to.yml.txt + state: absent + connection: local + + + # + # delegate_to, sudo + # + - name: "delegate_to, sudo" + shell: whoami > /tmp/delegate_to.yml.txt + delegate_to: localhost + become: true + + - name: "delegate_to, sudo" + assert: + that: "lookup('file', '/tmp/delegate_to.yml.txt') == 'root'" + + - name: "delegate_to, sudo" + file: + path: /tmp/delegate_to.yml.txt + state: absent + delegate_to: localhost + become: true + + + # + # connection:local, sudo + # + - name: "connection:local, sudo" + shell: whoami > /tmp/delegate_to.yml.txt + connection: local + become: true + + - name: "connection:local, sudo" + assert: + that: "lookup('file', '/tmp/delegate_to.yml.txt') == 'root'" + + - name: "connection:local, sudo" + file: + path: /tmp/delegate_to.yml.txt + state: absent + connection: local + become: true