Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions part00-getting-ready/ansible-learning-rollback.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
- name: Revert devops Account
hosts: all
become: true
gather_facts: False
tasks:
- name: Remove ssh key
authorized_key:
user: devops
key: "{{ lookup('file', lookup('env', 'HOME') + '/.ssh/id_rsa.pub') }}"
state: absent

- name: Remove account
user:
name: devops
state: absent
remove: yes

- name: Remove sudo access
file:
path: /etc/sudoers.d/devops
state: absent
1 change: 1 addition & 0 deletions part00-getting-ready/ansible.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[defaults]
inventory = inventory
remote_user = devops

[privilege_escalation]
become = true
become_user = root
Expand Down
12 changes: 10 additions & 2 deletions part01-create-user/create-user.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
---
- hosts: all
become: true
gather_facts: False
vars:
the_user: "devops"

tasks:
- name: create-user
user:
name: "{{ the_user }}"
groups: root,wheel
groups: root
shell: /bin/bash
state: present
create_home: yes
Expand All @@ -20,9 +21,16 @@
ssh_key_bits: 2048
ssh_key_file: .ssh/id_rsa

- name: Copy local SSH public key to target
authorized_key:
user: "{{ the_user }}"
state: present
manage_dir: yes
key: "{{ lookup('file', lookup('env','HOME') + '/.ssh/id_rsa.pub') }}"

- name: set password
user:
name: "{{ the_user }}"
password: "password"
password_expire_min: 14
password_expire_max: 60
password_expire_max: 60
7 changes: 7 additions & 0 deletions part02-update-linux/ansible.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[defaults]
inventory = inventory

[privilage_esclation]
become=True
become_method=sudo
become_user=root
3 changes: 3 additions & 0 deletions part02-update-linux/update-linux/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ Including an example of how to use your role (for instance, with variables passe

ansible-playbook play.yml [ --limit server-ip ]

Testing:
ansible-playbook update-linux/tests/test.yml -i update-linux/tests/inventory -u $(whoami) --ask-become-pass

## License

MIT
Expand Down
6 changes: 1 addition & 5 deletions part02-update-linux/update-linux/meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,4 @@ galaxy_info:
- dnf
- yum

dependencies:
- apt
- apt-get
- dnf
- yum
dependencies: []
3 changes: 1 addition & 2 deletions part02-update-linux/update-linux/tests/inventory
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
localhost

localhost ansible_connection=local
30 changes: 28 additions & 2 deletions part02-update-linux/update-linux/tests/test.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
---
- hosts: localhost
become: true
remote_user: root
roles:
- update-linux
gather_facts: true

tasks:
- name: Mock update for RedHat Family - yum
debug:
msg: "Would update all packages on RedHat using yum"
when:
- ansible_os_family == 'RedHat'
- ansible_pkg_mgr == 'yum'

- name: Mock update for RedHat Family - dnf
debug:
msg: "Would update all packages on RedHat using dnf"
when:
- ansible_os_family == 'RedHat'
- ansible_pkg_mgr == 'dnf'

- name: Mock update for Debian Family
debug:
msg: "Would update all packages on Debian using apt"
when:
- ansible_os_family == 'Debian'

handlers:
- name: reboot_machine
debug:
msg: "Handler would reboot machine if needed"