Skip to content

Commit

Permalink
feat: Create ansible user for use by pull mode
Browse files Browse the repository at this point in the history
  • Loading branch information
CraigJPerry committed Aug 7, 2020
1 parent b4dc0bf commit 1e0a48e
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@
A reboot of an old project from about 7 years ago,
https://github.com/CraigJPerry/home-network - I lost access to that github
account after an unfortunate mistake with 2FA :-)

19 changes: 19 additions & 0 deletions local.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
- hosts: all
tasks:
- group_by: key=user_{{ ansible_user_id }}
changed_when: False

# Invoked as root user
- hosts: user_root
gather_facts: no
sudo: no
roles:
- install_ansible_pull

# Invoked as non-root user, requires sudo
- hosts: "!user_root"
gather_facts: no
sudo: yes
roles:
- install_ansible_pull
17 changes: 17 additions & 0 deletions roles/install_ansible_pull/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---

# Install (or maintain) ansible pull mode

- name: Create ansible user
user: state="present" name="ansible" system="yes" createhome="yes" generate_ssh_key="yes" comment="Ansible Configuration Management"

- name: Add warning comment to ansible sudoers file
lineinfile: state="present" dest="/etc/sudoers.d/ansible" create="yes" insertbefore="BOF" regexp="^#" line="## Automatically Managed by Ansible, Manual Changes Will Be Lost!"

- name: Disable requiretty restriction on ansible user
# NB: Full line in quotes due to : char, see ansible YAML disclaimer
lineinfile: 'state="present" dest="/etc/sudoers.d/ansible" create="yes" regexp="^Defaults" line="Defaults: ansible !requiretty"'

- name: Allow ansible user full sudo privs
# NB: Full line in quotes due to : char, see ansible YAML disclaimer
lineinfile: 'state="present" dest="/etc/sudoers.d/ansible" create="yes" regexp="^ansible" line="ansible ALL=(ALL) NOPASSWD: ALL"'

0 comments on commit 1e0a48e

Please sign in to comment.