Browse Docs

Ansible

In this section

  • Collection
    • List
    1ansible-galaxy collection list
    
    • Install an Ansible Collection
     1# From Ansible Galaxy official repo
     2ansible-galaxy collection install community.general
     3
     4# From a tarball locally
     5ansible-galaxy collection install ./community-general-6.0.0.tar.gz
     6
     7# From custom Repo
     8ansible-galaxy collection install git+https://git.example.com/projects/namespace.collectionName.git
     9ansible-galaxy collection install git+https://git.example.com/projects/namespace.collectionName,v1.0.2
    10ansible-galaxy collection install git+https://git.example.com/namespace/collectionName.git
    11
    12# From a requirement.yml file
    13ansible-galaxy collection install -r ./requirement.yaml
    
    • Requirement file to install Ansible Collection
    1collections:
    2- name: kubernetes.core
    3
    4- source: https://gitlab.example.com/super-group/collector.git
    5  type: git
    6  version: "v1.0.6"
    7
    8- source: https://gitlab.ipolicedev.int/another-projects/plates.git
    9  type: git
    
  • Inventory
    1ansible-inventory --list | jq -r 'map_values(select(.hosts != null and (.hosts | contains(["myhost"])))) | keys[]'
    
    1kafka_host: "[{{ groups['KAFKA'] | map('extract', hostvars, 'inventory_hostname') | map('regex_replace', '^', '\"') | map('regex_replace', '\\\"', '\"') | map('regex_replace', '$', ':'+ kafka_port +'\"') | join(', ') }}]"
    2
    3elasticsearch_host: "{{ groups['ELASTICSEARCH'] | map('extract', hostvars, 'inventory_hostname') | map('regex_replace', '^', '\"') | map('regex_replace', '\\\"', '\"') | map('regex_replace', '$', ':'+ elasticsearch_port +'\"') | join(', ') }}"
    
  • Pull
    • Test locally a playbook
    1ansible-pull -U https://github.com/MozeBaltyk/Okub.git ./playbooks/tasks/provision.yml
    
    • Inside a cloud-init
     1#cloud-config
     2timezone: ${timezone}
     3
     4packages:
     5  - qemu-guest-agent
     6  - git
     7
     8package_update: true
     9package_upgrade: true
    10
    11
    12## Test 1
    13ansible:
    14  install_method: pip
    15  package_name: ansible-core
    16  run_user: ansible
    17  galaxy:
    18    actions:
    19      - ["ansible-galaxy", "collection", "install", "community.general"]
    20      - ["ansible-galaxy", "collection", "install", "ansible.posix"]
    21      - ["ansible-galaxy", "collection", "install", "ansible.utils"]
    22  pull:
    23    playbook_name: ./playbooks/tasks/provision.yml
    24    url: "https://github.com/MozeBaltyk/Okub.git"
    25
    26## Test 2
    27ansible:
    28  install_method: pip
    29  package_name: ansible
    30  #run_user only with install_method: pip
    31  run_user: ansible
    32  setup_controller:
    33    repositories:
    34      - path: /home/ansible/Okub
    35        source: https://github.com/MozeBaltyk/Okub.git
    36    run_ansible:
    37      - playbook_dir: /home/ansible/Okub
    38        playbook_name: ./playbooks/tasks/provision.yml
    39########
    
    • Troubleshooting
    1systemctl --failed
    2systemctl list-jobs --after
    3journalctl -e
    

    Checks user-data and config:

Thursday, January 15, 2026 Monday, January 1, 1