Skip to content

Instantly share code, notes, and snippets.

View duffney's full-sized avatar
⌨️
Coding

Josh Duffney duffney

⌨️
Coding
View GitHub Profile
@duffney
duffney / entrypoint.sh
Created July 26, 2020 10:10
Ansible entrypoint.sh using if statement to throw on failure
if ! ansible-playbook -i hosts_azure_rm.yml site.yml --vault-password-file .vault; then
echo "Ansible failed!"
rm .vault
exit 1
else
rm .vault
fi
@duffney
duffney / becomeAnsible_create_service_principal.ps1
Created July 20, 2020 13:55
Code Snippet for become Ansible Chapter 2 pg 18
$credentials = New-Object Microsoft.Azure.Commands.ActiveDirectory.PSADPasswordCredential -Property @{ StartDate=Get-Date; EndDate=Get-Date -Year 2024; Password='<Password>'};
$spSplat = @{ DisplayName = 'ansible' ; PasswordCredential = $credentials} ;
$sp = New-AzAdServicePrincipal @spSplat
@duffney
duffney / ansible-directory-layouts.md
Last active June 17, 2020 11:24
Ansible Directory Layouts

Basic

|-- dev
|-- production

|-- group_vars/
|   |-- all.yml
|   |-- linux.yml
| |-- windows.yml
TASK [run ping] ****************************************************************************
task path: /ansible/ping.yaml:20
<34.202.122.113> ESTABLISH SSH CONNECTION FOR USER: ansible
<34.202.122.113> SSH: EXEC sshpass -d9 ssh -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o 'User="ansible"' -o ConnectTimeout=10 -o StrictHostKeyChecking=no -o ControlPath=/root/.ansible/cp/65b11a12a7 34.202.122.113 '/bin/sh -c '"'"'echo ~ansible && sleep 0'"'"''
<34.202.122.113> (3, '', 'sshpass: Failed to run command: No such file or directory\n')
<34.202.122.113> Failed to connect to the host via ssh: sshpass: Failed to run command: No such file or directory
<34.202.122.113> ESTABLISH SSH CONNECTION FOR USER: ansible
<34.202.122.113> SSH: EXEC sshpass -d9 ssh -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o 'User="ansible"' -o ConnectTimeout=10 -o StrictHostKeyChecking=no -o ControlPath=/root/.ansible/cp/65b11a12a7 34.202.122.113 '/bin/sh -c '"'"'echo "`pwd`" && sleep 0'"'"''
<34.202.122.113> (3, '', 'sshpass:
#!/bin/bash
sudo apt-get install python -y
useradd -m -d /home/ansible -s /bin/bash ansible
echo 'ansible:P@ssw0rd'|chpasswd
echo 'ansible ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers
sudo sed -n 'H;${x;s/\PasswordAuthentication no/PasswordAuthentication yes/;p;}' /etc/ssh/sshd_config > tmp_sshd_config
sudo cat tmp_sshd_config > /etc/ssh/sshd_config
rm -f tmp_sshd_config
sudo service sshd restart
@duffney
duffney / vscode-bootstrap.ps1
Last active January 26, 2020 12:36
CloudSkills Azure DevOps VS Code Extension Bootstrap script
code --install-extension 'wilfriedwoivre.arm-params-generator';
code --install-extension 'bencoleman.armview';
code --install-extension 'msazurermtools.azurerm-vscode-tools';
code --install-extension 'samcogan.arm-snippets';
code --install-extension 'ms-vscode.azure-account';
code --install-extension 'ms-azuretools.vscode-azurefunctions';
code --install-extension 'docsmsft.docs-markdown';
code --install-extension 'docsmsft.docs-authoring-pack';
code --install-extension 'ms-azure-devops.azure-pipelines';
apiVersion: v1
kind: ConfigMap
metadata:
name: mysql-config
labels:
app: mysql
data:
mysql_binlog_format.cnf: |
[mysqld]
binlog-format=mixed
  1. Deploy v1 of the app
    kubectl apply -f archetype-deployment-and-service-recreate.yaml
    
  2. Change the .spec.template.spec.containers.image to v2
    kubectl set image deployment archetype-deployment archetype=duffney/archetype:v2
    
  3. Check pods & replicaset
  1. Edit ReplicationController or ReplicaSet.
    kubectl edit replicaset archetype
    
  2. Update Pod template to use a newer image.
    #within the config modify the template image
    #confirm settings with
    kubectl get replicaset archetype  -o yaml
    
apiVersion: apps/v1
kind: Deployment
metadata:
name: archetype-deployment
labels:
app: archetype
spec:
replicas: 3
selector:
matchLabels: