FAQs

Frequently Asked Questions


- name: Scale a Kubernetes Deployment
  hosts: localhost
  tasks:
    - name: Scale deployment to 5 replicas
      community.kubernetes.k8s:
        api_version: apps/v1
        kind: Deployment
        name: nginx-deployment
        namespace: default
        definition:
          spec:
            replicas: 5
- name: Stop and remove a Docker container
  hosts: all
  tasks:
    - name: Stop container
      community.docker.docker_container:
        name: nginx_server
        state: stopped

    - name: Remove container
      community.docker.docker_container:
        name: nginx_server
        state: absent
Use dry-run mode:
ansible-playbook playbook.yml --check
Debug Ansible errors:
ansible-playbook playbook.yml -vvv
Use Post-Build Actions in a Freestyle Job:
  • Select "Run Ansible Playbook" after a successful build.
Or, in a Pipeline Script, add:
post {
    success {
        sh 'ansible-playbook -i inventory.ini deploy.yml'
    }
}
- name: Update Kubernetes Deployment Image
  hosts: localhost
  tasks:
    - name: Update deployment image
      community.kubernetes.k8s:
        api_version: apps/v1
        kind: Deployment
        name: nginx-deployment
        namespace: default
        definition:
          spec:
            template:
              spec:
                containers:
                  - name: nginx
                    image: nginx:1.21.6
You can use Ansible to install the Chef client and configure it on multiple servers. Example playbook:
- name: Install Chef Client
  hosts: all
  tasks:
    - name: Download Chef installer
      get_url:
        url: https://packages.chef.io/files/stable/chef/17.10.0/el/7/chef-17.10.0-1.el7.x86_64.rpm
        dest: /tmp/chef.rpm

    - name: Install Chef
      yum:
        name: /tmp/chef.rpm
        state: present

    - name: Create Chef client configuration
      copy:
        dest: /etc/chef/client.rb
        content: |
          chef_server_url "https://chef-server.example.com"
          validation_client_name "my-validator"
Run with:
ansible-playbook -i inventory.ini install_chef.yml
You can use Ansible to install and configure the Puppet agent on multiple servers. Example playbook:
- name: Install Puppet Agent
  hosts: all
  tasks:
    - name: Install Puppet
      apt:
        name: puppet-agent
        state: present

    - name: Start Puppet Agent
      service:
        name: puppet
        state: started
        enabled: yes
You can use Ansible to install and configure Salt Minion on multiple servers:
- name: Install Salt Minion
  hosts: all
  tasks:
    - name: Install Salt Minion
      apt:
        name: salt-minion
        state: present

    - name: Configure Salt Minion
      copy:
        dest: /etc/salt/minion
        content: |
          master: salt-master.example.com
          id: {{ inventory_hostname }}

    - name: Start Salt Minion
      service:
        name: salt-minion
        state: started
        enabled: yes
Add the user to the Docker group:
- name: Add user to Docker group
  hosts: all
  tasks:
    - name: Add user to Docker group
      user:
        name: ansible
        groups: docker
        append: yes
Write a Terraform script to create resources:
resource "aws_instance" "web" {
  ami           = "ami-123456"
  instance_type = "t2.micro"
}
output "public_ip" {
  value = aws_instance.web.public_ip
}
Export the output for Ansible:
terraform output -json > terraform_outputs.json
Use Ansible to configure the instance:
ansible-playbook -i inventory.ini playbook.yml