summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorboom2 <blizzack@blizzack.com>2023-11-22 22:39:56 -0500
committerboom2 <blizzack@blizzack.com>2023-11-22 22:39:56 -0500
commitd00dff82886992cdad94ac70bc438ec5b2bda1a2 (patch)
treefc6e286816e8aaf48043b92fd81fc109569989f5
parent74b826b2e9783df019eea265772746cab691ce54 (diff)
more playbooks related to bash configs
-rw-r--r--ansible-practice/05-playbook-add-content-to-created-file.yml3
-rw-r--r--ansible-practice/07-playbook-create-directory.yml2
-rw-r--r--ansible-practice/12-playbook-copy-directory.yml3
-rw-r--r--ansible-practice/system/.bash_aliases9
-rw-r--r--ansible-practice/system/.bashrc38
-rw-r--r--ansible-practice/system/01-playbook-create-bash-alias.yml~0
-rw-r--r--ansible-practice/system/01-playbook-create-bash-configs.yml67
-rw-r--r--ansible-practice/system/01-playbook-create-bash-configs.yml~33
-rw-r--r--ansible-practice/system/02-playbook-copy-bash-configs.yml24
-rw-r--r--ansible-practice/system/02-playbook-copy-bash-configs.yml~60
-rw-r--r--ansible_stuff.org51
11 files changed, 286 insertions, 4 deletions
diff --git a/ansible-practice/05-playbook-add-content-to-created-file.yml b/ansible-practice/05-playbook-add-content-to-created-file.yml
index de3fdb6..f8d859c 100644
--- a/ansible-practice/05-playbook-add-content-to-created-file.yml
+++ b/ansible-practice/05-playbook-add-content-to-created-file.yml
@@ -9,8 +9,7 @@
tasks:
- name: Creating a file with content
copy:
- dest: "~/ansible_created_file-02.txt"
+ dest: "~/tmp/temp_files/ansible_created_file-02.txt"
content: |
line 01
line 02
-... \ No newline at end of file
diff --git a/ansible-practice/07-playbook-create-directory.yml b/ansible-practice/07-playbook-create-directory.yml
index ba4affc..9d38ee9 100644
--- a/ansible-practice/07-playbook-create-directory.yml
+++ b/ansible-practice/07-playbook-create-directory.yml
@@ -9,6 +9,6 @@
tasks:
- name: Create a new directory
file:
- path: "~/ansible_created_directory"
+ path: "~/tmp/temp_files"
state: directory
... \ No newline at end of file
diff --git a/ansible-practice/12-playbook-copy-directory.yml b/ansible-practice/12-playbook-copy-directory.yml
index 00a5fd8..beaabc8 100644
--- a/ansible-practice/12-playbook-copy-directory.yml
+++ b/ansible-practice/12-playbook-copy-directory.yml
@@ -11,9 +11,10 @@
ansible.builtin.copy:
src: /home/dpierre/ansible-practice
dest: /home/dpierre/tmp/temp_files
+ tags: ['step1']
- name: copy directory contents
ansible.builtin.copy:
src: /home/dpierre/tmp/grubstuff/
dest: /home/dpierre/tmp/temp_files/grub_files/
-... \ No newline at end of file
+ tags: ['step2']
diff --git a/ansible-practice/system/.bash_aliases b/ansible-practice/system/.bash_aliases
new file mode 100644
index 0000000..ad4cd25
--- /dev/null
+++ b/ansible-practice/system/.bash_aliases
@@ -0,0 +1,9 @@
+# navigation
+alias ls='ls --color=auto'
+alias ll='ls -al --color=auto'
+
+# applications
+alias vi=/usr/bin/vim
+
+# git
+alias gstat='git status'
diff --git a/ansible-practice/system/.bashrc b/ansible-practice/system/.bashrc
new file mode 100644
index 0000000..5d417ae
--- /dev/null
+++ b/ansible-practice/system/.bashrc
@@ -0,0 +1,38 @@
+# execute our aliases
+if [ -f ~/.bash_aliases ]; then
+. ~/.bash_aliases
+fi
+
+# history settings
+## setting unlimited filesize and history size
+export HISTFILESIZE=
+export HISTSIZE=
+export HISTCONTROL=erasedups:ignorespace:ignoredups
+
+# allows you to choose which standalone commands to drop from your history
+export HISTIGNORE='pwd:exit:fg:bg:top:clear:history:ls:uptime:ll'
+
+# display timestamp before the history command entry
+export HISTTIMEFORMAT='%F %T '
+
+# https://cyb.org.uk/2021/05/03/bash-productivity.html
+# http://mywiki.wooledge.org/BashFAQ/088
+PROMPT_COMMAND='history -a'
+shopt -s histappend
+
+#setting prompt
+# export PS1="\u@\h:\w\$ "
+# export PS1="\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ "
+export PS1="\n\[\033[11;33m\][\[\033[11;36m\]\D{%F} \t\[\033[11;33m\]][\[\033[11;36m\]\!\[\033[11;33m\]]\n[\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00;33m\]]\[\033[00m\]\n\$ "
+export PS2="> "
+
+# the default editor
+export EDITOR=vim
+
+# add color
+eval `dircolors -b`
+
+# this function calls 'cd' to enter a directory and then immediately calls 'ls'
+cdls() {
+ cd "$@" && ll;
+}
diff --git a/ansible-practice/system/01-playbook-create-bash-alias.yml~ b/ansible-practice/system/01-playbook-create-bash-alias.yml~
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/ansible-practice/system/01-playbook-create-bash-alias.yml~
diff --git a/ansible-practice/system/01-playbook-create-bash-configs.yml b/ansible-practice/system/01-playbook-create-bash-configs.yml
new file mode 100644
index 0000000..ff2156c
--- /dev/null
+++ b/ansible-practice/system/01-playbook-create-bash-configs.yml
@@ -0,0 +1,67 @@
+# creating a bash config files w/ content
+# https://phoenixnap.com/kb/ansible-create-file
+
+---
+- name: "01 - custom ansible - create bash config files w/ content"
+# hosts: all
+ hosts: localhost
+ connection: local
+ tasks:
+ - name: Creating '.bash_aliases' file with content
+ copy:
+ dest: "~/tmp/temp_files/.bash_aliases"
+ content: |
+ # navigation
+ alias ls='ls --color=auto'
+ alias ll='ls -al --color=auto'
+
+ # applications
+ alias vi=/usr/bin/vim
+
+ # git
+ alias gstat='git status'
+ tags: ['bash_aliases']
+
+ - name: Creating '.bashrc' file with content
+ copy:
+ dest: "~/tmp/temp_files/.bashrc"
+ content: |-
+ # execute our aliases
+ if [ -f ~/.bash_aliases ]; then
+ . ~/.bash_aliases
+ fi
+
+ # history settings
+ ## setting unlimited filesize and history size
+ export HISTFILESIZE=
+ export HISTSIZE=
+ export HISTCONTROL=erasedups:ignorespace:ignoredups
+
+ # allows you to choose which standalone commands to drop from your history
+ export HISTIGNORE='pwd:exit:fg:bg:top:clear:history:ls:uptime:ll'
+
+ # display timestamp before the history command entry
+ export HISTTIMEFORMAT='%F %T '
+
+ # https://cyb.org.uk/2021/05/03/bash-productivity.html
+ # http://mywiki.wooledge.org/BashFAQ/088
+ PROMPT_COMMAND='history -a'
+ shopt -s histappend
+
+ #setting prompt
+ # export PS1="\u@\h:\w\$ "
+ # export PS1="\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ "
+ export PS1="\n\[\033[11;33m\][\[\033[11;36m\]\D{%F} \t\[\033[11;33m\]][\[\033[11;36m\]\!\[\033[11;33m\]]\n[\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00;33m\]]\[\033[00m\]\n\$ "
+ export PS2="> "
+
+ # the default editor
+ export EDITOR=vim
+
+ # add color
+ eval `dircolors -b`
+
+ # this function calls 'cd' to enter a directory and then immediately calls 'ls'
+ cdls() {
+ cd "$@" && ll;
+ }
+ tags: ['bashrc']
diff --git a/ansible-practice/system/01-playbook-create-bash-configs.yml~ b/ansible-practice/system/01-playbook-create-bash-configs.yml~
new file mode 100644
index 0000000..d968faa
--- /dev/null
+++ b/ansible-practice/system/01-playbook-create-bash-configs.yml~
@@ -0,0 +1,33 @@
+# creating a file w/ content
+# https://phoenixnap.com/kb/ansible-create-file
+
+---
+- name: "01 - custom ansible - create bash config files w/ content"
+# hosts: all
+ hosts: localhost
+ connection: local
+ tasks:
+ - name: Creating '.bash_aliases' file with content
+ copy:
+ dest: "~/tmp/temp_files/.bash_aliases"
+ content: |
+ # navigation
+ alias ls='ls --color=auto'
+ alias ll='ls -al --color=auto'
+
+ # applications
+ alias vi=/usr/bin/vim
+
+ # git
+ alias gstat='git status'
+ tags: ['bash_aliases']
+
+ - name: Creating '.bashrc' file with content
+ copy:
+ dest: "~/tmp/temp_files/.bashrc"
+ content: |
+ # execute our aliases
+ if [ -f ~/.bash_aliases ]; then
+ . ~/.bash_aliases
+ fi
+ tags: ['bashrc']
diff --git a/ansible-practice/system/02-playbook-copy-bash-configs.yml b/ansible-practice/system/02-playbook-copy-bash-configs.yml
new file mode 100644
index 0000000..ae4dd97
--- /dev/null
+++ b/ansible-practice/system/02-playbook-copy-bash-configs.yml
@@ -0,0 +1,24 @@
+# copy directories from control node to managed node
+# https://www.freekb.net/Article?id=759
+# https://docs.ansible.com/ansible/latest/collections/ansible/builtin/copy_module.html
+#
+
+---
+- name: "02 - custom ansible - copy bash config files w/ content"
+# hosts: all
+ hosts: localhost
+ connection: local
+ tasks:
+ - name: copy '.bash_aliases'
+ ansible.builtin.copy:
+ src: ~/repos/ansible_repo/ansible-practice/system/.bash_aliases
+ dest: "~/tmp/temp_files/.bash_aliases"
+ mode: '0644'
+ tags: ['bash_aliases']
+
+ - name: Creating '.bashrc' file with content
+ copy:
+ src: ~/repos/ansible_repo/ansible-practice/system/.bashrc
+ dest: "~/tmp/temp_files/.bashrc"
+ mode: '0644'
+ tags: ['bashrc']
diff --git a/ansible-practice/system/02-playbook-copy-bash-configs.yml~ b/ansible-practice/system/02-playbook-copy-bash-configs.yml~
new file mode 100644
index 0000000..7ef9c07
--- /dev/null
+++ b/ansible-practice/system/02-playbook-copy-bash-configs.yml~
@@ -0,0 +1,60 @@
+# copy directories from control node to managed node
+# https://www.freekb.net/Article?id=759
+# https://docs.ansible.com/ansible/latest/collections/ansible/builtin/copy_module.html
+#
+
+---
+- name: "02 - custom ansible - copy bash config files w/ content"
+# hosts: all
+ hosts: localhost
+ connection: local
+ tasks:
+ - name: copy '.bash_aliases'
+ ansible.builtin.copy:
+ src: ~/repos/ansible_repo/ansible-practice/system/.bash_aliases
+ dest: "~/tmp/temp_files/.bash_aliases"
+ tags: ['bash_aliases']
+
+ - name: Creating '.bashrc' file with content
+ copy:
+ dest: "~/tmp/temp_files/.bashrc"
+ content: |-
+ # execute our aliases
+ if [ -f ~/.bash_aliases ]; then
+ . ~/.bash_aliases
+ fi
+
+ # history settings
+ ## setting unlimited filesize and history size
+ export HISTFILESIZE=
+ export HISTSIZE=
+ export HISTCONTROL=erasedups:ignorespace:ignoredups
+
+ # allows you to choose which standalone commands to drop from your history
+ export HISTIGNORE='pwd:exit:fg:bg:top:clear:history:ls:uptime:ll'
+
+ # display timestamp before the history command entry
+ export HISTTIMEFORMAT='%F %T '
+
+ # https://cyb.org.uk/2021/05/03/bash-productivity.html
+ # http://mywiki.wooledge.org/BashFAQ/088
+ PROMPT_COMMAND='history -a'
+ shopt -s histappend
+
+ #setting prompt
+ # export PS1="\u@\h:\w\$ "
+ # export PS1="\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ "
+ export PS1="\n\[\033[11;33m\][\[\033[11;36m\]\D{%F} \t\[\033[11;33m\]][\[\033[11;36m\]\!\[\033[11;33m\]]\n[\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00;33m\]]\[\033[00m\]\n\$ "
+ export PS2="> "
+
+ # the default editor
+ export EDITOR=vim
+
+ # add color
+ eval `dircolors -b`
+
+ # this function calls 'cd' to enter a directory and then immediately calls 'ls'
+ cdls() {
+ cd "$@" && ll;
+ }
+ tags: ['bashrc']
diff --git a/ansible_stuff.org b/ansible_stuff.org
index 6dc98eb..99f00db 100644
--- a/ansible_stuff.org
+++ b/ansible_stuff.org
@@ -530,6 +530,16 @@ dpierre@boom2:~$ ansible all -a "uptime"
14:00:39 up 5 min, 1 user, load average: 0.15, 0.05, 0.01
+- copying files that are owned by myself
+ansible all -m copy -a "src=./file.txt dest=~/myfile.txt"
+
+- change file permissions
+ansible all -m file -a "dest=/var/www/file.txt mode=600 owner=sammy group=sammy" --become -K
+
+- invoking services
+ansible all -a "/sbin/reboot" --become -K
+
+
interesting... we can use a different ssh key with our ansible
commands if we wish like so:
@@ -552,3 +562,44 @@ ansible all -m setup
ansible all -m setup -a "gather_subset=min"
ansible all -m setup -a " filter=*ipv* "
ansible all -m setup > ../bbox-system.json
+
+
+- to list out the tasks of a playbook:
+
+ansible-playbook 12-playbook-copy-directory.yml --list-tasks
+
+playbook: 12-playbook-copy-directory.yml
+
+ play #1 (all): 12 - Playing with Ansible - copy directories from control to managed node TAGS: []
+ tasks:
+ copy entire directory TAGS: [step1]
+ copy directory contents TAGS: [step2]
+
+- to list out the tags of a playbook:
+
+ ansible-playbook 12-playbook-copy-directory.yml --list-tags
+
+ playbook: 12-playbook-copy-directory.yml
+
+ play #1 (all): 12 - Playing with Ansible - copy directories from control to managed node TAGS: []
+ TASK TAGS: [step1, step2]
+
+- execute tasks by tag
+
+ ansible-playbook 12-playbook-copy-directory.yml --tags=step2
+
+ - skipping tasks by tag
+
+ ansible-playbook 12-playbook-copy-directory.yml --exclude-tags=step1
+
+ - starting execution at specific task
+
+ ansible-playbook 12-playbook-copy-directory.yml --start-at-task=step4
+
+- limiting targets for execution to a set of workstations
+ - many typically playbooks set up their target as 'all' by default,
+ and sometimes you want to limit the group or single server that
+ should be the target for that setup. You can use -l (limit) to set
+ up the target group or server in that play.
+
+ ansible-playbook -l dev-stations 12-playbook-copy-directory.yml