From bfe510f1edfc5dfac798efcf330cb650280fcc7f Mon Sep 17 00:00:00 2001 From: Michele Cereda Date: Wed, 7 Aug 2024 22:24:43 +0200 Subject: [PATCH] chore(ansible): improve ssm integration notes --- knowledge base/ansible.md | 5 +++++ knowledge base/cloud computing/aws/ssm.md | 7 ++++--- snippets/ansible/commands.sh | 5 +++++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/knowledge base/ansible.md b/knowledge base/ansible.md index ce182db..b857aad 100644 --- a/knowledge base/ansible.md +++ b/knowledge base/ansible.md @@ -4,6 +4,7 @@ 1. [Configuration](#configuration) 1. [Performance tuning](#performance-tuning) 1. [Inventories](#inventories) + 1. [AWS](#aws) 1. [Templating](#templating) 1. [Tests](#tests) 1. [Loops](#loops) @@ -257,6 +258,10 @@ saturn ; mars.lan ansible_port=4444 ``` +### AWS + +Refer [Integrate with AWS SSM]. + ## Templating Ansible leverages [Jinja2 templating], which can be used directly in tasks or through the `template` module. diff --git a/knowledge base/cloud computing/aws/ssm.md b/knowledge base/cloud computing/aws/ssm.md index c81cbb2..16f4281 100644 --- a/knowledge base/cloud computing/aws/ssm.md +++ b/knowledge base/cloud computing/aws/ssm.md @@ -145,7 +145,7 @@ aws ssm describe-instance-associations-status --instance-id 'instance-id' ## Integrate with Ansible -Create a dynamic inventory named `aws_ec2.yml`.
+Create a dynamic inventory which name ends with `aws_ec2.yml` (e.g. `test.aws_ec2.yml` or simply `aws_ec2.yml`).
It needs to be named like that to be found by the ['community.aws.aws_ssm' connection plugin][community.aws.aws_ssm connection]. @@ -167,6 +167,7 @@ hostnames: - instance-id # acts as keyword to use the instances' 'InstanceId' attribute # use 'private-ip-address' to use the instances' 'PrivateIpAddress' attribute instead + # or any option in really ``` Pitfalls: @@ -175,7 +176,7 @@ Pitfalls: From the [plugin notes][aws_ssm connection plugin notes]: > The `community.aws.aws_ssm` connection plugin does not support using the `remote_user` and `ansible_user` variables - > to configure the remote user. The ``become_user`` parameter should be used to configure which user to run commands + > to configure the remote user. The `become_user` parameter should be used to configure which user to run commands > as. Remote commands will often default to running as the `ssm-agent` user, however this will also depend on how SSM > has been configured. @@ -284,7 +285,7 @@ $ sudo ssm-cli get-diagnostics --output 'table' [amazon web services]: README.md [cli]: cli.md [ec2]: ec2.md -[snippets]: ../../../snippets/aws.fish +[snippets]: ../../../snippets/aws/commands.fish [aws_ssm connection plugin notes]: https://docs.ansible.com/ansible/latest/collections/community/aws/aws_ssm_connection.html#notes diff --git a/snippets/ansible/commands.sh b/snippets/ansible/commands.sh index 4e6b5b6..a693800 100644 --- a/snippets/ansible/commands.sh +++ b/snippets/ansible/commands.sh @@ -46,3 +46,8 @@ ANSIBLE_ENABLE_TASK_DEBUGGER=True ansible-playbook … ANSIBLE_CALLBACKS_ENABLED='profile_tasks' ansible-playbook … ansible-playbook 'path/to/playbook.yml' --syntax-check + +# Ad-hoc commands. +ansible -m 'ping' 'all' +ansible 'hostRegex' -m 'ansible.builtin.shell' -a 'echo $TERM' +ansible -i 'localhost,' -c 'local' -m 'ansible.builtin.copy' -a 'src=/tmp/src' -a 'dest=/tmp/dest' 'localhost'