Skip to content

Commit 915d15e

Browse files
committed
target mode is challenging
Signed-off-by: John McCrae <john.mccrae@progress.com>
1 parent 7aa7278 commit 915d15e

File tree

1 file changed

+34
-16
lines changed

1 file changed

+34
-16
lines changed

content/target_mode.md

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,28 +28,32 @@ Target Mode has the following requirements:
2828

2929
- A network-enabled system to execute Target Mode.
3030
- The `chef-client` CLI. This is included with Chef Workstation.
31-
- A credentials file which provides the system with information to connect to a target node.
31+
- A target_credentials file which provides the system with information to connect to a target node.
3232
- A recipe that only includes Target Mode-enabled resources.
3333

34-
## Credentials file
34+
## Target_Credentials file
3535

36-
The credentials file defines the SSH connection settings for each node in TOML format.
36+
The target_credentials file defines the SSH connection settings for each node in TOML format.
3737

38-
Create a credentials file on the computer running Chef Workstation in the following location:
38+
Create a target_credentials file on the computer running Chef Workstation in the following location:
3939

40-
- on Linux and macOS: `~/.chef/credentials`
41-
- on Windows: `c:\Users\<USERNAME>\.chef\credentials`
40+
- on Linux and macOS: `~/.chef/target_credentials`
41+
42+
- on Windows: `c:\Users\<USERNAME>\.chef\target_credentials`
43+
44+
- Previous iterations of the documentation referred to a "credentials" file. This has been deprecated.
4245

4346
### Define node connections
4447

4548
Define connection settings for each node with an [inline table](https://toml.io/en/v1.0.0#inline-table).
46-
For example, this adds credentials for three nodes:
49+
For example, this adds credentials for three nodes to your target_credentials file:
4750

4851
```toml
4952
['HOST-1']
5053
host = 'target.system.host.1.com'
5154
user = 'root'
52-
key_files = '~/.keys/key-pair.pem'
55+
sudo = true
56+
key_files = ['~/.keys/key-pair.pem']
5357

5458
['HOST-2']
5559
host = 'target.system.host.2.com'
@@ -104,15 +108,15 @@ host = '<IP_ADDRESS OR FQDN>'
104108
# forward_agent: Whether the connection to the authentication agent (if any) will be forwarded to the remote machine. Default is false.
105109
# forward_agent = false
106110

107-
# transport_protocol: The protocol to use to connect to a node. Define this once for all nodes in the credentials file. Set to 'ssh'. (Required)
111+
# transport_protocol: The protocol to use to connect to a node. Define this once for all nodes in the target_credentials file. Set to 'ssh'. (Required)
108112
transport_protocol = 'ssh'
109113
```
110114

111115
### Node connection parameters
112116

113117
<!-- markdownlint-disable MD007 MD006 -->
114118

115-
Target Mode supports the following SSH connection parameters in a credentials file.
119+
Target Mode supports the following SSH connection parameters in a target_credentials file.
116120

117121
Common parameters:
118122

@@ -136,7 +140,7 @@ Common parameters:
136140
: If connecting with a password, the password string to connect to a node.
137141

138142
`transport_protocol`
139-
: (Required) The protocol to use to connect to a node. Define this once for all nodes in the credentials file. Set to `ssh`.
143+
: (Required) The protocol to use to connect to a node. Define this once for all nodes in the target_credentials file. Set to `ssh`.
140144

141145
Additional parameters:
142146

@@ -199,18 +203,19 @@ Run the `chef-client` executable using `-t` or `--target` to target a specific n
199203
chef-client -t <TARGET_NAME>
200204
```
201205

202-
Replace `<TARGET_NAME>` with the name of the host as defined in the credentials file.
206+
Replace `<TARGET_NAME>` with the name of the host as defined in the target_credentials file.
203207
For example, `HOST-1` in the [credential file example](#define-node-connections).
204208

205209
To execute a specific Cookbook in Target Mode, run:
206210

207211
```sh
208212
chef-client -t <TARGET_NAME> <PATH/TO/COOKBOOK/COOKBOOK_NAME>
213+
chef-client -t SQL_Server 'recipe[sql_harden::default]' # this method assumes you are using a Chef/Automate server
209214
```
210215

211216
Replace the following:
212217

213-
- `<TARGET_NAME>` with the name of the host as defined in the credentials file.
218+
- `<TARGET_NAME>` with the name of the host as defined in the target_credentials file.
214219
- `<PATH/TO/COOKBOOK/COOKBOOK_NAME>` with the path to the Cookbook on your system. For example, `/chef-repo/cookbooks/example_cookbook.rb`
215220

216221
### Target Mode in Local Mode
@@ -222,13 +227,26 @@ Use `-z` and `-t` to run Target Mode in Local Mode:
222227

223228
```sh
224229
chef-client -z -t <TARGET_NAME>
230+
chef-client -z -t SQL_Server ~/.chef/apply.rb
225231
```
226232

227-
Replace `<TARGET_NAME>` with the name of the host as defined in the credentials file.
233+
Replace `<TARGET_NAME>` with the name of the host as defined in the target_credentials file.
228234
For example, `HOST-1` in the [credential file example](#define-node-connections).
229235

230236
## Run Target Mode with Chef Automate or Chef Infra Server
231237

238+
Upload the cookbooks you need to the chef server for your target node.
239+
240+
Don't forget to add those cookbooks to the run_list for each of your target nodes
241+
242+
```sh
243+
knife ssl fetch
244+
knife ssl check
245+
knife cookbook upload sql_harden
246+
knife node run_list add SQL_Server 'recipe[sql_harden::default]'
247+
chef-client -t SQL_Server 'recipe[sql_harden::default]'
248+
```
249+
232250
You can configure Chef Automate or Chef Infra Server to run Target Mode on a regular schedule.
233251

234252
Target Mode doesn't have a way to schedule Chef Infra Client runs on a node, but you can create a cron file that executes Target Mode on a regular schedule.
@@ -238,7 +256,7 @@ For example, this create a cron file that executes Target Mode every thirty minu
238256
```ruby
239257
cat > /etc/cron.d/nodename.cron <<EOF
240258
PATH="/opt/chefdk/bin:/opt/chefdk/embedded/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
241-
GEM_ROOT="/opt/chefdk/embedded/lib/ruby/gems/2.6.0"
259+
GEM_ROOT="/opt/chefdk/embedded/lib/ruby/gems/3.4.0"
242260

243261
0,30 * * * * * chef-runner /usr/bin/chef-client -t <TARGET_NAME>
244262
EOF
@@ -258,7 +276,7 @@ The following are the common errors and their potential troubleshooting steps.
258276

259277
### `chef-client` execute error
260278

261-
Verify that the target node's hostname or IP address is correct, that the host accessible using SSH, and that the user and password specified in the credentials file are correct.
279+
Verify that the target node's hostname or IP address is correct, that the host accessible using SSH, and that the user and password specified in the target_credentials file are correct.
262280

263281
### Custom resources don't execute
264282

0 commit comments

Comments
 (0)