diff --git a/knowledge base/ansible.md b/knowledge base/ansible.md index 67b9c3d..b838495 100644 --- a/knowledge base/ansible.md +++ b/knowledge base/ansible.md @@ -40,7 +40,7 @@ pip3 install --user 'ansible' brew install 'ansible' 'sshpass' # darwin sudo pamac install 'ansible' 'sshpass' # manjaro linux -# Generate an example configuration file with all entries disabled. +# Generate example configuration files with entries disabled. ansible-config init --disabled > 'ansible.cfg' ansible-config init --disabled -t 'all' > 'ansible.cfg' @@ -49,6 +49,11 @@ ansible -i 'path/to/hosts/file' -m 'setup' all ansible -i 'host1,hostN,' -m 'setup' 'host1' -u 'remote-user' ansible -i 'localhost,' -c 'local' -km 'setup' 'localhost' +# List hosts. +ansible-inventory -i 'inventory' --list +ansible-playbook -i 'inventory' 'playbook.yml' --list-hosts +ansible -i 'inventory' all --list-hosts + # Check the syntax of a playbook. # This will *not* execute the plays inside it. ansible-playbook 'path/to/playbook.yml' --syntax-check @@ -56,7 +61,7 @@ ansible-playbook 'path/to/playbook.yml' --syntax-check # Execute playbooks. ansible-playbook 'path/to/playbook.yml' -i 'hosts.list' ansible-playbook … -i 'host1,host2,hostN,' -l 'hosts,list' -ansible-playbook … -i 'host1,host2,other,' -l 'hosts-pattern' +ansible-playbook … -i 'host1,host2,other,' -l 'hosts-pattern' --step # Show what changes (with details) a play would apply to the local machine. ansible-playbook 'path/to/playbook.yml' -i 'localhost,' -c 'local' -vvC diff --git a/snippets/ansible.sh b/snippets/ansible.sh new file mode 100644 index 0000000..bdf63bd --- /dev/null +++ b/snippets/ansible.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env sh + +# Generate example configuration files with entries disabled. +ansible-config init --disabled > 'ansible.cfg' +ansible-config init --disabled -t 'all' > 'ansible.cfg' + +# List hosts. +ansible-inventory -i 'aws_ec2.yml' --list +ansible-playbook -i 'self-hosting.yml' 'gitlab.yml' --list-hosts +ansible -i 'webservers.yml' all --list-hosts + +# Show hosts' ansible facts. +ansible -i 'inventory.yml' -m 'setup' all +ansible -i '192.168.1.34,gitlab.lan,' -m 'setup' 'gitlab.lan' -u 'admin' +ansible -i 'localhost,' -c 'local' -km 'setup' 'localhost' + +# List tasks what would be executed. +ansible-playbook 'gitlab.yml' --list-tasks +ansible-playbook 'gitlab.yml' --list-tasks --tags 'configuration,packages' +ansible-playbook 'gitlab.yml' --list-tasks --skip-tags 'system,user' + +# Create new roles. +ansible-galaxy init 'gitlab' +ansible-galaxy role init --type 'container' --init-path 'gitlab' 'name' + +# Apply changes. +ansible-playbook \ + -i 'aws_ec2.yml' -e 'ansible_aws_ssm_plugin=/usr/local/sessionmanagerplugin/bin/session-manager-plugin' \ + -D --step \ + 'gitlab.yml'