Ansible: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
|||
(126 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
< | <syntaxhighlight lang="bash"> | ||
sudo apt update && sudo apt list --upgradeable | sudo apt update && sudo apt list --upgradeable | ||
sudo apt | sudo apt upgrade && sudo apt install ansible ansible-lint sshpass | ||
sshpass -V | |||
ansible --version | ansible --version | ||
</source> | ansible-lint --version | ||
</syntaxhighlight> | |||
== Playbook == | |||
{| | |||
| valign="top" colspan="2" | | |||
chorke-academia-project | |||
├─ main_playbook.yml | |||
└─ inventories/ | |||
├─ staging/ | |||
│ └─ academia/ | |||
│ ├─ inventory.yml | |||
│ └─ group_vars/ | |||
│ ├─ academia_group.yaml | |||
│ └─ all.yaml | |||
└─ test/ | |||
└─ academia/ | |||
├─ inventory.yml | |||
└─ group_vars/ | |||
├─ academia_group.yaml | |||
└─ all.yaml | |||
| valign="top" | | |||
<syntaxhighlight lang="properties"> | |||
all: | |||
children: | |||
gtw_servers: | |||
hosts: | |||
10.20.30.1: | |||
dmz_servers: | |||
hosts: | |||
10.20.30.100: | |||
dns_servers: | |||
hosts: | |||
10.20.30.[100:102]: | |||
vars: | |||
ansible_port: 4321 | |||
ansible_user: deploy | |||
ansible_ssh_pass: sadaqah | |||
</syntaxhighlight> | |||
|- | |||
| colspan="3" | | |||
---- | |||
|- | |||
| valign="top" colspan="3" | | |||
<syntaxhighlight lang="bash"> | |||
mkdir -p chorke-academia-project/inventories/{staging,test}/academia/{group_vars,host_vars} | |||
touch chorke-academia-project/inventories/{staging,test}/academia/group_vars/{all,academia_group}.yaml | |||
touch chorke-academia-project/inventories/{staging,test}/academia/inventory.yml | |||
touch chorke-academia-project/main_playbook.yml | |||
cd chorke-academia-project | |||
ansible-playbook -i inventories/staging main_playbook.yml | |||
ansible-inventory -i inventories/staging --list | |||
</syntaxhighlight> | |||
|} | |||
== Playbook » LXD== | |||
{| | |||
|valign="top"| | |||
<syntaxhighlight lang="yaml" highlight="4,12,36,39-43,65-67" line> | |||
mkdir -p ~/Documents/ansible-playground | |||
cd ~/Documents/ansible-playground | |||
cat << 'YML' | tee ./lxd-launch-ubuntu-24-lts.yml >/dev/null | |||
--- | |||
- name: LXD Launch Ubuntu 24.04 LTS | |||
hosts: localhost | |||
connection: local | |||
vars: | |||
cpu_architecture: "{{ ansible_architecture }}" | |||
os_family: "{{ ansible_os_family }}" | |||
container_name: ubuntu-24-lts | |||
tasks: | |||
- name: Dirty Facts | |||
set_fact: | |||
raw_cpu_family: > | |||
{% if ansible_architecture == 'x86_64' %} | |||
amd64 | |||
{% elif ansible_architecture == 'aarch64' %} | |||
arm64 | |||
{% else %} | |||
{{ ansible_architecture }} | |||
{% endif %} | |||
delegate_to: localhost | |||
- name: Clean Facts | |||
set_fact: | |||
cpu_family: "{{ raw_cpu_family | trim }}" | |||
delegate_to: localhost | |||
- name: Launch Container | |||
community.general.lxd_container: | |||
name: "{{ container_name }}" | |||
ignore_volatile_options: true | |||
type: container | |||
state: started | |||
source: | |||
mode: pull | |||
type: image | |||
protocol: simplestreams | |||
server: https://cloud-images.ubuntu.com/releases | |||
alias: 24.04/{{ cpu_family }} | |||
profiles: ["default"] | |||
wait_for_ipv4_addresses: true | |||
timeout: 600 | |||
- name: Check Python | |||
delegate_to: "{{ container_name }}" | |||
ansible.builtin.raw: | | |||
lxc exec {{ container_name }} -- dpkg -s python3.11 | |||
register: python_install_check | |||
failed_when: python_install_check.rc not in [0, 1] | |||
changed_when: false | |||
- name: Install Python | |||
delegate_to: "{{ container_name }}" | |||
ansible.builtin.raw: | | |||
lxc exec {{ container_name }} -- apt-get update | |||
lxc exec {{ container_name }} -- apt-get install -y python3.11 | |||
lxc exec {{ container_name }} -- apt-get clean | |||
when: python_install_check.rc == 1 | |||
YML | |||
ansible-playbook lxd-launch-ubuntu-24-lts.yml | |||
lxc exec ubuntu-24-lts -- bash | |||
lxc rm ubuntu-24-lts -f | |||
lxc ls | |||
</syntaxhighlight> | |||
|valign="top"| | |||
<syntaxhighlight lang="yaml" highlight="4,12,36,39-43,65-67" line> | |||
mkdir -p ~/Documents/ansible-playground | |||
cd ~/Documents/ansible-playground | |||
cat << 'YML' | tee ./lxd-launch-ubuntu-24-lts-vm.yml >/dev/null | |||
--- | |||
- name: LXD Launch Ubuntu 24.04 LTS | |||
hosts: localhost | |||
connection: local | |||
vars: | |||
cpu_architecture: "{{ ansible_architecture }}" | |||
os_family: "{{ ansible_os_family }}" | |||
container_name: ubuntu-24-lts-vm | |||
tasks: | |||
- name: Dirty Facts | |||
set_fact: | |||
raw_cpu_family: > | |||
{% if ansible_architecture == 'x86_64' %} | |||
amd64 | |||
{% elif ansible_architecture == 'aarch64' %} | |||
arm64 | |||
{% else %} | |||
{{ ansible_architecture }} | |||
{% endif %} | |||
delegate_to: localhost | |||
- name: Clean Facts | |||
set_fact: | |||
cpu_family: "{{ raw_cpu_family | trim }}" | |||
delegate_to: localhost | |||
- name: Launch Container | |||
community.general.lxd_container: | |||
name: "{{ container_name }}" | |||
ignore_volatile_options: true | |||
type: virtual-machine | |||
state: started | |||
source: | |||
mode: pull | |||
type: image | |||
protocol: simplestreams | |||
server: https://cloud-images.ubuntu.com/releases | |||
alias: 24.04/{{ cpu_family }} | |||
profiles: ["default"] | |||
wait_for_ipv4_addresses: true | |||
timeout: 600 | |||
- name: Check Python | |||
delegate_to: "{{ container_name }}" | |||
ansible.builtin.raw: | | |||
lxc exec {{ container_name }} -- dpkg -s python3.11 | |||
register: python_install_check | |||
failed_when: python_install_check.rc not in [0, 1] | |||
changed_when: false | |||
- name: Install Python | |||
delegate_to: "{{ container_name }}" | |||
ansible.builtin.raw: | | |||
lxc exec {{ container_name }} -- apt-get update | |||
lxc exec {{ container_name }} -- apt-get install -y python3.11 | |||
lxc exec {{ container_name }} -- apt-get clean | |||
when: python_install_check.rc == 1 | |||
YML | |||
ansible-playbook lxd-launch-ubuntu-24-lts-vm.yml | |||
lxc exec ubuntu-24-lts-vm -- bash | |||
lxc rm ubuntu-24-lts-vm -f | |||
lxc ls | |||
</syntaxhighlight> | |||
|} | |||
== Molecule == | |||
mkdir molecule-example && cd molecule-example | |||
python3 -m venv .venv --prompt="molecule" | |||
source ./.venv/bin/activate | |||
pip install 'molecule[lint]' | |||
pip install molecule-podman | |||
pip freeze > requirements.txt | |||
molecule init role 'acme.mywebapp' --driver-name podman | |||
== Modules == | |||
{| | |||
| valign="top" | | |||
* [https://docs.ansible.com/ansible/latest/collections/ansible/builtin/unarchive_module.html <code>ansible.builtin.unarchive</code>] | |||
| valign="top" | | |||
| valign="top" | | |||
|- | |||
| colspan="3" | | |||
---- | |||
|- | |||
| valign="top" | | |||
* [https://docs.ansible.com/ansible/latest/collections/community/general/apache2_mod_proxy_module.html <code>community.general.apache2_mod_proxy</code>] | |||
* [https://docs.ansible.com/ansible/latest/collections/community/general/rpm_ostree_pkg_module.html <code>community.general.rpm_ostree_pkg</code>] | |||
* [https://docs.ansible.com/ansible/latest/collections/community/general/iso_customize_module.html <code>community.general.iso_customize</code>] | |||
* [https://docs.ansible.com/ansible/latest/collections/community/general/iso_extract_module.html <code>community.general.iso_extract</code>] | |||
* [https://docs.ansible.com/ansible/latest/collections/community/general/iso_create_module.html <code>community.general.iso_create</code>] | |||
* [https://docs.ansible.com/ansible/latest/collections/community/general/apt_repo_module.html <code>community.general.apt_repo</code>] | |||
* [https://docs.ansible.com/ansible/latest/collections/community/general/apt_rpm_module.html <code>community.general.apt_rpm</code>] | |||
* [https://docs.ansible.com/ansible/latest/collections/community/general/bower_module.html <code>community.general.bower</code>] | |||
* [https://docs.ansible.com/ansible/latest/collections/community/general/cargo_module.html <code>community.general.cargo</code>] | |||
* [https://docs.ansible.com/ansible/latest/collections/community/general/apk_module.html <code>community.general.apk</code>] | |||
| valign="top" | | |||
* [https://docs.ansible.com/ansible/latest/collections/community/general/bitbucket_pipeline_known_host_module.html <code>community.general.bitbucket_pipeline_known_host</code>] | |||
* [https://docs.ansible.com/ansible/latest/collections/community/general/bitbucket_pipeline_variable_module.html <code>community.general.bitbucket_pipeline_variable</code>] | |||
* [https://docs.ansible.com/ansible/latest/collections/community/general/bitbucket_pipeline_key_pair_module.html <code>community.general.bitbucket_pipeline_key_pair</code>] | |||
* [https://docs.ansible.com/ansible/latest/collections/community/general/bitbucket_access_key_module.html <code>community.general.bitbucket_access_key</code>] | |||
* [https://docs.ansible.com/ansible/latest/collections/community/general/jenkins_job_info_module.html <code>community.general.jenkins_job_info</code>] | |||
* [https://docs.ansible.com/ansible/latest/collections/community/general/jenkins_plugin_module.html <code>community.general.jenkins_plugin</code>] | |||
* [https://docs.ansible.com/ansible/latest/collections/community/general/jenkins_script_module.html <code>community.general.jenkins_script</code>] | |||
* [https://docs.ansible.com/ansible/latest/collections/community/general/jenkins_build_module.html <code>community.general.jenkins_build</code>] | |||
* [https://docs.ansible.com/ansible/latest/collections/community/general/jenkins_job_module.html <code>community.general.jenkins_job</code>] | |||
* [https://docs.ansible.com/ansible/latest/collections/community/general/java_cert_module.html <code>community.general.java_cert</code>] | |||
| valign="top" | | |||
* [https://docs.ansible.com/ansible/latest/collections/community/general/nginx_status_info_module.html <code>community.general.nginx_status_info</code>] | |||
* [https://docs.ansible.com/ansible/latest/collections/community/general/dnf_versionlock_module.html <code>community.general.dnf_versionlock</code>] | |||
* [https://docs.ansible.com/ansible/latest/collections/community/general/cloudflare_dns_module.html <code>community.general.cloudflare_dns</code>] | |||
* [https://docs.ansible.com/ansible/latest/collections/community/general/java_keystore_module.html <code>community.general.java_keystore</code>] | |||
* [https://docs.ansible.com/ansible/latest/collections/community/general/lxd_container_module.html <code>community.general.lxd_container</code>] | |||
* [https://docs.ansible.com/ansible/latest/collections/community/general/openwrt_init_module.html <code>community.general.openwrt_init</code>] | |||
* [https://docs.ansible.com/ansible/latest/collections/community/general/archive_module.html <code>community.general.archive</code>] | |||
* [https://docs.ansible.com/ansible/latest/collections/community/general/redis_module.html <code>community.general.redis</code>] | |||
* [https://docs.ansible.com/ansible/latest/collections/community/general/nmcli_module.html <code>community.general.nmcli</code>] | |||
* [https://docs.ansible.com/ansible/latest/collections/community/general/npm_module.html <code>community.general.npm</code>] | |||
|- | |||
| colspan="3" | | |||
---- | |||
|- | |||
| valign="top" | | |||
* [https://docs.ansible.com/ansible/latest/collections/community/general/yarn_module.html <code>community.general.yarn</code>] | |||
| valign="top" | | |||
| valign="top" | | |||
|- | |||
| colspan="3" | | |||
---- | |||
|- | |||
| valign="top" | | |||
* [https://docs.ansible.com/ansible/latest/collections/community/docker/docker_config_module.html <code>community.docker.docker_config</code>] | |||
* [https://docs.ansible.com/ansible/latest/collections/community/docker/docker_image_module.html <code>community.docker.docker_image</code>] | |||
* [https://docs.ansible.com/ansible/latest/collections/community/docker/ <code>Community.Docker</code>] | |||
| valign="top" | | |||
| valign="top" | | |||
|- | |||
| colspan="3" | | |||
---- | |||
|- | |||
| valign="top" | | |||
* [https://docs.ansible.com/ansible/latest/collections/community/windows/win_iis_virtualdirectory_module.html <code>community.windows.win_iis_virtualdirectory</code>] | |||
* [https://docs.ansible.com/ansible/latest/collections/community/windows/win_iis_webapplication_module.html <code>community.windows.win_iis_webapplication</code>] | |||
* [https://docs.ansible.com/ansible/latest/collections/community/windows/win_security_policy_module.html <code>community.windows.win_security_policy</code>] | |||
* [https://docs.ansible.com/ansible/latest/collections/community/windows/win_iis_webapppool_module.html <code>community.windows.win_iis_webapppool</code>] | |||
* [https://docs.ansible.com/ansible/latest/collections/community/windows/win_iis_webbinding_module.html <code>community.windows.win_iis_webbinding</code>] | |||
* [https://docs.ansible.com/ansible/latest/collections/community/windows/win_iis_website_module.html <code>community.windows.win_iis_website</code>] | |||
* [https://docs.ansible.com/ansible/latest/collections/community/windows/win_wakeonlan_module.html <code>community.windows.win_wakeonlan</code>] | |||
* [https://docs.ansible.com/ansible/latest/collections/community/windows/win_shortcut_module.html <code>community.windows.win_shortcut</code>] | |||
* [https://docs.ansible.com/ansible/latest/collections/community/windows/win_robocopy_module.html <code>community.windows.win_robocopy</code>] | |||
* [https://docs.ansible.com/ansible/latest/collections/community/windows/win_timezone_module.html <code>community.windows.win_timezone</code>] | |||
| valign="top" | | |||
* [https://docs.ansible.com/ansible/latest/collections/community/windows/win_firewall_rule_module.html <code>community.windows.win_firewall_rule</code>] | |||
* [https://docs.ansible.com/ansible/latest/collections/community/windows/win_firewall_module.html <code>community.windows.win_firewall</code>] | |||
* [https://docs.ansible.com/ansible/latest/collections/community/windows/win_regmerge_module.html <code>community.windows.win_regmerge</code>] | |||
* [https://docs.ansible.com/ansible/latest/collections/community/windows/win_format_module.html <code>community.windows.win_format</code>] | |||
* [https://docs.ansible.com/ansible/latest/collections/community/windows/win_route_module.html <code>community.windows.win_route</code>] | |||
* [https://docs.ansible.com/ansible/latest/collections/community/windows/win_unzip_module.html <code>community.windows.win_unzip</code>] | |||
* [https://docs.ansible.com/ansible/latest/collections/community/windows/psexec_module.html <code>community.windows.psexec</code>] | |||
| valign="top" | | |||
|- | |||
| colspan="3" | | |||
---- | |||
|- | |||
| valign="top" | | |||
* [https://docs.ansible.com/ansible/latest/collections/community/general/homebrew_cask_module.html <code>community.general.homebrew_cask</code>] | |||
* [https://docs.ansible.com/ansible/latest/collections/community/general/homebrew_tap_module.html<code>community.general.homebrew_tap</code>] | |||
* [https://docs.ansible.com/ansible/latest/collections/community/general/homebrew_module.html <code>community.general.homebrew</code>] | |||
* [https://docs.ansible.com/ansible/latest/collections/community/general/launchd_module.html <code>community.general.launchd</code>] | |||
| valign="top" | | |||
| valign="top" | | |||
|} | |||
== Namespaces == | |||
{| | |||
| valign="top" | | |||
* [https://docs.ansible.com/ansible/latest/collections/community/digitalocean/ <code>community.digitalocean</code>] | |||
* [https://docs.ansible.com/ansible/latest/collections/community/hashi_vault/ <code>community.hashi_vault</code>] | |||
* [https://docs.ansible.com/ansible/latest/collections/community/postgresql/ <code>community.postgresql</code>] | |||
* [https://docs.ansible.com/ansible/latest/collections/community/general/ <code>community.general</code>] | |||
* [https://docs.ansible.com/ansible/latest/collections/community/windows/ <code>community.windows</code>] | |||
* [https://docs.ansible.com/ansible/latest/collections/community/libvirt/ <code>community.libvirt</code>] | |||
* [https://docs.ansible.com/ansible/latest/collections/community/network/ <code>community.network</code>] | |||
* [https://docs.ansible.com/ansible/latest/collections/community/mongodb/ <code>community.mongodb</code>] | |||
* [https://docs.ansible.com/ansible/latest/collections/community/vmware/ <code>community.vmware</code>] | |||
* [https://docs.ansible.com/ansible/latest/collections/community/mysql/ <code>community.mysql</code>] | |||
| valign="top" | | |||
* [https://docs.ansible.com/ansible/latest/collections/community/rabbitmq/ <code>community.rabbitmq</code>] | |||
* [https://docs.ansible.com/ansible/latest/collections/community/routeros/ <code>community.routeros</code>] | |||
* [https://docs.ansible.com/ansible/latest/collections/community/skydive/ <code>community.skydive</code>] | |||
* [https://docs.ansible.com/ansible/latest/collections/community/grafana/ <code>community.grafana</code>] | |||
* [https://docs.ansible.com/ansible/latest/collections/community/crypto/ <code>community.crypto</code>] | |||
* [https://docs.ansible.com/ansible/latest/collections/community/docker/ <code>community.docker</code>] | |||
* [https://docs.ansible.com/ansible/latest/collections/community/google/ <code>community.google</code>] | |||
* [https://docs.ansible.com/ansible/latest/collections/community/azure/ <code>community.azure</code>] | |||
* [https://docs.ansible.com/ansible/latest/collections/community/aws/ <code>community.aws</code>] | |||
* [https://docs.ansible.com/ansible/latest/collections/community/dns/ <code>community.dns</code>] | |||
| valign="top" | | |||
* [https://docs.ansible.com/ansible/latest/collections/openvswitch/openvswitch/ <code>openvswitch.openvswitch</code>] | |||
* [https://docs.ansible.com/ansible/latest/collections/chocolatey/ <code>chocolatey.chocolatey</code>] | |||
* [https://docs.ansible.com/ansible/latest/collections/azure/azcollection/ <code>azure.azcollection</code>] | |||
* [https://docs.ansible.com/ansible/latest/collections/containers/podman/ <code>containers.podman</code>] | |||
* [https://docs.ansible.com/ansible/latest/collections/check_point/mgmt/ <code>check_point.mgmt</code>] | |||
* [https://docs.ansible.com/ansible/latest/collections/kubernetes/core/ <code>kubernetes.core</code>] | |||
* [https://docs.ansible.com/ansible/latest/collections/openstack/ <code>openstack.cloud</code>] | |||
* [https://docs.ansible.com/ansible/latest/collections/amazon/ <code>amazon.aws</code>] | |||
|- | |||
| colspan="3" | | |||
---- | |||
|- | |||
| valign="top" | | |||
* [https://docs.ansible.com/ansible/latest/collections/ansible/netcommon/ <code>ansible.netcommon</code>] | |||
* [https://docs.ansible.com/ansible/latest/collections/ansible/builtin/ <code>ansible.builtin</code>] | |||
* [https://docs.ansible.com/ansible/latest/collections/ansible/windows/ <code>ansible.windows</code>] | |||
* [https://docs.ansible.com/ansible/latest/collections/ansible/posix/ <code>ansible.posix</code>] | |||
* [https://docs.ansible.com/ansible/latest/collections/ansible/utils/ <code>ansible.utils</code>] | |||
| valign="top" | | |||
| valign="top" | | |||
|} | |||
==Knowledge== | |||
{| | |||
| valign="top" | | |||
<syntaxhighlight lang="bash"> | |||
python3 -m venv .venv --prompt="Molecule" | |||
# source .venv/bin/activate | |||
# (Molecule) $ | |||
</syntaxhighlight> | |||
| valign="top" | | |||
<syntaxhighlight lang="bash"> | |||
python3 -m venv .venv --prompt="Molecule" | |||
# source .venv/bin/activate | |||
# (Molecule) $ | |||
</syntaxhighlight> | |||
| valign="top" | | |||
<syntaxhighlight lang="PowerShell"> | |||
python -m venv .venv --prompt="Molecule" | |||
# .venv\Scripts\activate | |||
# (Molecule) PS> | |||
</syntaxhighlight> | |||
|- | |||
| colspan="3" | | |||
---- | |||
|- | |||
| valign="top" | | |||
<syntaxhighlight lang="bash"> | |||
pip install -r requirements.txt | |||
pip freeze > requirements.txt | |||
</syntaxhighlight> | |||
| valign="top" | | |||
<syntaxhighlight lang="ini"> | |||
[all:vars] | |||
ansible_port=22 | |||
</syntaxhighlight> | |||
| valign="ini" | | |||
<syntaxhighlight lang="bash"> | |||
ansible_connection=ssh | |||
ansible_ssh_pass=vagrant | |||
</syntaxhighlight> | |||
|- | |||
| colspan="3" | | |||
---- | |||
|- | |||
| valign="top"| | |||
<syntaxhighlight lang="bash"> | |||
ansible-inventory\ | |||
-i inventories/staging/\ | |||
--list | |||
</syntaxhighlight> | |||
| valign="top"| | |||
<syntaxhighlight lang="bash"> | |||
ansible dns_servers\ | |||
-i inventories/staging/\ | |||
-m ping | |||
</syntaxhighlight> | |||
| valign="top"| | |||
<syntaxhighlight lang="bash"> | |||
ansible-playbook\ | |||
-i inventories/staging/\ | |||
main_playbook.yml | |||
</syntaxhighlight> | |||
|- | |||
| colspan="3" | | |||
---- | |||
|- | |||
| valign="top" | | |||
pip install -U pip | |||
pip install --upgrade pip | |||
| valign="bottom" | | |||
pip freeze > requirements.txt | |||
pip install -r requirements.txt --upgrade | |||
| valign="bottom" | | |||
pip list --outdated | |||
pip install pip-check | |||
|- | |||
| colspan="3" | | |||
---- | |||
|- | |||
| colspan="3" | | |||
pip list -o | gawk -F ' ' 'NR>2{print$1}' | xargs pip install -U | |||
pip list --outdated | gawk -F ' ' 'NR>2{print$1}' | xargs pip install --upgrade | |||
|} | |||
== References == | == References == | ||
{| | {| | ||
| valign="top" | | | valign="top" | | ||
* [https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-ansible-on-ubuntu-20-04 Install & Configure | * [https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-ansible-on-ubuntu-20-04 Ansible » Install & Configure on Ubuntu 20.04] | ||
* [https://www.ansible.com/blog/ansible-best-practices-essentials Ansible » Essentials Best Practices] | |||
* [https://www.digitalocean.com/community/tutorials/how-to-define-tasks-in-ansible-playbooks Ansible » Playbook » Define Tasks] | |||
* [https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_variables.html Ansible » Playbook » Variables] | |||
* [https://docs.ansible.com/ansible/latest/inventory_guide/ Ansible » Building Inventories] | |||
* [https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_filters.html Ansible » Playbook » Filters] | |||
* [https://www.redhat.com/sysadmin/developing-ansible-role Ansible » Developing Role] | |||
* [https://molecule.readthedocs.io/en/latest/ Ansible » Test » Molecule] | |||
* [https://testinfra.readthedocs.io/en/latest/ Ansible » Test » Testinfra] | |||
* [https://tox.wiki/en/latest/ Ansible » Test » Tox] | |||
| valign="top" | | | valign="top" | | ||
* [https://stackoverflow.com/questions/64905347/ Ansible » Resolve <code>inventory</code>, <code>group_vars</code> & <code>host_vars</code>] | |||
* [https://www.ansible.com/blog/developing-and-testing-ansible-roles-with-molecule-and-podman-part-1 Ansible » Test » Molecule » Podman » Roles » Part 1] | |||
* [https://www.ansible.com/blog/developing-and-testing-ansible-roles-with-molecule-and-podman-part-2 Ansible » Test » Molecule » Podman » Roles » Part 2] | |||
* [https://molecule.readthedocs.io/en/latest/getting-started.html Ansible » Test » Molecule » Getting Started] | |||
* [https://molecule.readthedocs.io/en/latest/ci.html Ansible » Test » Molecule » CI/CD] | |||
* [https://www.cherryservers.com/blog/how-to-set-up-ansible-inventory-file Ansible » Set Up Inventory File] | |||
* [https://marketplace.visualstudio.com/items?itemName=redhat.ansible Ansible » VS Code Extension] | |||
* [https://www.digitalocean.com/community/tutorials/how-to-set-up-ansible-inventories Ansible » Set Up Inventories] | |||
* [https://spacelift.io/blog/ansible-variables Ansible » Types of Variables] | |||
* [https://docs.ansible.com/ansible-tower/latest/html/userguide/ Ansible » Tower] | |||
| valign="top" | | | valign="top" | | ||
* [https://serverfault.com/questions/628989/ Ansible » Set Default User/Password for SSH] | |||
* [https://stackoverflow.com/questions/37004686/ Ansible » Prompt User/Password from CLI] | |||
|- | |- | ||
Line 19: | Line 520: | ||
|- | |- | ||
| valign="top" | | | valign="top" | | ||
* [https://realpython.com/python-virtual-environments-a-primer/ Python Virtual Environments] | |||
* [https://stackoverflow.com/questions/62209131/ Dependency File in Python] | |||
* [[VS Code on iPad Pro]] | |||
* [https://docs.fileformat.com/programming/yaml/ What is a YAML File] | |||
* [https://docs.fileformat.com/programming/yml/ What is a YML File] | |||
* [[Docker Compose]] | |||
* [[Linux Containers]] | |||
* [[Kubernetes]] | |||
* [[Podman]] | |||
* [[Docker]] | |||
| valign="top" | | | valign="top" | | ||
* [[Academia JavaEE Workspace in Raspbian]] | |||
* [[Academia JavaEE Workspace in Ubuntu]] | |||
* [[Academia JavaEE Workspace in MacOS]] | |||
* [https://dev.to/aws-builders/ssh-setup-and-tunneling-via-bastion-host-3kcc AWS » Bastion Host SSH Tunneling] | |||
* [[Sed Replace A Multi-Line String]] | |||
* [https://serverfault.com/questions/283129/ SSH Connection Hang Forever] | |||
* [https://pip.pypa.io/en/stable/cli/pip_freeze/ Python Pip Freeze] | |||
* [[Terraform]] | |||
* [[OpenVPN]] | |||
* [[Vagrant]] | |||
| valign="top" | | | valign="top" | | ||
* [https://www.activestate.com/resources/quick-reads/how-to-update-all-python-packages/ Update All Python Packages] | |||
|} | |} |
Latest revision as of 07:54, 19 May 2024
sudo apt update && sudo apt list --upgradeable
sudo apt upgrade && sudo apt install ansible ansible-lint sshpass
sshpass -V
ansible --version
ansible-lint --version
Playbook
chorke-academia-project ├─ main_playbook.yml └─ inventories/ ├─ staging/ │ └─ academia/ │ ├─ inventory.yml │ └─ group_vars/ │ ├─ academia_group.yaml │ └─ all.yaml └─ test/ └─ academia/ ├─ inventory.yml └─ group_vars/ ├─ academia_group.yaml └─ all.yaml |
all:
children:
gtw_servers:
hosts:
10.20.30.1:
dmz_servers:
hosts:
10.20.30.100:
dns_servers:
hosts:
10.20.30.[100:102]:
vars:
ansible_port: 4321
ansible_user: deploy
ansible_ssh_pass: sadaqah
| |
| ||
mkdir -p chorke-academia-project/inventories/{staging,test}/academia/{group_vars,host_vars}
touch chorke-academia-project/inventories/{staging,test}/academia/group_vars/{all,academia_group}.yaml
touch chorke-academia-project/inventories/{staging,test}/academia/inventory.yml
touch chorke-academia-project/main_playbook.yml
cd chorke-academia-project
ansible-playbook -i inventories/staging main_playbook.yml
ansible-inventory -i inventories/staging --list
|
Playbook » LXD
mkdir -p ~/Documents/ansible-playground
cd ~/Documents/ansible-playground
cat << 'YML' | tee ./lxd-launch-ubuntu-24-lts.yml >/dev/null
---
- name: LXD Launch Ubuntu 24.04 LTS
hosts: localhost
connection: local
vars:
cpu_architecture: "{{ ansible_architecture }}"
os_family: "{{ ansible_os_family }}"
container_name: ubuntu-24-lts
tasks:
- name: Dirty Facts
set_fact:
raw_cpu_family: >
{% if ansible_architecture == 'x86_64' %}
amd64
{% elif ansible_architecture == 'aarch64' %}
arm64
{% else %}
{{ ansible_architecture }}
{% endif %}
delegate_to: localhost
- name: Clean Facts
set_fact:
cpu_family: "{{ raw_cpu_family | trim }}"
delegate_to: localhost
- name: Launch Container
community.general.lxd_container:
name: "{{ container_name }}"
ignore_volatile_options: true
type: container
state: started
source:
mode: pull
type: image
protocol: simplestreams
server: https://cloud-images.ubuntu.com/releases
alias: 24.04/{{ cpu_family }}
profiles: ["default"]
wait_for_ipv4_addresses: true
timeout: 600
- name: Check Python
delegate_to: "{{ container_name }}"
ansible.builtin.raw: |
lxc exec {{ container_name }} -- dpkg -s python3.11
register: python_install_check
failed_when: python_install_check.rc not in [0, 1]
changed_when: false
- name: Install Python
delegate_to: "{{ container_name }}"
ansible.builtin.raw: |
lxc exec {{ container_name }} -- apt-get update
lxc exec {{ container_name }} -- apt-get install -y python3.11
lxc exec {{ container_name }} -- apt-get clean
when: python_install_check.rc == 1
YML
ansible-playbook lxd-launch-ubuntu-24-lts.yml
lxc exec ubuntu-24-lts -- bash
lxc rm ubuntu-24-lts -f
lxc ls
|
mkdir -p ~/Documents/ansible-playground
cd ~/Documents/ansible-playground
cat << 'YML' | tee ./lxd-launch-ubuntu-24-lts-vm.yml >/dev/null
---
- name: LXD Launch Ubuntu 24.04 LTS
hosts: localhost
connection: local
vars:
cpu_architecture: "{{ ansible_architecture }}"
os_family: "{{ ansible_os_family }}"
container_name: ubuntu-24-lts-vm
tasks:
- name: Dirty Facts
set_fact:
raw_cpu_family: >
{% if ansible_architecture == 'x86_64' %}
amd64
{% elif ansible_architecture == 'aarch64' %}
arm64
{% else %}
{{ ansible_architecture }}
{% endif %}
delegate_to: localhost
- name: Clean Facts
set_fact:
cpu_family: "{{ raw_cpu_family | trim }}"
delegate_to: localhost
- name: Launch Container
community.general.lxd_container:
name: "{{ container_name }}"
ignore_volatile_options: true
type: virtual-machine
state: started
source:
mode: pull
type: image
protocol: simplestreams
server: https://cloud-images.ubuntu.com/releases
alias: 24.04/{{ cpu_family }}
profiles: ["default"]
wait_for_ipv4_addresses: true
timeout: 600
- name: Check Python
delegate_to: "{{ container_name }}"
ansible.builtin.raw: |
lxc exec {{ container_name }} -- dpkg -s python3.11
register: python_install_check
failed_when: python_install_check.rc not in [0, 1]
changed_when: false
- name: Install Python
delegate_to: "{{ container_name }}"
ansible.builtin.raw: |
lxc exec {{ container_name }} -- apt-get update
lxc exec {{ container_name }} -- apt-get install -y python3.11
lxc exec {{ container_name }} -- apt-get clean
when: python_install_check.rc == 1
YML
ansible-playbook lxd-launch-ubuntu-24-lts-vm.yml
lxc exec ubuntu-24-lts-vm -- bash
lxc rm ubuntu-24-lts-vm -f
lxc ls
|
Molecule
mkdir molecule-example && cd molecule-example python3 -m venv .venv --prompt="molecule" source ./.venv/bin/activate pip install 'molecule[lint]' pip install molecule-podman pip freeze > requirements.txt molecule init role 'acme.mywebapp' --driver-name podman
Modules
Namespaces
| ||
Knowledge
python3 -m venv .venv --prompt="Molecule"
# source .venv/bin/activate
# (Molecule) $
|
python3 -m venv .venv --prompt="Molecule"
# source .venv/bin/activate
# (Molecule) $
|
python -m venv .venv --prompt="Molecule"
# .venv\Scripts\activate
# (Molecule) PS>
|
| ||
pip install -r requirements.txt
pip freeze > requirements.txt
|
[all:vars]
ansible_port=22
|
ansible_connection=ssh
ansible_ssh_pass=vagrant
|
| ||
ansible-inventory\
-i inventories/staging/\
--list
|
ansible dns_servers\
-i inventories/staging/\
-m ping
|
ansible-playbook\
-i inventories/staging/\
main_playbook.yml
|
| ||
pip install -U pip pip install --upgrade pip |
pip freeze > requirements.txt pip install -r requirements.txt --upgrade |
pip list --outdated pip install pip-check |
| ||
pip list -o | gawk -F ' ' 'NR>2{print$1}' | xargs pip install -U pip list --outdated | gawk -F ' ' 'NR>2{print$1}' | xargs pip install --upgrade |