Ansible ad-hoc commands

Common Use Cases and Examples

1. Ping Hosts

Check if the hosts are reachable.

ansible all -m ping        

2. Gather Facts

Collect information about the remote hosts.

ansible all -m gather_facts        

3. Run Shell Commands

Execute shell commands on remote hosts.

ansible all -m shell -a 'uptime'
ansible all -m command -a 'uptime'        

4. Copy Files

Copy files from the local machine to remote hosts.

ansible all -m copy -a 'src=/path/to/local/file dest=/path/to/remote/destination'        

5. Manage Packages

Install, update, or remove packages on remote hosts.

ansible all -m apt -a 'name=htop state=present' -b        

6. Manage Services

Start, stop, or restart services on remote hosts.

ansible all -m service -a 'name=nginx state=started' -b        

7. Create Users

Add a new user on remote hosts.

ansible all -m user -a 'name=Manasee state=present' -b        

8. Modify File Permissions

Change the permissions of files or directories on remote hosts.

ansible all -m file -a 'path=/path/to/file mode=0755' -b        

9. Target Specific Hosts

ansible webservers -m ping        

10. Use Patterns

ansible 'webservers: !dbservers' -m ping        



要查看或添加评论,请登录

Manasee Suuba的更多文章

  • How Pods Differ from Containers

    How Pods Differ from Containers

    Containers are the basic building blocks for running individual applications, pods provide the orchestration-friendly…

  • How would you perform a rolling update of an application across multiple servers to ensure zero downtime?

    How would you perform a rolling update of an application across multiple servers to ensure zero downtime?

    Use the serial keyword to update servers in batches. Ensure that a load balancer routes traffic away from the servers…

    1 条评论
  • AWS IAM (Identity and Access Management)

    AWS IAM (Identity and Access Management)

    AWS IAM is a service that enables you to manage access to AWS resources securely. It controls who (users, roles, or…

  • AWS Instance

    AWS Instance

    In AWS (Amazon Web Services), an instance refers to a virtual server that runs applications on the AWS infrastructure…

  • VPC

    VPC

    A VPC (Virtual Private Cloud) in AWS is a logically isolated section of the AWS cloud where you can launch AWS…

  • IAM

    IAM

    AWS IAM (Identity and Access Management) is a web service that helps you securely control access to AWS services and…

  • S3 bucket

    S3 bucket

    Amazon S3 (Simple Storage Service) is a scalable and durable object storage service provided by AWS. S3 Buckets are…

  • Cloudfront

    Cloudfront

    Amazon CloudFront is a content delivery network (CDN) service provided by AWS. It helps deliver content (web pages…

  • Cloudwatch

    Cloudwatch

    Amazon CloudWatch is a monitoring and observability service provided by AWS that helps you track the performance and…

  • CIDR Block

    CIDR Block

    A CIDR block (Classless Inter-Domain Routing block) is a range of IP addresses that is defined by a base IP address and…

社区洞察

其他会员也浏览了