From 1d321149e12310189ea5157c5681c87f507438bb Mon Sep 17 00:00:00 2001 From: Gustavo Martin Morcuende Date: Sun, 5 Feb 2017 21:21:51 +0100 Subject: [PATCH] Ansible: using sudo with apt and find commands --- ansible/apt/aptsudo.yml | 17 +++++++++++++++++ ansible/apt/sudopass | 7 +++++++ ansible/apt/vault.txt | 1 + ansible/find/findsudo.yml | 22 ++++++++++++++++++++++ ansible/find/sudopass | 7 +++++++ ansible/find/vault.txt | 1 + 6 files changed, 55 insertions(+) create mode 100644 ansible/apt/aptsudo.yml create mode 100644 ansible/apt/sudopass create mode 100644 ansible/apt/vault.txt create mode 100644 ansible/find/findsudo.yml create mode 100644 ansible/find/sudopass create mode 100644 ansible/find/vault.txt diff --git a/ansible/apt/aptsudo.yml b/ansible/apt/aptsudo.yml new file mode 100644 index 0000000..aa0c5d4 --- /dev/null +++ b/ansible/apt/aptsudo.yml @@ -0,0 +1,17 @@ +# Updates apt cache. +# +# ansible-vault --vault-password-file=vault.txt create sudopass +# ansible-playbook aptsudo.yml -vvvvv --vault-password-file=vault.txt +# +--- +- hosts: localhost + vars_files: + - sudopass + + tasks: + - name: apt update cache + become: yes + become_user: root + become_method: sudo + apt: + update_cache: yes diff --git a/ansible/apt/sudopass b/ansible/apt/sudopass new file mode 100644 index 0000000..1767ae2 --- /dev/null +++ b/ansible/apt/sudopass @@ -0,0 +1,7 @@ +$ANSIBLE_VAULT;1.1;AES256 +31366363623239353561623031653563343536636263396362386461616262313539643930666636 +6631613661306463356434663765313033643439373361300a373431363062643838356261343936 +34343263663933656635393735343265303832343964376336323965623637323433316265363065 +3436363864333265340a316335326463376332316531376635333837353532663632386534323730 +31346462376365303232363836343965646561663934323935376265633937383339626662303931 +3737653631633338386162623766323062393363376538336365 diff --git a/ansible/apt/vault.txt b/ansible/apt/vault.txt new file mode 100644 index 0000000..cbd8ecb --- /dev/null +++ b/ansible/apt/vault.txt @@ -0,0 +1 @@ +mysillypassword diff --git a/ansible/find/findsudo.yml b/ansible/find/findsudo.yml new file mode 100644 index 0000000..fbebb49 --- /dev/null +++ b/ansible/find/findsudo.yml @@ -0,0 +1,22 @@ +# Returns files in $HOME and fills result in fileoutput +# +# ansible-vault --vault-password-file=vault.txt create sudopass +# ansible-playbook aptsudo.yml -vvvvv --vault-password-file=vault.txt -e 'filename=fileoutput' +# +--- +- hosts: localhost + vars_files: + - sudopass + + tasks: + - name: List files in directory + become: yes + become_user: root + become_method: sudo -i + find: + paths: "{{ ansible_env.HOME }}" + register: result + - name: Fill file + shell: echo "{{ item.path }}" >> "{{ filename }}" + with_items: "{{ result.files }}" + diff --git a/ansible/find/sudopass b/ansible/find/sudopass new file mode 100644 index 0000000..1767ae2 --- /dev/null +++ b/ansible/find/sudopass @@ -0,0 +1,7 @@ +$ANSIBLE_VAULT;1.1;AES256 +31366363623239353561623031653563343536636263396362386461616262313539643930666636 +6631613661306463356434663765313033643439373361300a373431363062643838356261343936 +34343263663933656635393735343265303832343964376336323965623637323433316265363065 +3436363864333265340a316335326463376332316531376635333837353532663632386534323730 +31346462376365303232363836343965646561663934323935376265633937383339626662303931 +3737653631633338386162623766323062393363376538336365 diff --git a/ansible/find/vault.txt b/ansible/find/vault.txt new file mode 100644 index 0000000..cbd8ecb --- /dev/null +++ b/ansible/find/vault.txt @@ -0,0 +1 @@ +mysillypassword -- 2.1.4