# for Debian/Ubuntu/etc: $ sudo apt-get install gcc python-dev libkrb5-dev $ pip install pywinrm[kerberos] # for RHEL/CentOS/etc: $ sudo yum install gcc python-devel krb5-devel krb5-workstation python-devel $ pip install pywinrm[kerberos]
Sunday, 24 May 2020
To use Kerberos authentication you need these optional dependencies
Saturday, 9 May 2020
Wednesday, 6 May 2020
ANSIBLE FACTS
get all facts from a node (ad hoc)
ansible -i hosts targetName -m setup -a "filter="facter_*"
use fact in a playbook
include fact as {{ ansible_factname }}
add fact to Hosts file
[group]
host1 admin_user=jane
host2 admin_user=jack
host3
[group:vars]
admin_user=john
get default IPV4 address
ansible_default_ipv4.address
Local facts
place .fact file into /etc/ansible/facts.d on target node
vim /etc/ansible/facts.d/fruits.fact
[fruits]
sweet=banana, apple, grapes
bitter=grapefruit
get Local facts
ansible -i hosts mrx -m setup -a "filter=ansible_local"
ANSIBLE FILES & DIRS
delete all files and hidden files in a directory
vars:
app_home: /var/opt/application
tasks:
- name: clear home dir
- shell: "ls -la {{ app_home }}/"
register: files_to_delete
- file: path="{{ app_home }}/{{ item }}" state=absent
with_items: "{{ files_to_delete.stdout_lines }}"
get files from node
ansible node1 -s -m fetch -a "src=/etc/hosts dest=/tmp"
copy file to node
ansible node1 -m copy -a "src=/etc/hosts dest=/tmp/hosts"
remove all files matching a wildcard
file: path={{ item }} state=absent
with_fileglob: /tmp/*.rpm
ANSIBLE USER AND GROUP MGMT
change user password for user Joe (user Fred running the cmd as sudo on the target box)
# 1 install passlib
pip install passlib
#2 update the pw, using a hash
ansible targethost -s -m user -a "name=joe update_password=always password={{ 'MyNewPassword' | password_hash('sha512') }}" -u fred --ask-sudo-pass
copy public ssh key to remote authorized_keys file
- hosts: targetHost
tasks:
- name: update nessus SSH keys
become_user: root
become_method: sudo
become: true
authorized_key:
user: nessus
key: "{{ lookup('pipe','cat ../files/ssh_keys/nessus.pub') }}"
state: present
ANSIBLE PLAYBOOKS
run playbook with sudo
ansible-playbook -v config-users.yaml --sudo --sudo-user=joe --ask-sudo-pass
use different Hosts file
ansible-playbook -v -i /path/to/hosts
run playbook but only a specific task (tag)
ansible-playbook playbooks/restore_bitbucket.yaml -i hosts --tags rsync
or to skip: (--skip-tags tag1, tag2)
store output of a command as a variable
shell: cat /etc/network | grep eth0
register: address
debug: msg="address is {{ address.stdout }}"
configure multiple items with one task
- name: more complex items to add several users
user:
name: "{{ item.name }}"
uid: "{{ item.uid }}"
groups: "{{ item.groups }}"
state: present
with_items:
- { name: testuser1, uid: 1002, groups: "wheel, staff" }
- { name: testuser2, uid: 1003, groups: staff }
get path location of current Playbook (pwd)
{{ playbook_dir }}
Set playbook to be verbose by default
- hosts: blah
strategy: debug
run playbook with verbose traceback
ansible-playbook -i hosts myPlaybook.yaml -vvv
run playbook on multiple Host groups
- hosts: "search_head, deployer"
Run playbook locally on host
hosts: 127.0.0.1
connection: local
Prompt for password during Playbook run
# Playbook to change user password
- name: pw change
hosts: target
become: true
become_user: root
vars_prompt:
- name: username
prompt: "enter username for which to change the pw"
- name: password
prompt: "enter new password"
private: yes
tasks:
- name: change pw
user: "name={{ username }} password={{ password }} update_password=always"
run playbook with "dry run" / NOOP / simulate
ansible-playbook foo.yml --check
Run task on different target,
- name: run something on some other server
debug: msg="running stuff"
delegate_to: someserver
Delegate task to a host group
- name: restart web servers
service: name=memcached state=restarted
delegate_to: "{{ item }}"
with_items: "{{ groups['webservers'] }}"
Get IP or facter of a remote host
- name: get IP
debug: msg="{{ hostvars['nycweb01']['ansible_default_ipv4']['address'] }}"
or
debug: msg="{{ hostvars[item]['ansible_ssh_host'] }}"
with_items: "{{ groups['webservers'] }}"
synchronize file (copy file from Ansible host to target)
- synchronize:
src: "{{ playbook_dir }}/files/vscode.repo"
dest: /etc/yum.repos.d/
synchronize from server A to server B with a wildcard
- name: copy Splunk Apps
synchronize:
src: "/opt/splunk/etc/apps/{{ item }}" (server A)
dest: "/opt/splunk/etc/shcluster/apps/" (server B)
with_items:
- item1
- item2
delegate_to: server A
wget a file to a location
- get_url:
url: 'https://dl.google.com/go/go1.10.linux-amd64.tar.gz'
dest: '/tmp'
force: no # dont download if file already exists
untar tar.gz
Ansible Variables inside Inventory Hosts file
cat hosts
[web]
nycweb01.company.local
[web:vars]
role="super duper web server"
now get the "role" variable inside the playbook,
- hosts: web
gather_facts: true
tasks:
- name: print Role var
debug: msg={{ role }}
// super duper web server
Subscribe to:
Comments (Atom)
Git
1 git add ↳ It lets you add changes from the working directory into the staging area 2 git commit ↳ It lets you save a snapshot of currently...
-
https://github.com/crossplane-contrib
-
https://docs.aws.amazon.com/eks/latest/userguide/create-cluster.html
-
awk '{u=$2+$4; t=$2+$4+$5; if (NR==1){u1=u; t1=t;} else print ($2+$4-u1) * 100 / (t-t1) "%"; }' \ <(grep 'cpu ...