Ansible: using sudo with apt and find commands master
authorGustavo Martin Morcuende <gu.martinm@gmail.com>
Sun, 5 Feb 2017 20:21:51 +0000 (21:21 +0100)
committerGustavo Martin Morcuende <gu.martinm@gmail.com>
Sun, 5 Feb 2017 20:29:31 +0000 (21:29 +0100)
ansible/apt/aptsudo.yml [new file with mode: 0644]
ansible/apt/sudopass [new file with mode: 0644]
ansible/apt/vault.txt [new file with mode: 0644]
ansible/find/findsudo.yml [new file with mode: 0644]
ansible/find/sudopass [new file with mode: 0644]
ansible/find/vault.txt [new file with mode: 0644]

diff --git a/ansible/apt/aptsudo.yml b/ansible/apt/aptsudo.yml
new file mode 100644 (file)
index 0000000..aa0c5d4
--- /dev/null
@@ -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 (file)
index 0000000..1767ae2
--- /dev/null
@@ -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 (file)
index 0000000..cbd8ecb
--- /dev/null
@@ -0,0 +1 @@
+mysillypassword
diff --git a/ansible/find/findsudo.yml b/ansible/find/findsudo.yml
new file mode 100644 (file)
index 0000000..fbebb49
--- /dev/null
@@ -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 (file)
index 0000000..1767ae2
--- /dev/null
@@ -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 (file)
index 0000000..cbd8ecb
--- /dev/null
@@ -0,0 +1 @@
+mysillypassword